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

Text document version is implemented incorrectly #1490

Closed
Holi0317 opened this issue Jun 21, 2022 · 5 comments
Closed

Text document version is implemented incorrectly #1490

Holi0317 opened this issue Jun 21, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@Holi0317
Copy link

I am using neovim as the client. Whenever I apply a code action, neovim shows a warning saying "Buffer X newer than edits".

Searching through the Internet points me to this issue on neovim: neovim/neovim#12970.

A quick hack on neovim code shows that in my case, volar is reporting text_document.version as 5 while neovim is having 14.

Volar is at version 0.38.1.

@Holi0317
Copy link
Author

Related logs and neovim config: https://gist.github.com/Holi0317/4463e117942cbc2c9533ceae2b9c937c

System information

  • Volar 0.38.1
  • Neovim v0.7.0

Step to reproduce

  1. Create a vite vue typescript project
  2. Edit a .vue file
  3. Edit and add const a = computed(() => false) in <script> block
  4. Move cursor on computed (which should be a missing import)
  5. Invoke code action (<space>a in the config given), choose "Add import from vue"
  6. Neovim complains text document version mismatch

Diagnostic

The log attached in the gist only contains a section of the whole lsp log. However it is clear that neovim did indicate textDocument.version == 44 in the last textDocument/didChange call and volar returns textDocument.version == 32 in all the suggested edits in code action response.

@yaegassy
Copy link
Collaborator

yaegassy commented Jun 23, 2022

Hi, @Holi0317

Thanks for the steps to reproduce this in Neovim.

This problem is probably a known defect. However, I cannot reproduce it in VSCode on my environment. Can you reproduce this issue in VSCode? If VSCode can reproduce the problem, it may be possible to correct it.

@Holi0317
Copy link
Author

Hey @yaegassy,

I've tried to do the code action thing on vscode. Here is the related logs: https://gist.github.com/Holi0317/7498749499be45f77d9410e167bca677

Seems that the behavior of volar are the same in vscode and neovim. But vscode ignores the incorrect textDocument.version and apply the changes volar propose even if the version is lower than the one in vscode. I think it might be just because vscode's client implementation does not care textDocument.version when applying code action.

The lsp spec says the version should always be increasing: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#optionalVersionedTextDocumentIdentifier

Have tried similar action on tsserver (ask the server apply missing import for me) and tsserver respond with correct (increasing) textDocument.version.

@yaegassy
Copy link
Collaborator

yaegassy commented Jun 23, 2022

@Holi0317 Thanks for checking the behavior in VSCode. I think we have made a step forward in solving this problem.

BTW, I am the maintainer of coc-volar. coc-volar currently avoids the bug by adjusting the document version when executing code action etc.

@vanarok
Copy link

vanarok commented Jun 25, 2022

A workaround? Please.

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

No branches or pull requests

4 participants