mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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)
This commit is contained in:
parent
025c874415
commit
0df2c6b5d0
@ -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)
|
||||
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)
|
||||
|
@ -228,7 +228,7 @@ describe('vim.lsp.completion: item conversion', function()
|
||||
},
|
||||
},
|
||||
{
|
||||
filterText = 'notthis_thread',
|
||||
filterText = 'no_match',
|
||||
insertText = 'notthis_thread',
|
||||
insertTextFormat = 1,
|
||||
kind = 9,
|
||||
|
Loading…
Reference in New Issue
Block a user