fix(lsp): tune completion word extraction for decorated labels (#29331)

Problem:

For snippets lsp.completion prefers the label if it is shorter than the
insertText or textEdit to support postfix completion cases but clangd
adds decoration characters to labels. E.g.: `•INT16_C(c)`

Solution:

Use parse_snippet on insertText/textEdit before checking if it is
shorter than the label.

Fixes https://github.com/neovim/neovim/issues/29301
This commit is contained in:
Mathias Fußenegger
2024-06-14 19:32:34 +02:00
committed by GitHub
parent ba70404c55
commit aa47af7e69
2 changed files with 18 additions and 3 deletions

View File

@@ -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