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
Renaming bug "Buffer X newer than edits" #12970
Comments
Having the same problem with Every code action from Edit: It looks like some language servers just don't pass version number back. |
This still happens with even the most up-to-date neovim? And to be clear, |
According to this piece of code I think yes:
Here's related logic, which didn't change, so I guess it should still happen. neovim/runtime/lua/vim/lsp/util.lua Lines 265 to 272 in cc23c95
I feel like lsp should return same version back, or higher version. |
Instead of commenting it out, you could probably just do something like this anywhere in your config: vim.lsp.util.apply_text_document_edit = function(text_document_edit, index)
local text_document = text_document_edit.textDocument
local bufnr = vim.uri_to_bufnr(text_document.uri)
vim.lsp.util.apply_text_edits(text_document_edit.edits, bufnr)
end This way you don't have to have a custom patch to override the thing :) |
I'm not sure what we should do about adding cases to handle misbehaving clients... it's possible we could pass in the client id and allow you to set a flag that could ignore this, but that seems kind of overkill for them not following the spec correctly :/ I'm not sure of the right move forward. |
jdtls has the same bug, which led to workarounds: Still waiting on a response in the upstream repository. |
The eclipse.jdt.ls maintainers responsed and agree that it's a bug in the server. I now also left a comment in the svelte issue. I think the current check within neovim makes sense and we should keep it instead of adding a workaround for servers who don't follow the spec. |
If this happens for any additional servers, the policy should be to report upstream and add a mitigation in nvim-lspconfig like neovim/nvim-lspconfig@486f72a. I agree with TJ that we shouldn't add any mitigations in core for misbehaving servers. |
There were a couple of reports of "Buffer X newer than edits" problems. We first assumed that it is incorrect for a server to send 0 as a version - and stated that they should send a `null` instead, given that in the specification the `textDocument` of a `TextDocumentEdit` is a `OptionalVersionedTextDocumentIdentifier`. But it turns out that this was a change in 3.16, and in 3.15 and earlier versions of the specification it was a `VersionedTextDocumentIdentifier` and language servers didn't have a better option than sending `0` if they don't keep track of the version numbers. So this changes the version check to always accept `0` values. See - neovim#12970 - neovim#14256 - haskell/haskell-language-server#1727
Notice the workaround tjdevries provided would now be the following: vim.lsp.util.apply_text_document_edit = function(text_document_edit, index, offset_encoding)
local text_document = text_document_edit.textDocument
local bufnr = vim.uri_to_bufnr(text_document.uri)
if offset_encoding == nil then
vim.notify_once('apply_text_document_edit must be called with valid offset encoding', vim.log.levels.WARN)
end
vim.lsp.util.apply_text_edits(text_document_edit.edits, bufnr, offset_encoding)
end Notice the the 3rd parameter. |
I am trying to make a patch/hotfix/workaround on volar lspconfig as their Following the commit mentioned by @mjlbach, I have tried adding the handler in both The gist below is the minimal configuration for volar setup plus attempt on patching it. https://gist.github.com/Holi0317/74ebabbd14fdd76ac3bf68360ae75527 |
nvim --version
:rust-analyzer --version
"rust-analyzer e70cf70"nvim -c ":checkhealth nvim nvim_lsp"
health#nvim#check
Configuration
Performance
Remote Plugins
terminal
tmux
default-terminal
setting. Colors might look wrong.health#nvim_lsp#check
Checking language server protocol configuration
lsp.log
[ DEBUG ] 2020-09-23T14:22:40-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp.lua:640 ] "LSP[rust_analyzer]" "client.request" 1 "textDocument/rename" { newName = "my_var", position = { character = 8, line = 1 }, textDocument = { uri = "file:///tmp/tester/src/main.rs" }} <function 1> 1
[ DEBUG ] 2020-09-23T14:22:40-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:361 ] "rpc.send.payload" { id = 5, jsonrpc = "2.0", method = "textDocument/rename", params = { newName = "my_var", position = { character = 8, line = 1 }, textDocument = { uri = "file:///tmp/tester/src/main.rs" } }}
[ DEBUG ] 2020-09-23T14:22:40-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ] "decoded" { id = 5, jsonrpc = "2.0", result = { documentChanges = { { edits = { { newText = "my_var", range = { end = { character = 9, line = 1 }, start = { character = 8, line = 1 } } } }, textDocument = { uri = "file:///tmp/tester/src/main.rs", version = 0 } }, { edits = { { newText = "my_var", range = { end = { character = 13, line = 3 }, start = { character = 12, line = 3 } } } }, textDocument = { uri = "file:///tmp/tester/src/main.rs", version = 0 } } } }}
[ DEBUG ] 2020-09-23T14:22:40-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/callbacks.lua:332 ] "default_callback" "textDocument/rename" { bufnr = 1, client_id = 1, params = { documentChanges = { { edits = { { newText = "my_var", range = { end = { character = 9, line = 1 }, start = { character = 8, line = 1 } } } }, textDocument = { uri = "file:///tmp/tester/src/main.rs", version = 0 } }, { edits = { { newText = "my_var", range = { end = { character = 13, line = 3 }, start = { character = 12, line = 3 } } } }, textDocument = { uri = "file:///tmp/tester/src/main.rs", version = 0 } } } }}
[ DEBUG ] 2020-09-23T14:22:40-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp.lua:765 ] "on_lines bufnr: 1, changedtick: 4, firstline: 1, lastline: 2, new_lastline: 2, old_byte_size: 20, old_utf32_size: 20, old_utf16_size: 20" { ' let my_var = "test";' }
[ DEBUG ] 2020-09-23T14:22:40-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:361 ] "rpc.send.payload" { jsonrpc = "2.0", method = "textDocument/didChange", params = { contentChanges = { { text = 'fn main() {\n let my_var = "test";\n\n let b = a;\n println!("b: {}", b);\n}\n' } }, textDocument = { uri = "file:///tmp/tester/src/main.rs", version = 4 } }}
[ DEBUG ] 2020-09-23T14:22:40-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp.lua:640 ] "LSP[rust_analyzer]" "client.request" 1 "rust-analyzer/inlayHints" { textDocument = { uri = "file:///tmp/tester/src/main.rs" }} <function 1> 1
[ DEBUG ] 2020-09-23T14:22:40-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:361 ] "rpc.send.payload" { id = 6, jsonrpc = "2.0", method = "rust-analyzer/inlayHints", params = { textDocument = { uri = "file:///tmp/tester/src/main.rs" } }}
[ DEBUG ] 2020-09-23T14:22:40-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ] "decoded" { jsonrpc = "2.0", method = "textDocument/publishDiagnostics", params = { diagnostics = {}, uri = "file:///tmp/tester/src/main.rs", version = 4 }}
[ DEBUG ] 2020-09-23T14:22:40-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ] "decoded" { id = 6, jsonrpc = "2.0", result = { { kind = "TypeHint", label = "&str", range = { end = { character = 14, line = 1 }, start = { character = 8, line = 1 } } } }}
[ DEBUG ] 2020-09-23T14:22:40-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp.lua:434 ] "notification" "textDocument/publishDiagnostics" { diagnostics = {}, uri = "file:///tmp/tester/src/main.rs", version = 4}
[ DEBUG ] 2020-09-23T14:22:42-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp.lua:640 ] "LSP[rust_analyzer]" "client.request" 1 "rust-analyzer/inlayHints" { textDocument = { uri = "file:///tmp/tester/src/main.rs" }} <function 1> 1
[ DEBUG ] 2020-09-23T14:22:42-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:361 ] "rpc.send.payload" { id = 7, jsonrpc = "2.0", method = "rust-analyzer/inlayHints", params = { textDocument = { uri = "file:///tmp/tester/src/main.rs" } }}
[ DEBUG ] 2020-09-23T14:22:42-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ] "decoded" { id = 7, jsonrpc = "2.0", result = { { kind = "TypeHint", label = "&str", range = { end = { character = 14, line = 1 }, start = { character = 8, line = 1 } } } }}
[ DEBUG ] 2020-09-23T14:22:42-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp.lua:640 ] "LSP[rust_analyzer]" "client.request" 1 "rust-analyzer/inlayHints" { textDocument = { uri = "file:///tmp/tester/src/main.rs" }} <function 1> 1
[ DEBUG ] 2020-09-23T14:22:42-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:361 ] "rpc.send.payload" { id = 8, jsonrpc = "2.0", method = "rust-analyzer/inlayHints", params = { textDocument = { uri = "file:///tmp/tester/src/main.rs" } }}
[ DEBUG ] 2020-09-23T14:22:42-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ] "decoded" { id = 8, jsonrpc = "2.0", result = { { kind = "TypeHint", label = "&str", range = { end = { character = 14, line = 1 }, start = { character = 8, line = 1 } } } }}
[ DEBUG ] 2020-09-23T14:22:42-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp.lua:640 ] "LSP[rust_analyzer]" "client.request" 1 "rust-analyzer/inlayHints" { textDocument = { uri = "file:///tmp/tester/src/main.rs" }} <function 1> 1
[ DEBUG ] 2020-09-23T14:22:42-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:361 ] "rpc.send.payload" { id = 9, jsonrpc = "2.0", method = "rust-analyzer/inlayHints", params = { textDocument = { uri = "file:///tmp/tester/src/main.rs" } }}
[ DEBUG ] 2020-09-23T14:22:42-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ] "decoded" { id = 9, jsonrpc = "2.0", result = { { kind = "TypeHint", label = "&str", range = { end = { character = 14, line = 1 }, start = { character = 8, line = 1 } } } }}
[ DEBUG ] 2020-09-23T14:22:43-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp.lua:640 ] "LSP[rust_analyzer]" "client.request" 1 "rust-analyzer/inlayHints" { textDocument = { uri = "file:///tmp/tester/src/main.rs" }} <function 1> 1
[ DEBUG ] 2020-09-23T14:22:43-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:361 ] "rpc.send.payload" { id = 10, jsonrpc = "2.0", method = "rust-analyzer/inlayHints", params = { textDocument = { uri = "file:///tmp/tester/src/main.rs" } }}
[ DEBUG ] 2020-09-23T14:22:43-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ] "decoded" { id = 10, jsonrpc = "2.0", result = { { kind = "TypeHint", label = "&str", range = { end = { character = 14, line = 1 }, start = { character = 8, line = 1 } } } }}
[ DEBUG ] 2020-09-23T14:22:43-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp.lua:765 ] "on_lines bufnr: 1, changedtick: 5, firstline: 3, lastline: 4, new_lastline: 4, old_byte_size: 15, old_utf32_size: 15, old_utf16_size: 15" { " let b = a; " }
[ DEBUG ] 2020-09-23T14:22:43-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:361 ] "rpc.send.payload" { jsonrpc = "2.0", method = "textDocument/didChange", params = { contentChanges = { { text = 'fn main() {\n let my_var = "test";\n\n let b = a; \n println!("b: {}", b);\n}\n' } }, textDocument = { uri = "file:///tmp/tester/src/main.rs", version = 5 } }}
[ DEBUG ] 2020-09-23T14:22:43-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ] "decoded" { jsonrpc = "2.0", method = "textDocument/publishDiagnostics", params = { diagnostics = {}, uri = "file:///tmp/tester/src/main.rs", version = 5 }}
[ DEBUG ] 2020-09-23T14:22:43-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp.lua:434 ] "notification" "textDocument/publishDiagnostics" { diagnostics = {}, uri = "file:///tmp/tester/src/main.rs", version = 5}
[ DEBUG ] 2020-09-23T14:22:43-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp.lua:765 ] "on_lines bufnr: 1, changedtick: 6, firstline: 3, lastline: 4, new_lastline: 4, old_byte_size: 16, old_utf32_size: 16, old_utf16_size: 16" { " let b = a; ?" }
[ DEBUG ] 2020-09-23T14:22:43-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:361 ] "rpc.send.payload" { jsonrpc = "2.0", method = "textDocument/didChange", params = { contentChanges = { { text = 'fn main() {\n let my_var = "test";\n\n let b = a; ?\n println!("b: {}", b);\n}\n' } }, textDocument = { uri = "file:///tmp/tester/src/main.rs", version = 6 } }}
[ DEBUG ] 2020-09-23T14:22:43-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ] "decoded" { jsonrpc = "2.0", method = "textDocument/publishDiagnostics", params = { diagnostics = { { message = "Syntax Error: expected expression", range = { end = { character = 15, line = 3 }, start = { character = 15, line = 3 } }, severity = 1, source = "rust-analyzer" }, { message = "Syntax Error: expected SEMICOLON", range = { end = { character = 16, line = 3 }, start = { character = 16, line = 3 } }, severity = 1, source = "rust-analyzer" } }, uri = "file:///tmp/tester/src/main.rs", version = 6 }}
[ DEBUG ] 2020-09-23T14:22:43-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp.lua:434 ] "notification" "textDocument/publishDiagnostics" { diagnostics = { { message = "Syntax Error: expected expression", range = { end = { character = 15, line = 3 }, start = { character = 15, line = 3 } }, severity = 1, source = "rust-analyzer" }, { message = "Syntax Error: expected SEMICOLON", range = { end = { character = 16, line = 3 }, start = { character = 16, line = 3 } }, severity = 1, source = "rust-analyzer" } }, uri = "file:///tmp/tester/src/main.rs", version = 6}
[ DEBUG ] 2020-09-23T14:22:44-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp.lua:765 ] "on_lines bufnr: 1, changedtick: 7, firstline: 3, lastline: 4, new_lastline: 4, old_byte_size: 17, old_utf32_size: 17, old_utf16_size: 17" { " let b = a; ??" }
[ DEBUG ] 2020-09-23T14:22:44-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:361 ] "rpc.send.payload" { jsonrpc = "2.0", method = "textDocument/didChange", params = { contentChanges = { { text = 'fn main() {\n let my_var = "test";\n\n let b = a; ??\n println!("b: {}", b);\n}\n' } }, textDocument = { uri = "file:///tmp/tester/src/main.rs", version = 7 } }}
[ DEBUG ] 2020-09-23T14:22:44-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ] "decoded" { jsonrpc = "2.0", method = "textDocument/publishDiagnostics", params = { diagnostics = { { message = "Syntax Error: expected expression", range = { end = { character = 15, line = 3 }, start = { character = 15, line = 3 } }, severity = 1, source = "rust-analyzer" }, { message = "Syntax Error: expected SEMICOLON", range = { end = { character = 16, line = 3 }, start = { character = 16, line = 3 } }, severity = 1, source = "rust-analyzer" }, { message = "Syntax Error: expected expression", range = { end = { character = 16, line = 3 }, start = { character = 16, line = 3 } }, severity = 1, source = "rust-analyzer" }, { message = "Syntax Error: expected SEMICOLON", range = { end = { character = 17, line = 3 }, start = { character = 17, line = 3 } }, severity = 1, source = "rust-analyzer" } }, uri = "file:///tmp/tester/src/main.rs", version = 7 }}
[ DEBUG ] 2020-09-23T14:22:44-0400 ] /usr/local/share/nvim/runtime/lua/vim/lsp.lua:434 ] "notification" "textDocument/publishDiagnostics" { diagnostics = { { message = "Syntax Error: expected expression", range = { end = { character = 15, line = 3 }, start = { character = 15, line = 3 } }, severity = 1, source = "rust-analyzer" }, { message = "Syntax Error: expected SEMICOLON", range = { end = { character = 16, line = 3 }, start = { character = 16, line = 3 } }, severity = 1, source = "rust-analyzer" }, { message = "Syntax Error: expected expression", range = { end = { character = 16, line = 3 }, start = { character = 16, line = 3 } }, severity = 1, source = "rust-analyzer" }, { message = "Syntax Error: expected SEMICOLON", range = { end = { character = 17, line = 3 }, start = { character = 17, line = 3 } }, severity = 1, source = "rust-analyzer" } }, uri = "file:///tmp/tester/src/main.rs", version = 7}
Steps to reproduce using
nvim -u NORC
Actual behaviour
Note: It prints out the print() from here:
neovim/runtime/lua/vim/lsp/util.lua
Line 220 in f34eeba
Expected behaviour
Renaming all occurences in buffer.
Note, if I comment out the return from util.lua above, it seems to work properly.
The text was updated successfully, but these errors were encountered: