Git Product home page Git Product logo

vscode-lua's Introduction

Build Status Visual Studio Marketplace

Lua for Visual Studio Code

Provides Intellisense and Linting for Lua in VSCode

Features

  • Autocompletion
  • Go to Symbol
  • Error checking
  • Linting
  • Formatting
  • Code Snippets

Installing

  • Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter:
  • ext install vscode-lua

Alternatively, you can download the extension from the marketplace.

Settings

lua.luacheckPath (Default: null)

Specifies the path to luacheck binary (if not found on PATH).

lua.preferLuaCheckErrors (Default: false)

Specifies whether to prefer luacheck errors over the standard luaparse errors if luacheck is available.

lua.targetVersion (Default: 5.1)

Specifies the target version of Lua. Valid options:

  • 5.1
  • 5.2
  • 5.3

Can also be changed using the version selector in the bottom right of the IDE.

lua.format.enabled (Default: true)

Specifies whether to use the Lua formatter

lua.format.lineWidth (Default: 120)

Maximum length of a line before it will be wrapped.

lua.format.indentCount (Default: 4)

Number of characters to indent.

lua.format.singleQuote (Default: false)

Whether to use single or double quotes on strings. Defaults to double quotes.

lua.linting.enabled (Default: true)

Specifies whether to enable linting of source files

lua.linting.luaCheckConfig (Default: null)

Path to a .luacheckrc to be used for linting, instead of the default luacheck search path

lua.linting.luaCheckArgs (Default: [])

Additional arguments to pass to luacheck

Luacheck

Support for linting is provided via luacheck. Installation instructions can be found on the luacheck repository.

Once installed, luacheck support can be activated by assigning the lua.luacheckPath setting to the path of the luacheck executable. Additionally, since luacheck provides vastly more detailed and contextually aware errors that may sometimes duplicate those created by luaparse, the setting lua.preferLuaCheckErrors can be set to true to suppress luaparse errors.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

vscode-lua's People

Contributors

alloyed avatar lostintangent avatar trixnz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-lua's Issues

Provide minimal edits when formatting

When formatting the whole file, we return a single text edit containing the whole formatted document, which can sometimes cause vscode to lose track of the cursor position. According to microsoft/vscode#10133, vscode prefers that extensions provide a minimal number of edits.

We should instead use the proposed --write-mode=diff argument to provide vscode with a minimal number of edits.

This has a dependency on trixnz/lua-fmt#13.

Check Luacheck

Luaparse is working good. But how could i know is luacheck working?

Luacheck tries to lint itself

I already saw in your screenshot in #42 that you have the same "problem" but currently luacheck tries to lint it's own .luacheckrc. Is that intended?

Implement SignatureHelp provider

Continuation of #4.

While we provide argument hints when autocompleting functions, we do not provide them after typing the triggering ( character.

This also ties into #5, so some thought should go into how to properly generate signature information from a function declaration while also enriching the suggestions with information from docstrings, if present.

Code formatting setup

I think will be good to add formatting parameters to VSCode config. For example at big monitors it wrap code at half of string length and i don't find any way to correct this behaviour.

After formatting code may look like:

 if
        last_sync_version ~= nil and cur_version ~= nil and (not is_str_empty(cur_map_id)) and cur_level ~= nil and
            save_data ~= nil
     then
          some code here....
end

It will be great to put code wrapping length somewhere to save lines and compact code after formatting.

Using Tarantool or other third party libraries

Is there any option to use a library and the library functions to be known by the luacheck? For example i use tarantool and i get

severity: 'Warning' message: 'accessing undefined variable 'box'' at: '44,5' source: 'luacheck'

but the box is a builtin function.

Same question for autocompletion. Would be nice if autocompletion box could contain the functions of the third party libraries. Of course the developers need to make a description file for these, but this isn't a problem i think. I glad to make the Tarantools one. ;-)

Dynamic autocomplete

Is there any plan to implement dynamic autocompletion (for custom functions, tables, variables)?

Minor - Refocusing/saving with no changes editor should relint

Not sure if possible, but refocusing an editor should re-lint the active editor file. For those of us editing .luacheckrc files

Right now to force a re-lint I have to make a change to the file and re-save it (the re-save might not be necessary but the edit it)

In Atom I could easily do something like this by quickly saving the file with ctrl-s.

Support for formatting

Hello,

Is it possible to add support to make automatic formatting? Thanks !

best regards,
Zheng

Auto-indent feature request

when making a new line after an if/for/while/function etc. the new line should be indented by 1 tab (however many spaces is in the user's settings)

Luacheck no longer working on windows?

I had luacheck configured and working but since the past couple of days it refuses to work.

I have no idea how to check in vscode where if at all an extension is erroring.

I tried to get luacheck to bark with the following:

alskjdhlkajshd=nil;
ssss=defines;
sdfa=0;

But it is silent while it should have said something about each and everyone one of those lines.

These are my relevant settings (these worked perfectly):

	"lua.luacheckPath": "D:/DEV/luacheck/luacheck.exe",
	"lua.preferLuaCheckErrors": true,
	"lua.targetVersion": "5.2",

How could i change luaVersion for luaparse

Usually I avoid goto, but today needed to use it and got this:
message: 'unexpected identifier 'goto' near 'end'' at: '25,13' source: 'luaparse'
so i think i should to set luaVersion for luaparse. How could i do that?
By the way i love your extension. 👍 Thx.

[Request] LUA snippets

The only thing I see as truly missing in this extension is snippets for built in lua stuff. I am currently using keyring.lua for those but I would like to only have 1 lua extension.

Can not analyze symbols with Chinese

Can not analyze the Chinese function name, variable name, please add the analysis of Chinese function name and variable name support.
Luajit can support gbk or utf8 Chinese function name and variable name.

example
`
function 中文函数名(参数1,参数2)
local 中文变量 = "Chinese variable name"
end

`

Respect file indent settings

It looks like lua-fmt accepts --indent-count and --use-tabs, but vscode-lua does not propagate the current buffer's indent settings to these options. Would this be something easy to hook up?

Help with extending

I'd love to help out with this extension but even trying to debug it is giving me an error "channel has been closed". I do not have too much experience with vscode extensions though so a quick tutorial on setting this up for running in debug would be really helpful...

Module 'self' autocompletion

It would be nice to have autocompletion for modules using the 'self' parameter.

module = {
  enabled = false,
  toggle = function(self)
    -- autocompletion for 'enabled' here
    self.enabled = not self.enabled
  end
}

Question: adding custom functions support

Would it be possible to have a sort of extension file that you can plug to this extension to add support for your own functions exported from C/C++ code for example?

Docstrings

This is another suggestion I'm drawing with an example from the python extension. Basically this code:

def test(param1, param2):
    '''Concatenates two parameters and prints them'''
    print(param1 + param2)

produces this:
https://gyazo.com/8d84702d0cfc0235b7e106f0eda4c917

This also works at the beginning of a .py file, so when it's import-ed, you can hover over the variable and it will show you the docstring of that module.

It'd be very useful to have something like this in Lua as well, albeit its not that high of a priority. The real question would be how it would work in Lua.

I propose one of these two ways, or something along these lines, though the more ideas about it the better:

function test(param1, param2)
	--[[-Concatenates two parameters and prints them-]]--
	print(param1..param2);
end

or

function test(param1, param2)
	docstring "Concatenates two parameters and prints them";
	print(param1..param2);
end

function return value type awareness

hi, I enjoyed you plugin a lot. Can it make the following code show autocomplete list?

local tab = {key1 = 2, key2 = 2}
function returnTab()
    return tab
end
returnTab().key1 --can this show autocompletion?

Problems window not clearing up when closing file

Opened a folder, opened a file (FILE) that was not in the folder, closed FILE, warnings stayed in the problems window.

Expected, problems to disappear

Also I think this one was reported before but same kind of issue
Open a file, Compare with previous version (or some kind of split compare that opens a temp file, split window/temp file. warnings stay

Expected Don't lint temporary files, and problems to disappear when closing.

Keep up the awesome work!

format code with comment, comment moved to wrong block

from a file with these lines

function Test()
    if a == 0 then
        print("1")

    -- a is one
    elseif a == 1 then
        print("2")
    end
end

running Format Document with alt+shift+f
get this

function Test()
    if a == 0 then
        -- a is one
        print("1")
    elseif a == 1 then
        print("2")
    end
end

vscode version 1.25.0

WSL support?

I have luacheck installed in WSL and it can be run from Windows using bash -c "luacheck" (see here).

I tried setting lua.luacheckPath to "bash -c \"luacheck\"" in my settings, but this does not seem to work.

Any thoughts on best way to support this?

Increase depth of intellisense

Hiya,

It would be nice if the scope in tables went further than once in depth. For instance:

This is good:
screenshot from 2017-08-23 19-29-56

This is not good:
screenshot from 2017-08-23 19-30-03

It should show up two, and inside two it should show the string str.

Error: write EOF

Getting

Error: write EOF
    at exports._errnoException (util.js:1050:11)
    at WriteWrap.afterWrite (net.js:813:14)
[Info  - 18:34:27] Connection to server got closed. Server will restart.
[Error - 18:34:36] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'symbols' of undefined
  Code: -32603 
[Error - 18:34:37] Request textDocument/documentSymbol failed.
  Message: Request textDocument/documentSymbol failed with message: Cannot read property 'symbols' of undefined
  Code: -32603 

when playing around with super long files. https://github.com/WeakAuras/WeakAuras2/blob/master/.luacheckrc

Empty luacheck path doesn't work

luacheck is not ran if the luacheck path setting is empty and the luacheck is on windows path. The second problem is the .bat extension is needed on it.

The default setting should be luacheck (not null) and additionaly the code should add .bat behind the scenes if OS is windows

Something like this

if (process.platform == 'win32' && path.extname(cmd) != '.bat') {
        cmd += '.bat'
    }

git compare leaves problem window open

Expected: No linting to happen at all in these windows, OR problems go away when closed.

Steps to reproduce [reproduces on both windows and linux]
Open a project with a git repo

Right click on a file and compare with previous revision

image

image

Extensions used Git Lens, vscode-lua, keyring.lua

Related #32

luacheck options via VS code

Is there any way to add options to the luacheck call when using it via VS code?
I would like to add some globals I use that are in a require all my processes call

Formatting a file with invalid syntax causes the "Output" window to pop up due to an error.

As a compulsive saver, this is somewhat annoying when I'm working on a file and hit save mid-stride. I'm fine with VSCode showing me an error, but the pop up of the output window because the textFormatter has errored is a bit annoying, and really breaks the flow of code.

This is mostly a problem because I have VS Code set to format on save (for formatting consistency) and I'm guessing it was assumed that formatting will always be a concious decision, instead of something that gets done automatically by the editor.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.