alloyed / lua-lsp Goto Github PK
View Code? Open in Web Editor NEWA Lua language server
License: MIT License
A Lua language server
License: MIT License
lua-fmt is, at the moment, the most powerful and consistent formatter for Lua.
It works with multiple Lua versions, is well tested and is the only one so far that handles things like lines that are too long due to function calls - breaking arguments into multiple lines.
It has places that could be improved but the creator and maintainer, Trinx, is really open to contributions and feedback.
Error from the Language Server: /usr/local/share/lua/5.3/lua-lsp/methods.lua:517: attempt to index a nil value (local ’val’)
stack traceback:
/usr/local/share/lua/5.3/lua-lsp/methods.lua:517: in upvalue ’definition_of’
/usr/local/share/lua/5.3/lua-lsp/methods.lua:662: in function ’lua-lsp.methods.textDocument/hover’
/usr/local/share/lua/5.3/lua-lsp/loop.lua:57: in function </usr/local/share/lua/5.3/lua-lsp/loop.lua:56>
[C]: in function ’xpcall’
/usr/local/share/lua/5.3/lua-lsp/loop.lua:56: in function ’lua-lsp.loop’
/usr/local/lib/luarocks/rocks-5.3/lua-lsp/scm-2/bin/lua-lsp:3: in main chunk
[C]: in ? (Internal Error)
Error from the Language Server: /usr/local/share/lua/5.3/lua-lsp/methods.lua:517: attempt to index a nil value (local ’val’)
stack traceback:
/usr/local/share/lua/5.3/lua-lsp/methods.lua:517: in upvalue ’definition_of’
/usr/local/share/lua/5.3/lua-lsp/methods.lua:662: in function ’lua-lsp.methods.textDocument/hover’
/usr/local/share/lua/5.3/lua-lsp/loop.lua:57: in function </usr/local/share/lua/5.3/lua-lsp/loop.lua:56>
[C]: in function ’xpcall’
/usr/local/share/lua/5.3/lua-lsp/loop.lua:56: in function ’lua-lsp.loop’
/usr/local/lib/luarocks/rocks-5.3/lua-lsp/scm-2/bin/lua-lsp:3: in main chunk
[C]: in ? (Internal Error)
Mark set
Any idea how I'd integrate this with the neovim built-in LSP?
I'm using lspconfig, but they only have a config for the sumneko Lua lsp, which IMHO is far too complex to set up just to get an LSP (you have to install several dependencies and build from source).
I'd much prefer to use this one, but I'm not sure how to configure it with the neovim built-in LSP?
At least, when looking at the builtins, there are many cases where returnTypes aren't provided, even when the function returns a value. This means that the void return type should be an empty returnTypes array, not the absence of one
Variants are now supported: implemented as multiple signatures for one item
Also, there does not seem to be a builtin example of an "error" return type, aka return nil, my_err
. I think we will represent those like so function a() ->! bool, extra_ret
, but it's unfortunate that it won't be available in the standard lib.
🤔
I'm not willing to write my own but it's interesting that it doesn't exist to begin with
prior art:
https://github.com/trixnz/lua-fmt
written by the vscode server author
https://github.com/trixnz/vscode-lua
The package over on luarocks.org is 2 years old, and there have definitely been commits since then. The version there is still missing the rockspec update to include the missing formatting module, so formatting is broken, which is how I noticed.
Sooooo publish master to luarocks.org, please?
experimenting with lua-lsp, got weird assertion failures when mousing over the name of a function with ...
arguments:
/usr/local/share/lua/5.1/lua-lsp/methods.lua:175: assertion failed! stack traceback: [C]: in function 'assert' /usr/local/share/lua/5.1/lua-lsp/methods.lua:175: in function 'make_items' /usr/local/share/lua/5.1/lua-lsp/methods.lua:650: in function '?' /usr/local/share/lua/5.1/lua-lsp/loop.lua:55: in function </usr/local/share/lua/5.1/lua-lsp/loop.lua:54> [C]: in function 'xpcall' /usr/local/share/lua/5.1/lua-lsp/loop.lua:54: in function 'main' ...r/local/lib/luarocks/rocks/lua-lsp/scm-2/bin/lua-lsp:3: in main chunk [C]: ?
Haven't got a fix, might try to make one if you're interested and I get free time.
I am trying to package this for guix so that i can use it in my emacs, could you provide instructions on how to build this project without luarocks? ^-^
system: wsl ubuntu18.04
root@wj:~# luarocks install --server=http://luarocks.org/dev lua-lsp
Installing http://luarocks.org/dev/lua-lsp-scm-2.rockspec
Missing dependencies for lua-lsp scm-2:
lpeglabel ~> 1.5 (not installed)
inspect ~> 3.1 (not installed)
lua-lsp scm-2 depends on lpeglabel ~> 1.5 (not installed)
Installing https://luarocks.org/lpeglabel-1.5.0-1.src.rock
gcc -O2 -fPIC -I/usr/include/lua5.2 -c lpcap.c -o lpcap.o
lpcap.c:6:10: fatal error: lua.h: No such file or directory
#include "lua.h"
^~~~~~~
compilation terminated.
Error: Failed installing dependency: https://luarocks.org/lpeglabel-1.5.0-1.src.rock - Build error: Failed compiling object lpcap.o
Native modules can't be easily parsed the way lua can: for one we might not even have the source. So it makes sense to provide a .luacompleterc-inspired format that can either be hand-made or generated, and then can be loaded when a user tries to use this kind of a module. imagined filesystem structure
: share/lua/5.1/dir/my_module.lua
: share/lua/5.1/dir/my_module.luacmp.json
: share/lua/5.1/native_module.luacmp.json
: lib/lua/5.1/native_module.so
I just noticed the type sig of goto definition allows for multiple definition returns
Use cases, if we have a method name without a type we should return a list of all methods with that name
If we has a definition/declaration split or multiple potential definitions we should also return all of those
I tried installing following the instructions:
$ luarocks install --from=http://luarocks.org/dev lua-lsp
but i received an error:
Error: No results matching query were found.
it only found the download with:
$ luarocks install --from=http://luarocks.org/dev lua-lsp
ensions/coc-lua-data/tools/share/lua/5.3/lua-lsp\rpc.lua:111: assertion failed!
stack traceback:
[C]: in function 'assert'
...ensions/coc-lua-data/tools/share/lua/5.3/lua-lsp\rpc.lua:111: in function 'lua-lsp.rpc.decode'
...nsions/coc-lua-data/tools/share/lua/5.3/lua-lsp\loop.lua:35: in function 'lua-lsp.loop'
...a\tools\lib\luarocks\rocks-5.3\lua-lsp\scm-2\bin\lua-lsp:3: in main chunk
[C]: in ?
How To Solve It?
Here is the error output:
LSP :: Connected to [lsp-lua-lsp:83564].
LSP :: Error from the Language Server: .../stardiviner/.luarocks/share/lua/5.3/lua-lsp/methods.lua:703: attempt to get length of a nil value (field 'scopes')
stack traceback:
.../stardiviner/.luarocks/share/lua/5.3/lua-lsp/methods.lua:703: in function 'lua-lsp.methods.textDocument/documentSymbol'
/Users/stardiviner/.luarocks/share/lua/5.3/lua-lsp/loop.lua:57: in function </Users/stardiviner/.luarocks/share/lua/5.3/lua-lsp/loop.lua:56>
[C]: in function 'xpcall'
/Users/stardiviner/.luarocks/share/lua/5.3/lua-lsp/loop.lua:56: in function 'lua-lsp.loop'
...uarocks/lib/luarocks/rocks-5.3/lua-lsp/scm-5/bin/lua-lsp:3: in main chunk
[C]: in ? (Internal Error)
LSP :: Error from the Language Server: .../stardiviner/.luarocks/share/lua/5.3/lua-lsp/methods.lua:703: attempt to get length of a nil value (field 'scopes')
I use Homebrew installed Lua 5.3
I am having this issue on Ubuntu 16.04.
When I run this:
./luarocks install --server=http://luarocks.org/dev lua-lsp
I get:
Error: Failed finding Lua header files. You may need to install them or configure LUA_INCDIR.
At that point of time, Lua has already been installed, and LUA_INCDIR env var has been set to Lua's src directory which contains the headers.
Any idea?
I edited $HOME/.luacompleterc
{
"luaVersion": "5.1",
"packagePath": "./?.lua;/home/user/.luarocks/share/lua/5.1/?.lua"
}
I did luarocks install --local lua-cjson
I added $HOME/.luarocks into package.path and package.cpath.
When I use vim I can autocomplete standard Lua functions(table.insert, io.open,etc), however I can not autocomplete anything from $HOME/.luarocks/share/lua/5.1, vim displays:
User defined completion(^U^N^P) Pattern not found.
So will lua-lsp be able to index all files under $HOME/.luarocks/share/lua/5.1 somehow? what about the C modules under package.cpath? I want to do auto-complete for all imported modules and my own lua files in addition to the working built-in Lua functions(e.g. os.open etc)
Is this project still maintianed?
I'm using a library that use a specific require path like love2d, and it raise error when trying to jump to definitions from another file. How to configure to work with this?
I'm using neovim and the LanguageClient-neovim plugin, and setting g:LanguageClient_rootMarkers = ['main.lua',]
doesn't work.
completion/goto definition works pretty okay when you're pointing it at a plain expression/lhs. it doesn't understand the following examples, though:
-- in comments
"in strings"
{ at_table_lhs = {}}
these suffer from the "changing scope" problem that regular scopes do.
hi,
Thanks for the nice package. Would be nice to accept more recent lpeglabel to prevent this:
-- Performing Test HAS_DIAG_COLOR_FLAG - Success
-- Found PkgConfig: /nix/store/50vxsm7w48l5mqa2f114c43vcyyixxn0-pkg-config-0.29.2/bin/pkg-config (found version "0.29.2")
Missing dependencies for lua-lsp scm-2:
lpeglabel ~> 1.5 (1.6.0-1 installed)
lua-lsp scm-2 depends on lpeglabel ~> 1.5 (1.6.0-1 installed)
Also I package this program for nixos and it would be cool to have:
"No summary";
If I'm executing this command:
luarocks --local install --server=http://luarocks.org/dev lua-lsp
than I'm getting this error message:
Error: No results matching query were found for Lua 5.4.
To check if it is available for other Lua versions, use --check-lua-versions.
and if I try this command:
luarocks --check-lua-versions
than this pops up:
Usage: luarocks [-h] [--version] [--dev] [--server <server>]
[--only-server <server>] [--only-sources <url>]
[--namespace <namespace>] [--lua-dir <prefix>]
[--lua-version <ver>] [--tree <tree>] [--local] [--global]
[--verbose] [--timeout <seconds>] [--pin] [<command>] ...
Error: unknown option '--check-lua-versions'
What am I doing wrong? I've installed lua
from the official arch linux repositories and luarocks
from the official arch linux repositories as well.
we can complete simple expressions, like
module.a.b:c()
but only when we know the type of each of the ids. We should be equally informative in these kinds of cases:
local a = { str = return_a_string() }
a.str:m---
or the inline equivalent, like for example
("string"):m
return_a_table().a
assert(module.table).a
These are all built around guessing what the type of a Call or Invoke expression will be and then storing it.
mostly for windows users
$ luarocks install --local https://raw.githubusercontent.com/Alloyed/lua-lsp/master/lua-lsp-scm-1.rockspec
Cloning into 'lua-lsp'...
remote: Counting objects: 40, done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 40 (delta 6), reused 28 (delta 6), pack-reused 0
Receiving objects: 100% (40/40), 202.16 KiB | 433.00 KiB/s, done.
Resolving deltas: 100% (6/6), done.
cp: cannot stat 'lua-lsp.lua': No such file or directory
Error: Build error: Failed installing lua-lsp.lua in /home/user/.luarocks/lib/luarocks/rocks-5.3/lua-lsp/scm-1/lua/lua-lsp.lua: Failed copying lua-lsp.lua to /home/user/.luarocks/lib/luarocks/rocks-5.3/lua-lsp/scm-1/lua/lua-lsp.lua
I guess this is easy to fix, but i'm not proficient enough with luarocks to do it myself.
Installation works by changing the protocol to SSH
$ sudo luarocks install --server=ssh://luarocks.org/dev lua-lsp # works
Installation fails with HTTP URL which is currently suggested in lua-lsp README
$ sudo luarocks install --server=http://luarocks.org/dev lua-lsp # fails
...
fatal: remote error:
The unauthenticated git protocol on port 9418 is no longer supported.
Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information.
This change will be made permanent 2022-04-16. We're currently on brownout period, so the old command will work intermittently.
I'm not familiar with luarocks, simply providing the command that worked for me on Debian 11-Bullseye. I noticed the error while writing installation instructions for Micro editor's new LSP Plugin. It seems that Lua-lsp works to some extent with this Micro's LSP plugin, supporting linting (in the left side gutter) and alt-D jump to definition inside the same file.
I'm using neoclide/coc.nvim as language client support in my vim editor. However, when I move the cursor to self:foo()
inside the module:bar()
function, and try gd
key, which is mapped to <Plug>(coc-definition)
, it will output the error about finding no definition.
local module = {}
function module:foo()
end
function module:bar()
self:foo()
end
if we find a global by parsing a file, we should probably assume that every other file has access to that global. this means the global table exists on a workspace level, not a document level
Not very familiar with Lua, so I don't know how to find much more info than this. It seems to start happening if I start using a variable without declaring it.
LSP :: Error from the Language Server: /usr/local/share/lua/5.3/lua-lsp/methods.lua:308: assertion failed!
stack traceback:
[C]: in function 'assert'
/usr/local/share/lua/5.3/lua-lsp/methods.lua:308: in upvalue 'make_position'
/usr/local/share/lua/5.3/lua-lsp/methods.lua:324: in upvalue 'make_range'
/usr/local/share/lua/5.3/lua-lsp/methods.lua:334: in upvalue 'make_location'
/usr/local/share/lua/5.3/lua-lsp/methods.lua:711: in function 'lua-lsp.methods.textDocument/documentSymbol'
/usr/local/share/lua/5.3/lua-lsp/loop.lua:57: in function </usr/local/share/lua/5.3/lua-lsp/loop.lua:56>
[C]: in function 'xpcall'
/usr/local/share/lua/5.3/lua-lsp/loop.lua:56: in function 'lua-lsp.loop'
/usr/local/lib/luarocks/rocks/lua-lsp/scm-5/bin/lua-lsp:3: in main chunk
[C]: in ? (Internal Error)
Interestingly, according to the line number, the assertion that's failing is assert(pos <= document.text:len())
.
However, this error goes away if I restart the server, even without changing any code.
Let me know if (and how?) to get any extra info!
local module = { my_constant_field = "woah" }
function module:method()
return self.my_
end
should autocomplete as imagined. This is not strictly true that self
will always be module
, but the intent is to make the common case helpful instead of correctly represent the language semantics. Hopefully we can also support simple setmetatable usage, too.
I installed lua-lsp with luarocks install --server=http://luarocks.org/dev lua-lsp
. Starting lua-lsp
in the command line results in the following error:
/usr/local/bin/lua5.3: /usr/local/share/lua/5.3/lua-lsp/rpc.lua:2: module 'dkjson' not found:Failed loading module dkjson in LuaRocks rock dkjson 2.5-2
no field package.preload['dkjson']
no file '/Users/dschuessler/.luarocks/share/lua/5.3/dkjson.lua'
no file '/Users/dschuessler/.luarocks/share/lua/5.3/dkjson/init.lua'
no file '/usr/local/share/lua/5.3/dkjson.lua'
no file '/usr/local/share/lua/5.3/dkjson/init.lua'
no file '/usr/local/lib/lua/5.3/dkjson.lua'
no file '/usr/local/lib/lua/5.3/dkjson/init.lua'
no file './dkjson.lua'
no file './dkjson/init.lua'
no file '/Users/dschuessler/.luarocks/lib/lua/5.3/dkjson.so'
no file '/usr/local/lib/lua/5.3/dkjson.so'
no file '/usr/local/lib/lua/5.3/loadall.so'
no file './dkjson.so'
stack traceback:
[C]: in function 'require'
/usr/local/share/lua/5.3/lua-lsp/rpc.lua:2: in main chunk
[C]: in function 'require'
/usr/local/share/lua/5.3/lua-lsp/loop.lua:1: in main chunk
[C]: in function 'require'
/usr/local/lib/luarocks/rocks-5.3/lua-lsp/scm-2/bin/lua-lsp:2: in main chunk
[C]: in ?
Thank you for having a look. Let me know if there is any further troubleshooting I can help with.
macOS 10.13.4
Lua 5.3
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
file lua-lsp/json.lua actually not installed via command luarocks install --server=http://luarocks.org/dev lua-lsp
;
2020-10-21
$tree
tree
.
├── analyze.lua
├── data
│ ├── 5_1.lua
│ ├── 5_2.lua
│ ├── 5_3.lua
│ ├── love-completions.lua
│ ├── luajit-2_0.lua
│ └── _test.lua
├── formatting.lua
├── log.lua
├── loop.lua
├── lua-parser
│ ├── parser.lua
│ ├── scope.lua
│ └── validator.lua
├── methods.lua
├── rpc.lua
└── unicode.lua
2 directories, 16 files
Hi,
I am trying to clean up my configs and I am wondering if I can put luacompleterc under XDG_CONFIG_HOME? :)
// molle
Ideally, we should update our grammar to support the new features at the same time that we port to lua 5.4 as a runtime
I am trying to bring some updates to nixpkgs (NixOS/nixpkgs#172096) and one of the problems is that lua-lsp requires dkjson ~> 2.5
but I would like to update dkjson to 2.6.
Is it possible for you to update the dependency? (As a small motivation: 2.5 was released 2014 and 2.6 was released in 2021).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.