mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 03:15:39 +00:00
Merge pull request #12237 from h-michael/vim-nil
lsp: text_document.version may be vim.NIL not nil
This commit is contained in:
@@ -160,7 +160,7 @@ function M.apply_text_document_edit(text_document_edit)
|
|||||||
local text_document = text_document_edit.textDocument
|
local text_document = text_document_edit.textDocument
|
||||||
local bufnr = vim.uri_to_bufnr(text_document.uri)
|
local bufnr = vim.uri_to_bufnr(text_document.uri)
|
||||||
-- `VersionedTextDocumentIdentifier`s version may be nil https://microsoft.github.io/language-server-protocol/specification#versionedTextDocumentIdentifier
|
-- `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.")
|
print("Buffer ", text_document.uri, " newer than edits.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -770,13 +770,14 @@ describe('LSP', function()
|
|||||||
exec_lua([[require'vim.lsp'; return vim.fn.getcompletion('Lsp', 'highlight')]]))
|
exec_lua([[require'vim.lsp'; return vim.fn.getcompletion('Lsp', 'highlight')]]))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('apply_edits', function()
|
describe('apply_text_edits', function()
|
||||||
before_each(function()
|
before_each(function()
|
||||||
insert(dedent([[
|
insert(dedent([[
|
||||||
First line of text
|
First line of text
|
||||||
Second line of text
|
Second line of text
|
||||||
Third line of text
|
Third line of text
|
||||||
Fourth line of text]]))
|
Fourth line of text
|
||||||
|
å å ɧ 汉语 ↥ 🤦 🦄]]))
|
||||||
end)
|
end)
|
||||||
it('applies apply simple edits', function()
|
it('applies apply simple edits', function()
|
||||||
local edits = {
|
local edits = {
|
||||||
@@ -790,6 +791,7 @@ describe('LSP', function()
|
|||||||
'2econd line of text';
|
'2econd line of text';
|
||||||
'3ird line of text';
|
'3ird line of text';
|
||||||
'Fourth line of text';
|
'Fourth line of text';
|
||||||
|
'å å ɧ 汉语 ↥ 🤦 🦄';
|
||||||
}, buf_lines(1))
|
}, buf_lines(1))
|
||||||
end)
|
end)
|
||||||
it('applies complex edits', function()
|
it('applies complex edits', function()
|
||||||
@@ -813,8 +815,104 @@ describe('LSP', function()
|
|||||||
'The next line of text';
|
'The next line of text';
|
||||||
'another line of text';
|
'another line of text';
|
||||||
'before this!';
|
'before this!';
|
||||||
|
'å å ɧ 汉语 ↥ 🤦 🦄';
|
||||||
}, buf_lines(1))
|
}, buf_lines(1))
|
||||||
end)
|
end)
|
||||||
|
pending('applies non-ASCII characters edits', function()
|
||||||
|
-- FIXME: We don't handle non-ASCII characters well in UTF-16
|
||||||
|
local edits = {
|
||||||
|
make_edit(4, 0, 4, 14, {"a a h"});
|
||||||
|
}
|
||||||
|
exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1)
|
||||||
|
eq({
|
||||||
|
'First line of text';
|
||||||
|
'Second line of text';
|
||||||
|
'Third line of text';
|
||||||
|
'Fourth line of text';
|
||||||
|
'a a h';
|
||||||
|
}, buf_lines(1))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe('apply_text_document_edit', function()
|
||||||
|
local target_bufnr
|
||||||
|
before_each(function()
|
||||||
|
target_bufnr = exec_lua [[
|
||||||
|
local bufnr = vim.fn.bufadd("fake/uri")
|
||||||
|
local lines = {"1st line of text", "2nd line of text"}
|
||||||
|
vim.api.nvim_buf_set_lines(bufnr, 0, 1, false, lines)
|
||||||
|
return bufnr
|
||||||
|
]]
|
||||||
|
end)
|
||||||
|
it('correctly goes ahead with the edit if all is normal', function()
|
||||||
|
local text_document_edit = {
|
||||||
|
edits = {
|
||||||
|
make_edit(0, 0, 0, 3, "First")
|
||||||
|
},
|
||||||
|
textDocument = {
|
||||||
|
uri = "file://fake/uri";
|
||||||
|
version = 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exec_lua([[
|
||||||
|
local args = {...}
|
||||||
|
local target_bufnr = args[2]
|
||||||
|
vim.lsp.util.buf_versions[target_bufnr] = 4
|
||||||
|
vim.lsp.util.apply_text_document_edit(...)
|
||||||
|
]], text_document_edit, target_bufnr)
|
||||||
|
eq({
|
||||||
|
'First line of text';
|
||||||
|
'2nd line of text';
|
||||||
|
}, buf_lines(target_bufnr))
|
||||||
|
end)
|
||||||
|
it('correctly goes ahead with the edit if the version is vim.NIL', function()
|
||||||
|
-- we get vim.NIL when we decode json null value.
|
||||||
|
local json = exec_lua[[
|
||||||
|
return vim.fn.json_decode("{ \"a\": 1, \"b\": null }")
|
||||||
|
]]
|
||||||
|
eq(json.b, exec_lua("return vim.NIL"))
|
||||||
|
|
||||||
|
local text_document_edit = {
|
||||||
|
edits = {
|
||||||
|
make_edit(0, 0, 0, 3, "First")
|
||||||
|
},
|
||||||
|
textDocument = {
|
||||||
|
uri = "file://fake/uri";
|
||||||
|
version = exec_lua("return vim.NIL")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exec_lua([[
|
||||||
|
local args = {...}
|
||||||
|
local target_bufnr = args[2]
|
||||||
|
vim.lsp.util.buf_versions[target_bufnr] = vim.NIL
|
||||||
|
vim.lsp.util.apply_text_document_edit(...)
|
||||||
|
]], text_document_edit, target_bufnr)
|
||||||
|
eq({
|
||||||
|
'First line of text';
|
||||||
|
'2nd line of text';
|
||||||
|
}, buf_lines(target_bufnr))
|
||||||
|
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, 3, "First")
|
||||||
|
},
|
||||||
|
textDocument = {
|
||||||
|
uri = "file://fake/uri";
|
||||||
|
version = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exec_lua([[
|
||||||
|
local args = {...}
|
||||||
|
local target_bufnr = args[2]
|
||||||
|
vim.lsp.util.buf_versions[target_bufnr] = 2
|
||||||
|
vim.lsp.util.apply_text_document_edit(...)
|
||||||
|
]], text_document_edit, target_bufnr)
|
||||||
|
eq({
|
||||||
|
'1st line of text';
|
||||||
|
'2nd line of text';
|
||||||
|
}, buf_lines(target_bufnr))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('completion_list_to_complete_items', function()
|
describe('completion_list_to_complete_items', function()
|
||||||
|
|||||||
Reference in New Issue
Block a user