LuaLS / lua-language-server

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

Adding a new workspace folder breaks things #1974

Open musjj opened 1 year ago

musjj commented 1 year ago

How are you using the lua-language-server?

NeoVim

Which OS are you using?

Windows

What is the issue affecting?

Completion, Diagnostics/Syntax Checking, Hover, Libraries

Expected Behaviour

Addding new workspace folders should not break anything.

Actual Behaviour

Right now, adding a new workspace folder breaks two things, diagnostics and require statements:

Other LSP servers doesn't have this problem. Adding a new workspace folder should just work without any additional steps.

Reproduction steps

  1. Initialize the LSP server with a root directory
  2. Add a new workspace folder using workspace/didChangeWorkspaceFolders
  3. Opening a file from that workspace folder results in diagnostic errors and modules not being resolved correctly

Additional Notes

No response

Log File

No response

sumneko commented 1 year ago

Please provide your log

musjj commented 1 year ago

https://gist.github.com/musjj/fd726d9b809eba569ff28039ab248ce3 Actually, it seems that the buggy requires is caused by a plugin, never mind that. The diagnostic issue still persists though.

sumneko commented 1 year ago

I have fixed this problem in v3.6.7. Can you test which version it started to break?

musjj commented 1 year ago

I'm using 3.6.13, the latest stable version. I'll try out the latest commit later on.

musjj commented 1 year ago

Tried commit 81cffaa, still experiencing this issue.

sumneko commented 1 year ago

I'm using 3.6.13, the latest stable version. I'll try out the latest commit later on.

Could you try out if it appears in v3.6.7?

musjj commented 1 year ago

Sorry about that, I mistakenly thought that 3.6.7 is a version higher than 3.6.13.

Tried out 3.6.7, and yes, I'm still experiencing this issue.

sumneko commented 1 year ago

https://github.com/LuaLS/lua-language-server/issues/1810

So this fix dose not work, I will look into again.

chrisgrieser commented 1 year ago

Also have exactly the same issue – as soon as you open a second workspace, there "undefined global" is all over the place. In addition, in the second workspace, some capabilities like renaming of variables also sometimes being broken (though I cannot produce that one reliably)

I have had this issue for a while now, haven't made a report because there were already various issues for that already. But they all got closed by now, while the problem at hand still persists for me. 🙁

flrgh commented 4 months ago

Tried to do some debugging on this today, but I haven't figured out the issue.

I'm guessing it's dependent upon some order of operations in the server or in the client, because I can't reproduce it 100% of the time by doing this:

  1. Open somefile.lua in /path/to/workspace
  2. Open up another file outside of the workspace
  3. Wait and observe diagnostics on the opened file

I did manage to capture server logs from one instance where I got the bug and one instance where I did not:

Each time I opened the same file from the same $PWD and then opened the same external file.

In the ok case, you can see there are 12 diagnostic entries for [...]/nvim/runtime/lua/vim/shared.lua:

[16:56:36.749][debug][#0:script/provider/diagnostic.lua:330]: publishDiagnostics file:///home/michaelm/.local/share/nvim/runtime/lua/vim/shared.lua 12

...whereas in the bugged case, 12 entries are initially published, but ~10s later a second diagnostic update happens with 68 entries:

[16:58:23.803][debug][#0:script/provider/diagnostic.lua:330]: publishDiagnostics file:///home/michaelm/.local/share/nvim/runtime/lua/vim/shared.lua 12 [16:58:34.087][debug][#0:script/provider/diagnostic.lua:330]: publishDiagnostics file:///home/michaelm/.local/share/nvim/runtime/lua/vim/shared.lua 68