elixir-tools / next-ls

The language server for Elixir that just works. Ready for early adopters!
https://www.elixir-tools.dev/next-ls
MIT License
691 stars 41 forks source link

The server shuts down when I close the editor #486

Closed shiroyasha closed 4 months ago

shiroyasha commented 4 months ago

I'm starting a standalone language server with:

NEXTLS_SPITFIRE_ENABLED=1 ./next_ls --port 12000

and connect to it via Neovim.

Everything works as expected. However, as I close the editor, the server shuts down.

Let me know if I can help in any other way, e.g. by providing version numbers, operating system, etc..

mhanberg commented 4 months ago

This is expected

mhanberg commented 4 months ago

Are you using the TCP adapter for a special reason?

shiroyasha commented 4 months ago

This is expected

Oh, I see, sorry for not checking the documentation first. My mistake.

Are you using the TCP adapter for a special reason?

Two reasons:

  1. My typical workflow is to open vim, edit some files, close vim, and commit. But, I'm seeing some delays in starting up the language server. As a workaround I'm looking into having an up-and-running language server where my vim instance can attach fast.

  2. The rest of my project is running inside of Docker containers during development, and I would love to move the language server inside of a container as well. This is just an experiment so far, which is also not going great as I'm stuck on a problem that I don't know how to further debug https://elixirforum.com/t/running-elixir-lsp-in-docker/63618 😅

mhanberg commented 4 months ago

How long are these delays?

The TCP mode is not meant to be used by multiple editors or editing sessions, it's mostly meant to for easy testing during development of Next LS.

Regarding that Elixir Forum post, I noticed that your downloaded the linux arm binary. Is that correct? What is your host OS?

shiroyasha commented 4 months ago

Around 15-20 seconds. Not a huge problem, but it would be nice if I could eliminate it.

I have a short screencast that demonstrates this behaviour.

https://github.com/elixir-tools/next-ls/assets/1779493/a6c830a0-70b9-42df-9fd2-7b7619263896

Sorry for the awful video quality, GitHub limited me to 10mb, so I exported it is as 480p. I still have the original, and can upload it to Youtube if it helps.


The TCP mode is not meant to be used by multiple editors or editing sessions, it's mostly meant to for easy testing during development of Next LS.

Clear. I was experimenting with something that was not meant for regular usage 😅

Regarding that Elixir Forum post, I noticed that your downloaded the linux arm binary. Is that correct? What is your host OS?

It should be the correct one, I think. I'm running inside of an UTM based virtual machine on a Mac Studio 2.

$ uname -a
Linux dev 5.15.0-102-generic #112-Ubuntu SMP Tue Mar 5 16:49:56 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux

Thank you for taking time to look into this. I fully understand that I'm doing something a bit exotic, which does not fall into the regular, everyday, usage of next-ls.

mhanberg commented 4 months ago

Around 15-20 seconds. Not a huge problem, but it would be nice if I could eliminate it.

I have a short screencast that demonstrates this behaviour.

Left pane: Opening a feature test with Vim, and pressing continuously gd to execute "go to definition". Right page: tail -f .elixir-tools/next-ls.log

so, definitions shouldn't work inside of test files (its a current limitation of test files), so i am surprised to see that jump work at all.

From what I saw, the server booted up pretty quickly, the textDocument/publishDiagnostics notifications comes once your app has compiled or credo has finished running.

Also, based on looking at your config, are you using Elixir LS and Next LS? that might explain why it was able to jump at all (I can't remember how Elixir LS works inside test files).

Can you try your test again but opening a normal file inside lib?

mhanberg commented 4 months ago

Ignore that other issue i opened 😅

shiroyasha commented 4 months ago

Heh, interesting, I also didn't know that go-to-definition should not work in test files.

Here are some further experiments:

  1. I've disabled elixir_ls in my vimfiles: https://github.com/shiroyasha/neovimfiles/blob/master/lua/shiroyasha/plugins/lsp/elixir.lua#L15.

  2. I've tested it from the lib folder. There, it is super fast, it is able to jump in a second of opening a file.

https://github.com/elixir-tools/next-ls/assets/1779493/78397e13-2301-4ee8-bb70-58f8a1a902a3

  1. I've tested the jump from the test file, it was still working, but same as before with a 20 second delay.

The good news is that the original performance problem is non-existent as I was basing my judgment mostly on test files. One thing that still puzzles me is how does the jump still working even after I've removed the elixir_ls config. 🤔


Edit: Just to be sure that it is not elixir-ls, I've also commented out this line https://github.com/shiroyasha/neovimfiles/blob/master/lua/shiroyasha/plugins/lsp/elixir.lua#L2

shiroyasha commented 4 months ago

I dig a bit deeper, and looked into the database.

Screenshot 2024-05-17 at 23 17 34

Given that there is no mention of the test directory, or the support module in the nextls.db, it must mean that I'm still using ElixirLS for that jump after all.


Out of curiosity, what is the root problem that prevents nextls from collecting references in the test directory?

mhanberg commented 4 months ago

Edit: Just to be sure that it is not elixir-ls, I've also commented out this line https://github.com/shiroyasha/neovimfiles/blob/master/lua/shiroyasha/plugins/lsp/elixir.lua#L2

Elixir LS is enabled by default, so you have to disable it for it to turn off.

Out of curiosity, what is the root problem that prevents nextls from collecting references in the test directory?

Tests are scripts and are not compiled. The way Next LS builds its index is via compiler tracers.

Also, some test code (often in test/support) is only compiled in the test environment, but we compile your project in the dev environment.

shiroyasha commented 4 months ago

Thank you for your detailed responses regarding the language server behavior. I would really like to have the goto definition functionality inside of tests, if it is possible in any way.

Would you be open to continuing this conversation in a dedicated github discussion? I would be happy to contribute or prototype some ideas to explore this further. Of course, if it is not a planned feature, I understand that as well.

mhanberg commented 4 months ago

There are two open issues related to test files.

https://github.com/elixir-tools/next-ls/issues/90

https://github.com/elixir-tools/next-ls/issues/84

I think I might have an idea with how to accomplish definition/references and will post about it in that issue.

shiroyasha commented 4 months ago

Sounds great! Thank you for investing time & energy into this 🙇‍♂️