Skip to content
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

Diagnostics are updated based on the previous file state if the client sends a completely new state with didClose and didOpen #820

Closed
dmitmel opened this issue Nov 24, 2021 · 0 comments · Fixed by #821
Labels
bug Something isn't working

Comments

@dmitmel
Copy link
Contributor

dmitmel commented Nov 24, 2021

Describe the bug
The client can, in certain situations, send the contents of the entire file all over again by closing the file (textDocument/didClose) and opening it again (textDocument/didOpen) with the new contents. For example, Nvim does that if it "reloads" the file, which can happen if it is modified by some other process outside of the editor. However, this breaks lua-language-server because it doesn't properly resolve text edits sent with textDocument/didChange after the file is "reloaded" - it uses the previous state of the file to apply text edits and generate diagnostics.

To Reproduce
Steps to reproduce the behavior:

  1. a.lua
    function func1()
      if test2 then
        print(1)
      end
      print(2)
    end
    func1()
  2. b.lua
    function func1()
      print(1)
      print(2)
      print(3)
    end
    func1()
  3. $ cp a.lua c.lua
  4. $ nvim c.lua
  5. Make any edit in c.lua, 2gg>>u will do
  6. $ cp b.lua c.lua (don't close the editor, this will cause a "reload" of the file)
  7. Return to the editor, make an edit which would cause a syntax error if it was done in a.lua, e.g. 4ggI--
  8. Misplaced and irrelevant diagnostics!

Expected behavior
After Nvim sends the the didClose and didOpen pair of events (responsible code), subsequent text edits should apply to the new contents (b.lua) and not the previous ones (a.lua).

Screenshots

An example of misplaced diagnostics with c.lua's contents same as b.lua:
image

Notice how they are correct if applied to a.lua with the text edit:
image

Environment (please complete the following information):

  • OS: Arch Linux
  • Client: neovim 0.5.1

Additional context
I already have a PR ready for this, I'm opening a bug ticket just for formality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants