Dynamically filter completion #1851
Unanswered
felipesere
asked this question in
Q&A
Replies: 1 comment 4 replies
-
It is kinda possible, but the only way I found is a convoluted hack. Plan of attack:
mapping = cmp.mapping.preset.insert { ...
['<M-q>'] = function()
cmp.mapping.abort()()
vim.g.filter_lsp_kind = 'Method'
cmp.mapping.complete()()
end, It does three things: Aborts current completion, sets global var to filter only methods(we'll use it), calls completition again(so we can use global var). (I have no idea if there's better way to abort/reopen autocomplete window than to use
{
name = 'nvim_lsp',
entry_filter = function(entry, ctx)
if vim.g.filter_lsp_kind ~= nil then
return require('cmp.types').lsp.CompletionItemKind[entry:get_kind()] == vim.g.filter_lsp_kind
end
return true
end,
},
Now when you open completition window, press . This will reset the filter and reopen completition which will apply the filter and display methods only. (Here's example of my current config to show how this filterworks ) |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Sometimes I get multple hits from my whatever I'm completing, some of the hits a methods, some snippets, some fields and sometimes variables.
I'd love to be able to hit a key stroke and type
Me
and narrow down the currently visible option to just those coming from Methods. The same mechanic could work for variables or fields.Is this something that exists but I have overlooked?
Beta Was this translation helpful? Give feedback.
All reactions