Skip to content

Commit

Permalink
fix(lsp): pre-filter matches on label if filterText is missing
Browse files Browse the repository at this point in the history
Although the built-in pum completion mechanism will filter anyway on the
next input it is odd if the initial popup shows entries which don't
match the current prefix.

Using fuzzy match on the label/prefix is compatible with
`completeopt+=fuzzy` and also doesn't seem to break postfix snippet
cases

Closes neovim#29287
  • Loading branch information
mfussenegger committed Jun 26, 2024
1 parent 0a789a8 commit 93c97c6
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions runtime/lua/vim/lsp/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,20 @@ function M._lsp_to_complete_items(result, prefix, client_id)
return {}
end

local matches = prefix == '' and function()
return true
end or function(item)
if item.filterText then
return next(vim.fn.matchfuzzy({ item.filterText }, prefix))
---@type fun(item: lsp.CompletionItem):boolean
local matches
if prefix == '' then
matches = function(_)
return true
end
else
---@param item lsp.CompletionItem
matches = function(item)
local text = item.filterText or item.label
return next(vim.fn.matchfuzzy({ text }, prefix)) ~= nil
end
return true
end

local candidates = {}
for _, item in ipairs(items) do
if matches(item) then
Expand Down

0 comments on commit 93c97c6

Please sign in to comment.