-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
lsp: deleting entire file breaks incremental synchronization #27383
Comments
i get a similar error when |
Yeah, I've seen desyncs happen like that, but I couldn't figure out how to reliably reproduce it. |
dear god this issue is constant. i'm running neovim |
For what it's worth, I've noticed similar issues with |
This is a different issue. I can reproduce this one regardless of if didChangeWatchedFiles is on or off. |
Angular language service crashes with
Not sure if related but
note that |
Looks like this may be a duplicate of #16259 |
This line seems to be describing the issue, but I can still reproduce the bug. https://github.com/neovim/neovim/blob/master/runtime/lua/vim/lsp/_changetracking.lua#L101 Perhaps this fixes it internally, but doesn't share with the language servers? |
This comment was marked as off-topic.
This comment was marked as off-topic.
That sounds like a very different issue. |
Problem
Neovim generates an invalid
textDocument/didChange
message when deleting and pasting the entire file.The message references the range {line 0 col 0 - line 1 col 0}, but when you delete the entire file, there is no line 1.
I'm making a language server, and my server gets confused by this range, because it goes past the end of the file.
Every other language server I've tried seems to tolerate the invalid message, but I'm fairly sure Neovim's behavior isn't correct.
Steps to reproduce using "nvim -u minimal_init.lua"
You should be able to reproduce this really easily with almost any setup, as long as the language supports the
{"change":2}
mode. (pretty much all language servers do this).At this point, skip down to the Steps section.
Probably unnecessary details
If you really want the exact same setup as me, you can follow these steps:
The exact steps to set up the environment
Download fennel-ls and put it on the path. To run it, you also need need
lua
on the path, because fennel-ls runs in lua.Then, init.lua:
I know bufenter is the wrong autocmd, but there is no filetype for .fnl.
Then,
touch .editorconfig
so that the current dir is a root dir.fennel-ls
needs a workspace to run in, so this is important.Finally, run the following steps, using
broken.fnl
as the filename.Steps
o
)dG
to delete everythingp
to paste everything backDescription of each sync step
For each step, I'll show the
textDocument/didOpen
andtextDocument/didChange
messages that are sent to the server, and what the file should contain.Open a new file that starts a language server
Okay, so Neovim starts an "empty" file with a newline. That's fine. The contents of the file are
"\n"
.Type any text.
In this instance, I simply typed the letter
o
.Okay, so we take the range {line 0 char 0 - line 0 char 0} and replace it with
"o"
. The contents of the file are"o\n"
.Delete everything
Okay, so we replace from {line 0 char 0 - line 1 char 0} with "". Now, the current content of the file is
""
, with no newline. The file is empty.Press
p
Here's where I've got a problem. According to the previous messages, the file's contents are
""
. It's empty. However, the server is being asked to replace from {line 0 char 0 - line 1 char 0} with some text.There is no position that corresponds to line 1 char 0, because there is no newline character in the file, and therefore no line 1.
Now, you may argue that the protocol says:
However, this doesn't apply here, because there is no "line ending character(s)" that could possibly be included here. I believe that Neovim's message isn't valid, and that it is correct for the language server to crash.
Expected behavior
I expected the the content changes to be applicable to the file. For example: I would be okay if the final message did not try to reference line 1:
It would also be okay if instead, there was an extra "contentChanges" message after the
dP
that re-introduces the newline after telling the server that the newline was deleted. I'm not sure exactly where the server and client are desyncing, but I would like them to stay in sync.Neovim version (nvim -v)
0.9.5 Release
Language server name/version
fennel-ls 0.1.0
Operating system/version
Arch Linux
Log file
https://gist.github.com/XeroOl/873a8ab9968861cf33c73f8acea3ab28
The text was updated successfully, but these errors were encountered: