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

Fails to launch using socket #2382

Closed carsakiller closed 10 months ago

carsakiller commented 11 months ago

How are you using the lua-language-server?

Command Line

Which OS are you using?

Linux

What is the issue affecting?

Other

Expected Behaviour

Using --socket=5050 would start the language server and it would attempt to communicate with my VS Code client over a TCP socket on port 5050.

Actual Behaviour

The language server almost immediately exits with the following error: /workspaces/lua-language-server/script/brave/work.lua:65: socket closed!

Reproduction steps

  1. Run ./bin/lua-language-server --socket=5050
  2. See error /workspaces/lua-language-server/script/brave/work.lua:65: socket closed!

Additional Notes

No response

Log File

Log File ``` [15:08:49.214][info] [#0:/workspaces/lua-language-server/main.lua:66]: Lua Lsp startup, root: /workspaces/lua-language-server [15:08:49.224][info] [#0:/workspaces/lua-language-server/main.lua:67]: ROOT: /workspaces/lua-language-server [15:08:49.225][info] [#0:/workspaces/lua-language-server/main.lua:68]: LOGPATH: /workspaces/lua-language-server/log [15:08:49.226][info] [#0:/workspaces/lua-language-server/main.lua:69]: METAPATH: /workspaces/lua-language-server/meta [15:08:49.268][info] [#0:/workspaces/lua-language-server/main.lua:70]: VERSION: 3.7.1-dev [15:08:50.943][info] [#0:script/service/service.lua:144]: ========= Medical Examination Report ========= --------------- Memory --------------- Total: 2.149 MB # 00 : 2.149 MB # 01 : 0.000 MB # 02 : 0.000 MB # 03 : 0.000 MB # 04 : 0.000 MB --------------- Coroutine --------------- Total: 0 Running: 0 Suspended: 0 Normal: 0 Dead: 0 --------------- Cache --------------- Total: 1 Dead: 0 --------------- RPC --------------- Holdon: 0 Waiting: 0 ============================================== [15:08:51.030][error][#3]: /workspaces/lua-language-server/script/brave/work.lua:65: socket closed! stack traceback: [C]: in function 'error' /workspaces/lua-language-server/script/brave/work.lua:65: in function [C]: in function 'xpcall' /workspaces/lua-language-server/script/brave/brave.lua:57: in function 'brave.brave.start' /workspaces/lua-language-server/script/brave/brave.lua:23: in function 'brave.brave.register' [string "package.path = "/workspaces/lua-language-ser..."]:13: in main chunk [C]: in ? ```
sumneko commented 11 months ago

See https://github.com/LuaLS/vscode-lua/blob/7b58d50b4ea5feb1a478e6b0c18194ca1d1192a1/client/src/languageserver.ts#L128-L139

carsakiller commented 11 months ago

@sumneko I already checked that. That seems fine – but the problem seems to be with the language server, not the client. The server immediately throws an error when trying to launch in “socket mode”, it doesn't even seem to try connecting.

I also tried hard-coding the client, but it did not work:

const serverOptions: ServerOptions = {
    command: command,
    transport: { kind: TransportKind.socket, port: 5050 },
    args: commandParam,
};
carsakiller commented 11 months ago

Using Wireshark, I can see traffic from the client on port 5050, but when I launch the language server, there is no traffic at all.

sumneko commented 11 months ago

I don't know, I have tried using the parameter on the Windows platform and it works fine for me. I am not sure about any differences on Linux.

carsakiller commented 11 months ago

@actboy168 is this potentially a problem with bee.socket on Linux? I am also able to run it fine on Windows.

actboy168 commented 11 months ago

I looked at script/brave/work.lua, and the use of socket is very rough and crude. It's a miracle that it works under windows. Obviously miracles don't always happen.

Every return value of every function of bee.socket should be nodiscard. If you ignore any of them, it will definitely bring you errors at some point.

Trey2k commented 11 months ago

I am running into this issue as well on linux

./bin/lua-language-server --socket=5050
...ment/lua/lua-language-server/luaLS/script/brave/work.lua:65: socket closed!
stack traceback:
        [C]: in function 'error'
        ...ment/lua/lua-language-server/luaLS/script/brave/work.lua:65: in function <...ment/lua/lua-language-server/luaLS/script/brave/work.lua:16>
        [C]: in function 'xpcall'
        ...ent/lua/lua-language-server/luaLS/script/brave/brave.lua:57: in function 'brave.brave.start'
        ...ent/lua/lua-language-server/luaLS/script/brave/brave.lua:23: in function 'brave.brave.register'
        [string "package.path  = "/home/trey2k/Development/lua..."]:13: in main chunk
        [C]: in ?
carsakiller commented 11 months ago

Should it not be binding with rfd:bind("127.0.0.1", socketPort)? https://github.com/LuaLS/lua-language-server/blob/ce964793afc6251673238c256a25e06502e487b8/script/proto/proto.lua#L241

Is there any documentation for bee.socket? I am having to learn the implementation by the language server and guess what bee.socket is doing.

actboy168 commented 11 months ago

The design concept of bee.socket is to keep the details of bsd socket as much as possible.

bsd socket is the cornerstone of all network programs, if you are familiar with bsd socket, you don't need any documentation to use bee.socket. if you are not familiar with bsd socket, it doesn't help if you have the documentation because the documentation won't teach you how to write the code.

You need to learn bsd socket to use bee.socket directly.

carsakiller commented 11 months ago

I would disagree. Good documentation can help guide someone who even only has a basic understanding of what they are trying to accomplish. A good explanation and example of common usage can be more than enough to help most people quickly understand. Even if the implementation is very similar to another project, this one is specifically for Lua and is deserving of documentation for its specific API and implementation.

actboy168 commented 11 months ago

Documentation may be useful, but documentation cannot teach you how to use socket. For people who want to learn to use socket through documentation and examples, what they need is a higher-level encapsulated library.

In one sentence, even with documentation, many errors in using bee.socket in luals cannot be solved.

sumneko commented 11 months ago

Please try this commit

carsakiller commented 11 months ago

A different error is progress

Log File ``` [05:11:47.407][info] [#0:/workspaces/lua-language-server/fromCI/lua-language-server-adf8d52-linux-x64/main.lua:66]: Lua Lsp startup, root: /workspaces/lua-language-server/fromCI/lua-language-server-adf8d52-linux-x64 [05:11:47.418][info] [#0:/workspaces/lua-language-server/fromCI/lua-language-server-adf8d52-linux-x64/main.lua:67]: ROOT: /workspaces/lua-language-server/fromCI/lua-language-server-adf8d52-linux-x64 [05:11:47.418][info] [#0:/workspaces/lua-language-server/fromCI/lua-language-server-adf8d52-linux-x64/main.lua:68]: LOGPATH: /workspaces/lua-language-server/fromCI/lua-language-server-adf8d52-linux-x64/log [05:11:47.419][info] [#0:/workspaces/lua-language-server/fromCI/lua-language-server-adf8d52-linux-x64/main.lua:69]: METAPATH: /workspaces/lua-language-server/fromCI/lua-language-server-adf8d52-linux-x64/meta [05:11:47.461][info] [#0:/workspaces/lua-language-server/fromCI/lua-language-server-adf8d52-linux-x64/main.lua:70]: VERSION: 3.7.1-dev [05:11:49.023][info] [#0:script/service/service.lua:144]: ========= Medical Examination Report ========= --------------- Memory --------------- Total: 2.162 MB # 00 : 2.162 MB # 01 : 0.000 MB # 02 : 0.000 MB # 03 : 0.000 MB # 04 : 0.000 MB --------------- Coroutine --------------- Total: 0 Running: 0 Suspended: 0 Normal: 0 Dead: 0 --------------- Cache --------------- Total: 1 Dead: 0 --------------- RPC --------------- Holdon: 0 Waiting: 0 ============================================== [05:11:49.280][error][#0:script/service/net.lua:295]: script/service/net.lua:295: attempt to call a nil value (field 'select') stack traceback: script/service/net.lua:295: in function 'service.net.update' script/proto/proto.lua:261: in function Githubissues.
  • Githubissues is a development platform for aggregating issues.