fix(lsp): don't use completion filterText if prefix is empty

Follow up to https://github.com/neovim/neovim/pull/32072

If there is no prefix (e.g. at the start of word boundary or a line), it
always used the `filterText` because the `match` function always
returned false.
This commit is contained in:
Mathias Fussenegger 2025-01-19 21:49:02 +01:00 committed by Mathias Fußenegger
parent d56ba71af1
commit 5f527f24f0
2 changed files with 11 additions and 3 deletions

View File

@ -231,6 +231,9 @@ end
---@param prefix string
---@return boolean
local function match_item_by_value(value, prefix)
if prefix == '' then
return true
end
if vim.o.completeopt:find('fuzzy') ~= nil then
return next(vim.fn.matchfuzzy({ value }, prefix)) ~= nil
end

View File

@ -239,13 +239,18 @@ describe('vim.lsp.completion: item conversion', function()
},
},
}
local expected = {
assert_completion_matches('<mo', items, {
{
abbr = 'module',
word = '<module',
},
}
assert_completion_matches('<mo', items, expected)
})
assert_completion_matches('', items, {
{
abbr = 'module',
word = 'module',
},
})
end)
it('fuzzy matches on label when filterText is missing', function()