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 {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function matches_prefix(item)
|
if prefix ~= '' then
|
||||||
return vim.startswith(get_completion_word(item), prefix)
|
---@param item lsp.CompletionItem
|
||||||
end
|
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)
|
table.sort(items, function(a, b)
|
||||||
return (a.sortText or a.label) < (b.sortText or b.label)
|
return (a.sortText or a.label) < (b.sortText or b.label)
|
||||||
end)
|
end)
|
||||||
|
@ -228,7 +228,7 @@ describe('vim.lsp.completion: item conversion', function()
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
filterText = 'notthis_thread',
|
filterText = 'no_match',
|
||||||
insertText = 'notthis_thread',
|
insertText = 'notthis_thread',
|
||||||
insertTextFormat = 1,
|
insertTextFormat = 1,
|
||||||
kind = 9,
|
kind = 9,
|
||||||
|
Loading…
Reference in New Issue
Block a user