hinell / lsp-timeout.nvim

Start/stop LSP servers upon demand; keeps RAM usage low
Other
194 stars 6 forks source link

switching buffers on restart makes the LSP attach to the wrong buffer #23

Open dylan-chong opened 1 week ago

dylan-chong commented 1 week ago

I've read TROUBLESHOOTING instructions

Summary

image

see lua and vim lsps are attached to the lua file buffer according to statusline

Steps to reproduce

  vim.g.lspTimeoutConfig = {
    startTimeout = 1000 * 0.1,
    stopTimeout = 1000 * 2,
  }
  1. open file a
  2. open file b in another tab
  3. defocus terminal
  4. wait for timeout
  5. focus terminal and switch to file a
  6. lsp for language a and b will be active for buffer a and file b will show Lsp inactive status in statusline. file b may even have no lsps inactive

probably some race condition with picking the current buffer after a time delay (after which the user has switched buffers)

Versions

NVIM v0.11.0-dev-302+gbe999e6a0 plugin 6325906730330105a9adc41d0ceb8499b3072e2b

Specify operating system/environment

Windows WSL

hinell commented 1 week ago

What lsp clients are involved?

Have to dig it up later, when I have more time on hands. Currently I'm a bit busy with fixing my old laptop...

dylan-chong commented 1 week ago

hey, cheers for the quick response. the dont think the lsp matters but in the example i have lua_ls/vimls. i can replicate with jsonls/tsserver too.

dylan-chong commented 1 week ago

i wonder if this line needs to pass the opts { bufnr: auEvent.buf } as vim.lsp.start probably attaches to the current buffer

ive also noticed a separate issue where this plugin doesnt seem to disable lsps in other tabs through normal usage (not racing). ie you timeout on one tab, refocus (it'll say Lsp inactive in statusline) then switch to another tab before the start duration, then the lsp is still running.

is the plugin supposed to work as a global stop all lsps, or work per buffer?

hinell commented 1 week ago

Please, make a screenshot of two files and use :LspInfo command to show which lsps are running and which aren't.

Once again, read troubleshooting doc subsection on nvim-navic

lsp-timeout doesn't care about current buffer. It keeps track of lsp per every buffer's window and stop/restart them accordingly per the same buffer every time, regardless of the currently focused one.

dylan-chong commented 1 week ago

file a

image

file b image

ah so you have to be really quick on step 5 (switching to file a) it may help to try a startTimeout of 0.4 in case you are not fast enough at switching buffers

hinell commented 5 days ago

Running in single file mode

This is not expected. You have to deal with this problem first. Checkout single_file_support setting for lspconfig plugin first. Try also to stop and start LSP clients manually by using LspStart / LspStop to see if lsps are working directory-relative.

dylan-chong commented 3 days ago

Ah okay that's interesting. In the case shown above, lua_ls and json_lsp have no marker to detect the root of the project. This makes sense for neovim configs or some random json file. So running in single file mode is by design