completion-nvim
completion-nvim copied to clipboard
Sorting completion items by external sources
Is your feature request related to a problem? Please describe.
My completion_chain_complete_list contains lsp and buffer. I'm frustrated when the top of the popupmenu is Buffer (which is mostly noise when lsp is available).

Describe the solution you'd like Support sorting completion items by external sources. User could put lsp result ahead of buffer.
That's a sensilbe enhancement. Unfortunately I might not have time to work on this project recently so it might takes a while for me to implement this:( Right now a possible solution might be putting lsp sources and buffer sources in different group and use the following mapping to switch between them.
imap <c-j> <Plug>(completion_next_source) "use <c-j> to switch to previous completion
imap <c-k> <Plug>(completion_prev_source) "use <c-k> to switch to next completion
@haorenW1025 To build on top of this idea, it would be nice to customize the ordering of the completion types. Using the types like in here:
So we could for example put Variable before Function.
How would that fit with completion_sorting = "length"? As in, would there be another option to group types together and then sort within each type as per completion_sorting?
Yeah I think length sorting or alphabetical sorting within each type is nice.
@quantum-booty that would be cool, can you create a separate issue for that?
@haorenW1025 please, consider investing on this issue, I think that really makes sense to prioritize ordering of sources.
@haorenW1025 would you explain in the readme or there, how I can separate in groups?
I currently have this chain config
vim.g.completion_chain_complete_list = {
default = {
default = {
{
complete_items = {
"lsp", "snippet", "ts", "path", "buffers"
}
}
},
string = {
{
complete_items = {"path"}
}
}
}
}
I have it like this:
vim.g.completion_chain_complete_list = {
{complete_items = {'lsp', 'snippet'}},
{complete_items = {'buffers'}},
{mode = '<c-p>'},
{mode = '<c-n>'},
}
So so I have lsp and snippet in one group and buffers in other one.
In your case it would be something like this:
vim.g.completion_chain_complete_list = {
default = {
default = {
{ complete_items = { "lsp", "snippet" } },
{ complete_items = { "ts", "path", "buffers" } }
},
string = {
{
complete_items = {"path"}
}
}
}
}
You have it described here
I also just found out that you can sort by types, and use it to push things like buffers to the bottom of the list
vim.g.completion_items_priority = {
Method = 10,
Field = 9,
Property = 9,
Variables = 6,
Function = 7,
Interfaces = 6,
Constant = 6,
Class = 6,
Struct = 6,
Keyword = 5,
Treesitter = 4,
Buffers = 0,
TabNine = 1,
File = 2,
}
