diff options
author | Kristijan Husak <husakkristijan@gmail.com> | 2024-11-13 16:18:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-13 15:18:29 +0000 |
commit | 33d10db5b7a7cd03b22e3ba401cb3bc74640f522 (patch) | |
tree | 09175e05c0cc7c2f0ac9fb3d854f90553520564a /runtime/lua/vim/lsp/completion.lua | |
parent | 36990f324de2cfb96a6d2450e9c3ddfc3fba8afa (diff) | |
download | rneovim-33d10db5b7a7cd03b22e3ba401cb3bc74640f522.tar.gz rneovim-33d10db5b7a7cd03b22e3ba401cb3bc74640f522.tar.bz2 rneovim-33d10db5b7a7cd03b22e3ba401cb3bc74640f522.zip |
fix(lsp): filter completion candidates based on completeopt (#30945)
Diffstat (limited to 'runtime/lua/vim/lsp/completion.lua')
-rw-r--r-- | runtime/lua/vim/lsp/completion.lua | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/runtime/lua/vim/lsp/completion.lua b/runtime/lua/vim/lsp/completion.lua index 10086fa49e..92bc110a97 100644 --- a/runtime/lua/vim/lsp/completion.lua +++ b/runtime/lua/vim/lsp/completion.lua @@ -220,6 +220,20 @@ local function get_doc(item) return '' end +---@param value string +---@param prefix string +---@return boolean +local function match_item_by_value(value, prefix) + if vim.o.completeopt:find('fuzzy') ~= nil then + return next(vim.fn.matchfuzzy({ value }, prefix)) ~= nil + end + + if vim.o.ignorecase and (not vim.o.smartcase or not prefix:find('%u')) then + return vim.startswith(value:lower(), prefix:lower()) + end + return vim.startswith(value, prefix) +end + --- Turns the result of a `textDocument/completion` request into vim-compatible --- |complete-items|. --- @@ -244,8 +258,16 @@ function M._lsp_to_complete_items(result, prefix, client_id) else ---@param item lsp.CompletionItem matches = function(item) - local text = item.filterText or item.label - return next(vim.fn.matchfuzzy({ text }, prefix)) ~= nil + if item.filterText then + return match_item_by_value(item.filterText, prefix) + end + + if item.textEdit then + -- server took care of filtering + return true + end + + return match_item_by_value(item.label, prefix) end end |