looping through kinds #1796
qwertzui11
started this conversation in
Ideas
Replies: 1 comment
-
was wondering the same thing, came out with the following snippet to re-trigger completion with an entry_filter set local cmp = require('cmp')
local kinds = require('cmp.types').lsp.CompletionItemKind
local filter_by_kind = function(_)
local entries
if not cmp.visible() then
entries = vim.iter(kinds)
:filter(function(item) return string.match(item, '[a-zA-Z]') end)
:map(function(it, _) return it end)
:map(string.lower)
:totable()
else
entries = vim.fn.uniq(vim.iter(cmp.get_entries())
:map(function(entry) return kinds[entry:get_kind()] end)
:map(string.lower)
:totable())
end
_G.SelectSourceKind = function(a, _, p)
return vim.iter(entries)
:filter(function(it) return string.sub(it, 1, p) == a end)
:totable()
end
local confirm = function(chosen)
local filter = function(entry, _) return string.lower(kinds[entry:get_kind()]) == chosen end
cmp.complete({ config = { sources = { { name = 'nvim_lsp', entry_filter = filter } } } })
end
vim.ui.input({
prompt = "Select Completion Kind: ",
completion = "customlist,v:lua.SelectSourceKind"
}, confirm)
end
-- cmp.setup({ mapping = cmp.mapping.preset.insert({sources={ ["<c-s>"] = filter_by_kind }}) }) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First of all thx for your great work! 😍
When I write code I sometimes know that I look for a specific
class
,method
orfunction
.Sometimes I'm only interested into snippets.
So now, instead of a completion menu with 30 entries or more I'd like to cycle the different available
kind
s and reduce the completion list.Eg triggering a second time
nvim-cmp
, I'd like to filter forclass
es. On another clickfunction
s and so on.Is something like that available? If not, makes my idea sense?
I guess I could implement it using
entry_filter
, what do you think?Thx for any feedback! 🎉
Beta Was this translation helpful? Give feedback.
All reactions