aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/completion.lua
diff options
context:
space:
mode:
authorMathias Fußenegger <mfussenegger@users.noreply.github.com>2024-06-27 12:20:00 +0200
committerGitHub <noreply@github.com>2024-06-27 12:20:00 +0200
commit724d1110b1e4699a34f489e9cdb2d25098746499 (patch)
tree84dc431d609c9e3f7342498b73e88658f0477c61 /runtime/lua/vim/lsp/completion.lua
parentfc9b70826ec88ca2e6c0624c522b872e87aa7ac1 (diff)
downloadrneovim-724d1110b1e4699a34f489e9cdb2d25098746499.tar.gz
rneovim-724d1110b1e4699a34f489e9cdb2d25098746499.tar.bz2
rneovim-724d1110b1e4699a34f489e9cdb2d25098746499.zip
fix(lsp): pre-filter matches on label if filterText is missing (#29491)
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 https://github.com/neovim/neovim/issues/29287
Diffstat (limited to 'runtime/lua/vim/lsp/completion.lua')
-rw-r--r--runtime/lua/vim/lsp/completion.lua18
1 files changed, 12 insertions, 6 deletions
diff --git a/runtime/lua/vim/lsp/completion.lua b/runtime/lua/vim/lsp/completion.lua
index 2e6d82b367..b935c48d3c 100644
--- a/runtime/lua/vim/lsp/completion.lua
+++ b/runtime/lua/vim/lsp/completion.lua
@@ -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