aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/util.lua
diff options
context:
space:
mode:
authorMathias Fußenegger <mfussenegger@users.noreply.github.com>2024-07-27 22:30:14 +0200
committerGitHub <noreply@github.com>2024-07-27 22:30:14 +0200
commitbdff50dee56ebf6de58d58315920abf2f8e262f7 (patch)
treeaa1265a07bfe97b1283ee7ec808a679565fc0870 /runtime/lua/vim/lsp/util.lua
parentaee4254b76206354d74d6fdd4d8e6b640279cedd (diff)
downloadrneovim-bdff50dee56ebf6de58d58315920abf2f8e262f7.tar.gz
rneovim-bdff50dee56ebf6de58d58315920abf2f8e262f7.tar.bz2
rneovim-bdff50dee56ebf6de58d58315920abf2f8e262f7.zip
fix(lsp): revert text edit application order change (#29877)
Reverts https://github.com/neovim/neovim/pull/29212 and adds a few additional test cases From the spec > All text edits ranges refer to positions in the document they are > computed on. They therefore move a document from state S1 to S2 without > describing any intermediate state. Text edits ranges must never overlap, > that means no part of the original document must be manipulated by more > than one edit. However, it is possible that multiple edits have the same > start position: multiple inserts, or any number of inserts followed by a > single remove or replace edit. If multiple inserts have the same > position, the order in the array defines the order in which the inserted > strings appear in the resulting text. The previous fix seems wrong. The important part: > If multiple inserts have the same position, the order in the array > defines the order in which the inserted strings appear in the > resulting text. Emphasis on _appear in the resulting text_ Which means that in: local edits1 = { make_edit(0, 3, 0, 3, { 'World' }), make_edit(0, 3, 0, 3, { 'Hello' }), } `World` must appear before `Hello` in the final text. That means the old logic was correct, and the fix was wrong.
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r--runtime/lua/vim/lsp/util.lua5
1 files changed, 1 insertions, 4 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index b0fd25af3a..59ae3beae4 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -396,10 +396,7 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
if a.range.start.character ~= b.range.start.character then
return a.range.start.character > b.range.start.character
end
- if a._index ~= b._index then
- return a._index < b._index
- end
- return false
+ return a._index > b._index
end)
-- save and restore local marks since they get deleted by nvim_buf_set_lines