completion-nvim icon indicating copy to clipboard operation
completion-nvim copied to clipboard

Sorting completion items by external sources

Open rx2130 opened this issue 5 years ago • 9 comments
trafficstars

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). Screen Shot 2020-11-16 at 2 40 39 PM

Describe the solution you'd like Support sorting completion items by external sources. User could put lsp result ahead of buffer.

rx2130 avatar Nov 16 '20 22:11 rx2130

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 avatar Nov 20 '20 09:11 haorenW1025

@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: image So we could for example put Variable before Function.

quantum-booty avatar Jan 03 '21 18:01 quantum-booty

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?

gegoune avatar Jan 03 '21 21:01 gegoune

Yeah I think length sorting or alphabetical sorting within each type is nice.

quantum-booty avatar Jan 03 '21 21:01 quantum-booty

@quantum-booty that would be cool, can you create a separate issue for that?

lucax88x avatar Jan 22 '21 16:01 lucax88x

@haorenW1025 please, consider investing on this issue, I think that really makes sense to prioritize ordering of sources.

lucax88x avatar Jan 22 '21 16:01 lucax88x

@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"}
      }
    }
  }
}

lucax88x avatar Jan 22 '21 16:01 lucax88x

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

pbogut avatar Jan 28 '21 16:01 pbogut

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,
}

screenshot_from_2021-01-28_18-18-57

pbogut avatar Jan 28 '21 17:01 pbogut