LuaLS / lua-language-server

A language server that offers Lua language support - programmed in Lua
https://luals.github.io
MIT License
3.26k stars 306 forks source link

Build/Use outside of VSCode #60

Closed norcalli closed 3 years ago

norcalli commented 5 years ago

I've been looking for a good lua language server since I've found EmmyLua to be a little unreliable. I want to use this with vim, which just requires running the server, but I don't see instructions for how to build the server standalone.

Is it possible to run as a stdio server so I could use it with vim?

sumneko commented 5 years ago

If you are on Windows, you can download this extension then copy the server folder. Otherwise, see readme How to use on macOS/Linux. And then startup server like here.

norcalli commented 5 years ago

So, I actually went through the steps by installing VSCode, and etc, but in that process I learned what the real build steps were. They were defined in .vscode/tasks.json:

git clone git@github.com:sumneko/lua-language-server.git
cd lua-language-server
# PreCompile
cd 3rd/luamake/
ninja -f ninja/linux.ninja
cd ../../
# Compile
3rd/luamake/luamake rebuild
# Run
server/bin/lua-language-server -E -e LANG=en server/main.lua

You could put this in a Makefile for those of us who want to try this outside of VSCode.

Here's a 30 second version:

run: server/bin/lua-language-server
  server/bin/lua-language-server -E -e LANG=en server/main.lua

server/bin/lua-language-server: 3rd/luamake/luamake
  3rd/luamake/luamake rebuild

3rd/luamake/luamake:
  cd 3rd/luamake && ninja -f ninja/linux.ninja

Note to others:

server/bin/lua-language-server must be run from inside of lua-language-server as it contains relative paths.

norcalli commented 5 years ago

Works well!

@sumneko consider adding the instructions I made above to the README. I could open a PR if you're interested.

MaskRay commented 4 years ago

Drop-by comment. I was looking for a Lua language server and just came across this project.

@sumneko Please add a wiki page and probably make it publicly editable https://help.github.com/en/articles/changing-access-permissions-for-wikis Users of editors other than VSCode can benefit from the build instructions here.

wbthomason commented 4 years ago

For anyone finding these instructions now, @norcalli's comment needs two modifications:

  1. You'll need git submodule update --init --recursive before you can run ninja for luamake.
  2. Running the server (on Linux, at least) now requires running /path/to/lua-language-server/server/Linux/bin/lua -E -e LANG=en /path/to/lua-language-server/server/main.lua (the main difference is that the executable now seems to be called lua instead of lua-language-server, and that seemingly you can run it from outside of the root repo directory).

It would be really great if, as @MaskRay suggests, there was a wiki where we could put these build instructions, or section of the README, a Makefile, etc.

sumneko commented 4 years ago

I have create a wiki page for building and runing. @MaskRay Sorry I missed your message before, now everyone could edit wiki.

norcalli commented 4 years ago

@wbthomason @MaskRay @sumneko Since opening this PR, I have since joined the neovim team and wrote the builtin client for neovim vim.lsp. I also started a project to add specific language server configs in https://github.com/neovim/nvim-lsp/, but I hope for it to be a reference for any 3rd party users as to how to configure servers since the configurations are very abstracted and you don't need a lot familiarity with Lua to use them.

I wrote a script to auto install it that you can reference, and it has the benefit that it will be maintained by the neovim contributors. I added a step to download ninja if you don't have it.

Here's the PR https://github.com/neovim/nvim-lsp/pull/49/files#diff-b4f1130fbd1295c6654d11c3dd94b1e7

And here's the install script https://github.com/neovim/nvim-lsp/blob/ddd62036c8509a8a9fd78595fdcf53884bd02f7f/lua/nvim_lsp/sumneko_lua.lua#L32

You may find our automatic extension scraping and settings generation especially useful. You can see it in the README.md. I scrape the package.json for settings.

teto commented 4 years ago

mainstream packager for lua projects is https://luarocks.org/. It would be very cool to see a rockspec for it. It's quite simple to write.

weisa-san commented 4 years ago

I got the server running outside of VSCode. Like @sumneko suggests I copied the server folder from the extension and ran it with the command: bin\Windows\lua-language-server.exe -E main.lua

Now I just don't understand how I can access it? How do I send him the code of my file so that the Lua LS can send me his suggestions?

Context: I work with Angular 8 and the Monaco Editor (core of VSCode) on a IDE, it's only used locally. To connect Monaco to an LSP I use the Monaco Editor Language Client (https://github.com/TypeFox/monaco-languageclient), it provides a language client that establishes communication between Monaco editors and language servers over JSON-RPC via WebSockets.

sumneko commented 4 years ago

@weisa-san Currently the language server only supports connection by standard output and standard input.

rodamaral commented 4 years ago

I got it working with neovim, using the coc.nvim plugin, in my Linux machine. The steps are similar to @norcalli 's.

# Clone the repository recursively into a desired folder
# in my case $HOME/.lua-language-server/
git clone --recursive git@github.com:sumneko/lua-language-server.git .lua-language-server/

# PreCompile with ninja, you must have this package
cd .lua-language-server/3rd/luamake/
ninja -f ninja/linux.ninja

# Compile
cd ../../
3rd/luamake/luamake rebuild

# Run
cd ../
.lua-language-server/bin/Linux/lua-language-server  -E -e LANG=en .lua-language-server/main.lua

If everything went OK, the command won't return and wont' print anything, until you Ctrl+C. Pay attention to the OS name in the path. And make sure to invoke this command in the parent directory, because main.lua uses the path argument. To connect to coc.nvim, you must use edit coc-settings.json and include:

    "languageserver": {
        "lua": {
            // FIXME: avoid absolute paths
            "cwd": "/home/myUserName/",
            "command": "/home/myUserName/.lua-language-server/bin/Linux/lua-language-server",
            "args": ["-E", "-e", "LANG=\"en\"", ".lua-language-server/main.lua"],
            "filetypes": [
                "lua"
            ]
        }
    },
gagbo commented 4 years ago

Do you need dotnet as an additional dependency ? I'm trying to build it on Linux, and I can't build luamake (rewritten here because it's running on another laptop and reasons) :

# In 3rd/luamake with the submodules recursively initialized
[0/3] cd 3rd/bee.lua && ninja -f ninja/linux.ninja
[2/2] build/linux/bin/bootstrap test/test.lua
FAILED: build/linux/_/test
build/linux/bin/boootstrap test/test.lua
OS: Linux
Arch: 64
Compiler: GCC 10.1.0
CRT: libstdc++ 20200507
DEBUG: false
....
ninja: build stopped: subcommand fialed.
FAILED: build/linux/_/bee
cd 3rd/bee.lua && ninja -f ninja/linux.ninja
ninja: build stopped: subcommand failed.
gagbo commented 4 years ago

That's actually this issue I was able to compile removing the tests (both on 3rd/luamake/3rd/bee and 3rd/bee).

The unit tests at the end of luamake fail though. Still trying to figure out why.

But meanwhile, commenting out the test in the default targets to make.lua works well

lm:default {
    'install',
-    'test',
+    -- 'test',
    'unittest',
}
wbthomason commented 4 years ago

@gagbo: If you could try the steps in https://github.com/actboy168/bee.lua/issues/8#issuecomment-636936575 and report if you get any more information in https://github.com/actboy168/bee.lua/issues/8, that would be helpful!

sumneko commented 3 years ago

Has been integrated into neovim.

gagbo commented 3 years ago

But there are other editors than VSCode and neovim :(

Either way, I think the issue I mentionned earlier has been fixed, I didn't need extra steps to get it working after reinstalling recently. :+1:

arnoson commented 2 years ago

@weisa-san I also tried to connect this language server to a Monaco Editor running in the browser and finally got a working example: https://github.com/arnoson/monaco-lua-example