mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
fix(lsp): unify get_completion_word for textEdits/insertText
Problem: After https://github.com/neovim/neovim/pull/32377 selecting snippets provided by luals inserted the multi-line text before accepting the candidates. That's inconsistent with servers who provide `textEdit` instead of `insertText` and having lines shift up/down while cycling through the completion candidates is a bit irritating. Solution: Use the logic used for `textEdit` snippets also for `insertText`
This commit is contained in:

committed by
Mathias Fußenegger

parent
db2c3d1143
commit
8d7eb03040
@@ -132,7 +132,7 @@ end
|
|||||||
--- @return string
|
--- @return string
|
||||||
local function get_completion_word(item, prefix, match)
|
local function get_completion_word(item, prefix, match)
|
||||||
if item.insertTextFormat == protocol.InsertTextFormat.Snippet then
|
if item.insertTextFormat == protocol.InsertTextFormat.Snippet then
|
||||||
if item.textEdit then
|
if item.textEdit or (item.insertText and item.insertText ~= '') then
|
||||||
-- Use label instead of text if text has different starting characters.
|
-- Use label instead of text if text has different starting characters.
|
||||||
-- label is used as abbr (=displayed), but word is used for filtering
|
-- label is used as abbr (=displayed), but word is used for filtering
|
||||||
-- This is required for things like postfix completion.
|
-- This is required for things like postfix completion.
|
||||||
@@ -154,8 +154,6 @@ local function get_completion_word(item, prefix, match)
|
|||||||
else
|
else
|
||||||
return word
|
return word
|
||||||
end
|
end
|
||||||
elseif item.insertText and item.insertText ~= '' then
|
|
||||||
return parse_snippet(item.insertText)
|
|
||||||
else
|
else
|
||||||
return item.label
|
return item.label
|
||||||
end
|
end
|
||||||
|
@@ -562,12 +562,23 @@ describe('vim.lsp.completion: item conversion', function()
|
|||||||
range = range0,
|
range = range0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
-- luals for snippet
|
||||||
|
{
|
||||||
|
insertText = 'for ${1:index}, ${2:value} in ipairs(${3:t}) do\n\t$0\nend',
|
||||||
|
insertTextFormat = 2,
|
||||||
|
kind = 15,
|
||||||
|
label = 'for .. ipairs',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
local expected = {
|
local expected = {
|
||||||
{
|
{
|
||||||
abbr = 'copyOf(Collection<? extends E> coll) : List<E>',
|
abbr = 'copyOf(Collection<? extends E> coll) : List<E>',
|
||||||
word = 'copyOf',
|
word = 'copyOf',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
abbr = 'for .. ipairs',
|
||||||
|
word = 'for .. ipairs',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
abbr = 'insert',
|
abbr = 'insert',
|
||||||
word = 'insert',
|
word = 'insert',
|
||||||
|
Reference in New Issue
Block a user