Skip to content

Buffer becomes out of sync with language server if file changes outside of neovim #26483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jacksonludwig opened this issue Dec 9, 2023 · 2 comments
Labels
bug issues reporting wrong behavior duplicate lsp

Comments

@jacksonludwig
Copy link

jacksonludwig commented Dec 9, 2023

Problem

If a file changes on disk/outside of neovim, it seems like neovim's buffers or "view" of the file becomes out of sync with the new content. The LSP client reports inaccurate diagnostics, semantic highlighting, completion, etc.

Furthermore, reloading the file (e.g. through :e) doesn't resolve the problem. It's like the buffer or lsp state becomes "stuck" at where it was before the file was changed outside of neovim.

I haven't found a workaround aside from restarting neovim.

Although I only have encountered this with the tsserver LSP, I believe it is a neovim client bug since even restarting the tsserver LSP does not fix the inaccurate diagnostics until neovim itself is restarted.

Steps to reproduce using "nvim -u minimal_init.lua"

  1. Make sure you have typescript-language-server installed globally
  2. clone the repro: git clone git@github.com:jacksonludwig/nvimlsprepro.git
  3. cd nvimlsprepro
  4. run npm i to install typescript locally
  5. use the minimal config to open the typescript file: nvim -u minimal_init.lua index.ts
  6. move to line 8
  7. copy/paste the line (e.g. yyp)
  8. delete one of the quotes in the console.log('stuff') so you're left with console.log(stuff'). Notice the errors reported here so far are accurate and expected.
  9. save the file with :w
  10. open a terminal and stash your changes: :sp | term, then git stash
  11. go back to the buffer with the index.ts file
  12. run :e to re-read from disk and update the buffer contents
  13. Notice that the diagnostics are no longer accurate. Making other changes results in continued inaccurate diagnostics.

Expected behavior

LSP client should report diagnostics consistent with the current buffer contents.

Neovim version (nvim -v)

stable 0.9.4

Language server name/version

typscript-language-server 4.1.3

Operating system/version

ubuntu 20.04

Log file

https://gist.github.com/jacksonludwig/227a4f33cceeb67624e474b837bf98aa

@jacksonludwig jacksonludwig added bug issues reporting wrong behavior lsp labels Dec 9, 2023
@jacksonludwig jacksonludwig changed the title Buffer becomes out of sync with LSP if file changes outside of neovim Buffer becomes out of sync with language server if file changes outside of neovim Dec 9, 2023
@mfussenegger
Copy link
Member

In 0.9 neovim doesn't enable the lsp file watching mechanism by default, so the language server doesn't get notified about changes happening outside of neovim.

You can enable the mechanism by setting the following client capabilities:

workspace = {
  didChangeWatchedFiles = {
    dynamicRegistration = true
  }
}

For 0.10/nightly it's currently enabled by default, but that may still change before the release - depending on #23291

Furthermore, reloading the file (e.g. through :e) doesn't resolve the problem. It's like the buffer or lsp state becomes "stuck" at where it was before the file was changed outside of neovim.

This sounds a bit more like a language server problem, and related to #26131
Most other servers do re-publish diagnostics on :e.

@jacksonludwig
Copy link
Author

Thanks for the info. I see that this is a language server thing. I think I'll close this a duplicate with #26131 then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues reporting wrong behavior duplicate lsp
Projects
None yet
Development

No branches or pull requests

3 participants