diff options
author | ckipp01 <ckipp@pm.me> | 2020-04-27 10:55:06 +0200 |
---|---|---|
committer | ckipp01 <ckipp@pm.me> | 2020-05-01 17:40:03 +0200 |
commit | 6dc8398944fd86038b07d77fcab92cd282555dee (patch) | |
tree | 9bdbff478451eb42afb20fc0153e4cccf81a4ef5 | |
parent | e5022c61ed769153dab5a91752c52a8f9ad3b504 (diff) | |
download | rneovim-6dc8398944fd86038b07d77fcab92cd282555dee.tar.gz rneovim-6dc8398944fd86038b07d77fcab92cd282555dee.tar.bz2 rneovim-6dc8398944fd86038b07d77fcab92cd282555dee.zip |
[LSP] check for vim.NIL and add apply_text_document_edit tests
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 2 | ||||
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 56 |
2 files changed, 57 insertions, 1 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 68f3b35df3..82b9a0b3aa 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -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 diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index fdbe45c09a..53530eb513 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -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 |