Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

Sorting completion items by external sources #273

Open
rx2130 opened this issue Nov 16, 2020 · 9 comments
Open

Sorting completion items by external sources #273

rx2130 opened this issue Nov 16, 2020 · 9 comments
Labels
enhancement New feature or request

Comments

@rx2130
Copy link

rx2130 commented Nov 16, 2020

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.

@haorenW1025
Copy link
Collaborator

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 haorenW1025 added the enhancement New feature or request label Nov 20, 2020
@quantum-booty
Copy link

@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.

@gegoune
Copy link

gegoune commented Jan 3, 2021

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?

@quantum-booty
Copy link

quantum-booty commented Jan 3, 2021

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

@lucax88x
Copy link

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

@lucax88x
Copy link

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

@lucax88x
Copy link

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

@pbogut
Copy link

pbogut commented Jan 28, 2021

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
Copy link

pbogut commented Jan 28, 2021

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants