aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/lua/vim/lsp/completion.lua4
-rw-r--r--test/functional/plugin/lsp/completion_spec.lua17
2 files changed, 18 insertions, 3 deletions
diff --git a/runtime/lua/vim/lsp/completion.lua b/runtime/lua/vim/lsp/completion.lua
index 4b7deabf41..2e6d82b367 100644
--- a/runtime/lua/vim/lsp/completion.lua
+++ b/runtime/lua/vim/lsp/completion.lua
@@ -145,8 +145,8 @@ local function get_completion_word(item)
-- label: insert
--
-- Typing `i` would remove the candidate because newText starts with `t`.
- local text = item.insertText or item.textEdit.newText
- return #text < #item.label and text or item.label
+ local text = parse_snippet(item.insertText or item.textEdit.newText)
+ return #text < #item.label and vim.fn.matchstr(text, '\\k*') or item.label
elseif item.insertText and item.insertText ~= '' then
return parse_snippet(item.insertText)
else
diff --git a/test/functional/plugin/lsp/completion_spec.lua b/test/functional/plugin/lsp/completion_spec.lua
index 0e81e4fddb..1b56d1740a 100644
--- a/test/functional/plugin/lsp/completion_spec.lua
+++ b/test/functional/plugin/lsp/completion_spec.lua
@@ -81,10 +81,21 @@ describe('vim.lsp.completion: item conversion', function()
-- plain text
{
label = 'foocar',
- sortText = 'k',
+ sortText = 'g',
insertText = 'foodar(${1:var1})',
insertTextFormat = 1,
},
+ {
+ label = '•INT16_C(c)',
+ insertText = 'INT16_C(${1:c})',
+ insertTextFormat = 2,
+ filterText = 'INT16_C',
+ sortText = 'h',
+ textEdit = {
+ newText = 'INT16_C(${1:c})',
+ range = range0,
+ },
+ },
}
local expected = {
{
@@ -115,6 +126,10 @@ describe('vim.lsp.completion: item conversion', function()
abbr = 'foocar',
word = 'foodar(${1:var1})', -- marked as PlainText, text is used as is
},
+ {
+ abbr = '•INT16_C(c)',
+ word = 'INT16_C',
+ },
}
local result = complete('|', completion_list)
result = vim.tbl_map(function(x)