aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2021-01-11 11:39:11 -0500
committerGitHub <noreply@github.com>2021-01-11 11:39:11 -0500
commite0a4399adc4472b9b02a26c7f93b056c4725a6b9 (patch)
tree81980fd4f008fd4f404a913bd3d40d86c327b1de /runtime
parent0c0c3ee330c9e3aa7d6f054073b999c5f8001472 (diff)
downloadrneovim-e0a4399adc4472b9b02a26c7f93b056c4725a6b9.tar.gz
rneovim-e0a4399adc4472b9b02a26c7f93b056c4725a6b9.tar.bz2
rneovim-e0a4399adc4472b9b02a26c7f93b056c4725a6b9.zip
fix(lsp): Allow subsequent text document edits to pass (#13534)
* fix: Allow subsequent text document edits to pass * fixup: cleaner code * add tests
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/lsp.txt10
-rw-r--r--runtime/lua/vim/lsp/util.lua24
2 files changed, 24 insertions, 10 deletions
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index 6ca7b52fff..88e8275b44 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -1400,9 +1400,15 @@ show_line_diagnostics({opts}, {bufnr}, {line_nr}, {client_id})
Lua module: vim.lsp.util *lsp-util*
*vim.lsp.util.apply_text_document_edit()*
-apply_text_document_edit({text_document_edit})
+apply_text_document_edit({text_document_edit}, {index})
+ Applies a `TextDocumentEdit` , which is a list of changes to a
+ single document.
+
Parameters: ~
- {text_document_edit} (table) a `TextDocumentEdit` object
+ {text_document_edit} table: a `TextDocumentEdit` object
+ {index} number: Optional index of the edit,
+ if from a list of edits (or nil, if
+ not from a list)
See also: ~
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentEdit
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index ecff95f61e..e33e0109b6 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -254,19 +254,27 @@ function M.extract_completion_items(result)
end
--- Applies a `TextDocumentEdit`, which is a list of changes to a single
--- document.
+--- document.
---
---@param text_document_edit (table) a `TextDocumentEdit` object
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentEdit
-function M.apply_text_document_edit(text_document_edit)
+---@param text_document_edit table: a `TextDocumentEdit` object
+---@param index number: Optional index of the edit, if from a list of edits (or nil, if not from a list)
+---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentEdit
+function M.apply_text_document_edit(text_document_edit, index)
local text_document = text_document_edit.textDocument
local bufnr = vim.uri_to_bufnr(text_document.uri)
+ -- For lists of text document edits,
+ -- do not check the version after the first edit.
+ local should_check_version = true
+ if index and index > 1 then
+ should_check_version = false
+ end
+
-- `VersionedTextDocumentIdentifier`s version may be null
-- https://microsoft.github.io/language-server-protocol/specification#versionedTextDocumentIdentifier
- if text_document.version
+ if should_check_version and (text_document.version
and M.buf_versions[bufnr]
- and M.buf_versions[bufnr] > text_document.version then
+ and M.buf_versions[bufnr] > text_document.version) then
print("Buffer ", text_document.uri, " newer than edits.")
return
end
@@ -459,12 +467,12 @@ end
-- @see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit
function M.apply_workspace_edit(workspace_edit)
if workspace_edit.documentChanges then
- for _, change in ipairs(workspace_edit.documentChanges) do
+ for idx, change in ipairs(workspace_edit.documentChanges) do
if change.kind then
-- TODO(ashkan) handle CreateFile/RenameFile/DeleteFile
error(string.format("Unsupported change: %q", vim.inspect(change)))
else
- M.apply_text_document_edit(change)
+ M.apply_text_document_edit(change, idx)
end
end
return