fix(lsp): fallback to filterText for non-matching PlainText items #39695

Problem:
PlainText completion items used `textEdit.newText` or `insertText` as
the completion word even when they did not match the typed prefix. This
could break popup completion behavior like 'completeopt+=longest'.

Solution:
Fall back to `filterText` when `newText` or `insertText` does not match
the typed prefix.
This commit is contained in:
glepnir
2026-05-17 23:58:49 +08:00
committed by GitHub
parent a562fb33ca
commit 767fbd88ff
2 changed files with 61 additions and 26 deletions

View File

@@ -211,8 +211,15 @@ local function get_completion_word(item, prefix, match)
elseif item.textEdit then
local word = item.textEdit.newText
word = string.gsub(word, '\r\n?', '\n')
return word:match('([^\n]*)') or word
word = word:match('([^\n]*)') or word
if item.filterText and not match(word, prefix) then
return item.filterText
end
return word
elseif item.insertText and item.insertText ~= '' then
if item.filterText and not match(item.insertText, prefix) then
return item.filterText
end
return item.insertText
end
return item.label