mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
[LSP] check for vim.NIL and add apply_text_document_edit tests
This commit is contained in:
parent
e5022c61ed
commit
6dc8398944
@ -160,7 +160,7 @@ function M.apply_text_document_edit(text_document_edit)
|
||||
local text_document = text_document_edit.textDocument
|
||||
local bufnr = vim.uri_to_bufnr(text_document.uri)
|
||||
-- `VersionedTextDocumentIdentifier`s version may be nil https://microsoft.github.io/language-server-protocol/specification#versionedTextDocumentIdentifier
|
||||
if text_document.version ~= nil and M.buf_versions[bufnr] > text_document.version then
|
||||
if text_document.version ~= vim.NIL and M.buf_versions[bufnr] > text_document.version then
|
||||
print("Buffer ", text_document.uri, " newer than edits.")
|
||||
return
|
||||
end
|
||||
|
@ -817,6 +817,62 @@ describe('LSP', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('apply_text_document_edit', function()
|
||||
before_each(function()
|
||||
insert(dedent([[
|
||||
First line of text
|
||||
Second line of text]]))
|
||||
end)
|
||||
it('correctly goes ahead with the edit when all is normal', function()
|
||||
local text_document_edit = {
|
||||
edits = {
|
||||
make_edit(0, 0, 0, 0, "hi")
|
||||
},
|
||||
textDocument = {
|
||||
uri = "file://fake/uri";
|
||||
version = 5
|
||||
}
|
||||
}
|
||||
exec_lua('vim.lsp.util.apply_text_document_edit(...)', text_document_edit, 1)
|
||||
eq({
|
||||
'hiline of text';
|
||||
'Second line of text';
|
||||
}, buf_lines(1))
|
||||
end)
|
||||
it('correctly goes ahead with the edit whe the version is nil', function()
|
||||
local text_document_edit = {
|
||||
edits = {
|
||||
make_edit(0, 0, 0, 0, "hi")
|
||||
},
|
||||
textDocument = {
|
||||
uri = "file://fake/uri";
|
||||
version = vim.NIL
|
||||
}
|
||||
}
|
||||
exec_lua('vim.lsp.util.apply_text_document_edit(...)', text_document_edit, 1)
|
||||
eq({
|
||||
'hiline of text';
|
||||
'Second line of text';
|
||||
}, buf_lines(1))
|
||||
end)
|
||||
it('skips the edit if the version of the edit is behind the local buffer ', function()
|
||||
local text_document_edit = {
|
||||
edits = {
|
||||
make_edit(0, 0, 0, 0, "hi")
|
||||
},
|
||||
textDocument = {
|
||||
uri = "file://fake/uri";
|
||||
version = 1
|
||||
}
|
||||
}
|
||||
exec_lua('vim.lsp.util.apply_text_document_edit(...)', text_document_edit, 1)
|
||||
eq({
|
||||
'First line of text';
|
||||
'Second line of text';
|
||||
}, buf_lines(1))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('completion_list_to_complete_items', function()
|
||||
-- Completion option precedence:
|
||||
-- textEdit.newText > insertText > label
|
||||
|
Loading…
Reference in New Issue
Block a user