aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/lsp.txt16
-rw-r--r--runtime/lua/vim/lsp/protocol.lua3
-rw-r--r--runtime/lua/vim/lsp/util.lua4
-rw-r--r--test/functional/plugin/lsp_spec.lua57
4 files changed, 56 insertions, 24 deletions
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index 9deaf26983..3a93390210 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -164,21 +164,21 @@ name: >
LSP HIGHLIGHT *lsp-highlight*
*hl-LspDiagnosticsError*
-LspDiagnosticsError used for "Error" diagnostic virtual text
+LspDiagnosticsError used for "Error" diagnostic virtual text
*hl-LspDiagnosticsErrorSign*
-LspDiagnosticsErrorSign used for "Error" diagnostic signs in sign column
+LspDiagnosticsErrorSign used for "Error" diagnostic signs in sign column
*hl-LspDiagnosticsWarning*
-LspDiagnosticsWarning used for "Warning" diagnostic virtual text
+LspDiagnosticsWarning used for "Warning" diagnostic virtual text
*hl-LspDiagnosticsWarningSign*
-LspDiagnosticsWarningSign used for "Warning" diagnostic signs in sign column
+LspDiagnosticsWarningSign used for "Warning" diagnostic signs in sign column
*hl-LspDiagnosticsInformation*
-LspDiagnosticInformation used for "Information" diagnostic virtual text
+LspDiagnosticsInformation used for "Information" diagnostic virtual text
*hl-LspDiagnosticsInformationSign*
-LspDiagnosticInformationSign used for "Information" signs in sign column
+LspDiagnosticsInformationSign used for "Information" signs in sign column
*hl-LspDiagnosticsHint*
-LspDiagnosticHint used for "Hint" diagnostic virtual text
+LspDiagnosticsHint used for "Hint" diagnostic virtual text
*hl-LspDiagnosticsHintSign*
-LspDiagnosticHintSign used for "Hint" diagnostic signs in sign column
+LspDiagnosticsHintSign used for "Hint" diagnostic signs in sign column
*hl-LspReferenceText*
LspReferenceText used for highlighting "text" references
*hl-LspReferenceRead*
diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua
index 64911fe7bb..4fded1961d 100644
--- a/runtime/lua/vim/lsp/protocol.lua
+++ b/runtime/lua/vim/lsp/protocol.lua
@@ -897,7 +897,8 @@ function protocol.resolve_capabilities(server_capabilities)
text_document_will_save = ifnil(textDocumentSync.willSave, false);
text_document_will_save_wait_until = ifnil(textDocumentSync.willSaveWaitUntil, false);
text_document_save = ifnil(textDocumentSync.save, false);
- text_document_save_include_text = ifnil(textDocumentSync.save and textDocumentSync.save.includeText, false);
+ text_document_save_include_text = ifnil(type(textDocumentSync.save) == 'table'
+ and textDocumentSync.save.includeText, false);
}
else
return nil, string.format("Invalid type for textDocumentSync: %q", type(textDocumentSync))
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 49e2557c16..4c3c4fa6cb 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -92,7 +92,7 @@ local function sort_by_key(fn)
end
end
local edit_sort_key = sort_by_key(function(e)
- return {e.A[1], e.A[2], e.i}
+ return {e.A[1], e.A[2], -e.i}
end)
--- Position is a https://microsoft.github.io/language-server-protocol/specifications/specification-current/#position
@@ -841,7 +841,7 @@ function M.open_floating_preview(contents, filetype, opts)
end
api.nvim_buf_set_lines(floating_bufnr, 0, -1, true, contents)
api.nvim_buf_set_option(floating_bufnr, 'modifiable', false)
- M.close_preview_autocmd({"CursorMoved", "CursorMovedI", "BufHidden"}, floating_winnr)
+ M.close_preview_autocmd({"CursorMoved", "CursorMovedI", "BufHidden", "BufLeave"}, floating_winnr)
return floating_bufnr, floating_winnr
end
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index ae436360c3..1ab81a0ef8 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -811,10 +811,33 @@ describe('LSP', function()
'å å ɧ 汉语 ↥ 🤦 🦄';
}, buf_lines(1))
end)
+ it('handles edits with the same start position, applying changes in the order in the array', function()
+ local edits = {
+ make_edit(0, 6, 0, 10, {""});
+ make_edit(0, 6, 0, 6, {"REPLACE"});
+ make_edit(1, 0, 1, 3, {""});
+ make_edit(1, 0, 1, 0, {"123"});
+ make_edit(2, 16, 2, 18, {""});
+ make_edit(2, 16, 2, 16, {"XYZ"});
+ make_edit(3, 7, 3, 11, {"this"});
+ make_edit(3, 7, 3, 11, {"will"});
+ make_edit(3, 7, 3, 11, {"not "});
+ make_edit(3, 7, 3, 11, {"show"});
+ make_edit(3, 7, 3, 11, {"(but this will)"});
+ }
+ exec_lua('vim.lsp.util.apply_text_edits(...)', edits, 1)
+ eq({
+ 'First REPLACE of text';
+ '123ond line of text';
+ 'Third line of teXYZ';
+ 'Fourth (but this will) of text';
+ 'å å ɧ 汉语 ↥ 🤦 🦄';
+ }, buf_lines(1))
+ end)
it('applies complex edits', function()
local edits = {
- make_edit(0, 0, 0, 0, {"", "12"});
make_edit(0, 0, 0, 0, {"3", "foo"});
+ make_edit(0, 0, 0, 0, {"", "12"});
make_edit(0, 1, 0, 1, {"bar", "123"});
make_edit(0, #"First ", 0, #"First line of text", {"guy"});
make_edit(1, 0, 1, #'Second', {"baz"});
@@ -1232,7 +1255,7 @@ describe('LSP', function()
]])
end)
end)
- describe('convert SymbolInformation[] to items', function()
+ it('convert SymbolInformation[] to items', function()
local expected = {
{
col = 1,
@@ -1296,11 +1319,11 @@ describe('LSP', function()
end)
describe('lsp.util._get_completion_item_kind_name', function()
- describe('returns the name specified by protocol', function()
+ it('returns the name specified by protocol', function()
eq("Text", exec_lua("return vim.lsp.util._get_completion_item_kind_name(1)"))
eq("TypeParameter", exec_lua("return vim.lsp.util._get_completion_item_kind_name(25)"))
end)
- describe('returns the name not specified by protocol', function()
+ it('returns the name not specified by protocol', function()
eq("Unknown", exec_lua("return vim.lsp.util._get_completion_item_kind_name(nil)"))
eq("Unknown", exec_lua("return vim.lsp.util._get_completion_item_kind_name(vim.NIL)"))
eq("Unknown", exec_lua("return vim.lsp.util._get_completion_item_kind_name(1000)"))
@@ -1308,11 +1331,11 @@ describe('LSP', function()
end)
describe('lsp.util._get_symbol_kind_name', function()
- describe('returns the name specified by protocol', function()
+ it('returns the name specified by protocol', function()
eq("File", exec_lua("return vim.lsp.util._get_symbol_kind_name(1)"))
eq("TypeParameter", exec_lua("return vim.lsp.util._get_symbol_kind_name(26)"))
end)
- describe('returns the name not specified by protocol', function()
+ it('returns the name not specified by protocol', function()
eq("Unknown", exec_lua("return vim.lsp.util._get_symbol_kind_name(nil)"))
eq("Unknown", exec_lua("return vim.lsp.util._get_symbol_kind_name(vim.NIL)"))
eq("Unknown", exec_lua("return vim.lsp.util._get_symbol_kind_name(1000)"))
@@ -1381,12 +1404,20 @@ describe('LSP', function()
end)
describe('lsp.util._make_floating_popup_size', function()
- exec_lua [[ contents =
- {"text tαxt txtα tex",
- "text tααt tααt text",
- "text tαxt tαxt"}
- ]]
- eq({19,3}, exec_lua[[ return {vim.lsp.util._make_floating_popup_size(contents)} ]])
- eq({15,5}, exec_lua[[ return {vim.lsp.util._make_floating_popup_size(contents,{width = 15, wrap_at = 14})} ]])
+ before_each(function()
+ exec_lua [[ contents =
+ {"text tαxt txtα tex",
+ "text tααt tααt text",
+ "text tαxt tαxt"}
+ ]]
+ end)
+
+ it('calculates size correctly', function()
+ eq({19,3}, exec_lua[[ return {vim.lsp.util._make_floating_popup_size(contents)} ]])
+ end)
+
+ it('calculates size correctly with wrapping', function()
+ eq({15,5}, exec_lua[[ return {vim.lsp.util._make_floating_popup_size(contents,{width = 15, wrap_at = 14})} ]])
+ end)
end)
end)