aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/completion.lua
diff options
context:
space:
mode:
authorMathias Fussenegger <f.mathias@zignar.net>2024-05-28 21:37:46 +0200
committerMathias Fußenegger <mfussenegger@users.noreply.github.com>2024-05-30 09:24:24 +0200
commit0df2c6b5d09fab392dd1a14e4b2e6a3b03203aaa (patch)
tree62b307751318f7368efa95f0ff02b61cdc9d8146 /runtime/lua/vim/lsp/completion.lua
parent025c87441502cf570bad7b71f40bc6fe88989297 (diff)
downloadrneovim-0df2c6b5d09fab392dd1a14e4b2e6a3b03203aaa.tar.gz
rneovim-0df2c6b5d09fab392dd1a14e4b2e6a3b03203aaa.tar.bz2
rneovim-0df2c6b5d09fab392dd1a14e4b2e6a3b03203aaa.zip
feat(lsp): use fuzzy match on filterText instead of prefix match
The `complete()` mechanism matches completion candidates against the typed text, so strict pre-filtering isn't necessary. This is a first step towards supporting postfix snippets (like `items@insert` in luals)
Diffstat (limited to 'runtime/lua/vim/lsp/completion.lua')
-rw-r--r--runtime/lua/vim/lsp/completion.lua14
1 files changed, 10 insertions, 4 deletions
diff --git a/runtime/lua/vim/lsp/completion.lua b/runtime/lua/vim/lsp/completion.lua
index 25b3d53c8c..f9b0563b86 100644
--- a/runtime/lua/vim/lsp/completion.lua
+++ b/runtime/lua/vim/lsp/completion.lua
@@ -201,11 +201,17 @@ function M._lsp_to_complete_items(result, prefix, client_id)
return {}
end
- local function matches_prefix(item)
- return vim.startswith(get_completion_word(item), prefix)
- end
+ if prefix ~= '' then
+ ---@param item lsp.CompletionItem
+ local function match_prefix(item)
+ if item.filterText then
+ return next(vim.fn.matchfuzzy({ item.filterText }, prefix))
+ end
+ return true
+ end
- items = vim.tbl_filter(matches_prefix, items) --[[@as lsp.CompletionItem[]|]]
+ items = vim.tbl_filter(match_prefix, items) --[[@as lsp.CompletionItem[]|]]
+ end
table.sort(items, function(a, b)
return (a.sortText or a.label) < (b.sortText or b.label)
end)