zbirenbaum / copilot-cmp

Lua plugin to turn github copilot into a cmp source
MIT License
1.08k stars 39 forks source link

How to sort copilot lower than lsp? #42

Closed lkhphuc closed 1 year ago

lkhphuc commented 1 year ago

I tried to follow your code snippet on the readme to rank copilot lower than exact match, but it does not work.

sorting = {
        priority_weight = 2,
        comparators = {
          require("copilot_cmp.comparators").prioritize,
          require("copilot_cmp.comparators").score,
          compare.offset,
          compare.exact,
          compare.score,
          compare.recently_used,
          compare.kind,
          compare.sort_text,
          compare.length,
          compare.order,
        },
      }

Screenshot 2023-01-17 at 18 43 54

But in the text you said copilot should be put lower, so I tried this:

      sorting = {
        priority_weight = 2,
        comparators = {
          compare.offset,
          compare.exact,
          compare.score,
          compare.recently_used,
          compare.kind,
          compare.sort_text,
          compare.length,
          compare.order,
          require("copilot_cmp.comparators").prioritize,
          require("copilot_cmp.comparators").score,
        },
      },

Screenshot 2023-01-17 at 18 46 59

I tried remove the sorting config and use cmp's default but copilot is stilled ranked highest. Screenshot 2023-01-17 at 18 48 24

Do you have any idea? Thank you.

zbirenbaum commented 1 year ago

Copilot technically is a LSP, and I don't think it would be too useful if it always popped up on the bottom, but an easier way to do that than messing with comparators would be to just set the source priority like so:

sources = {
  { name = "nvim_lsp", group_index = 1 },
  { name = "copilot", group_index = 2 },
  { name = "path", group_index = 2 },
  { name = 'neorg', group_index = 2 },
}

Also though, I just tried putting the length comparator above the copilot-cmp ones, and it properly made copilot completions show up at the end.

It may be that 2 isn't a high enough weight to make the exact comparator always prioritized. I would try increasing it to 3 or 4 and see f that fixes it. Here is the formula that it is used in from the nvim-cmp docs: final_score = orig_score + ((#sources - (source_index - 1)) * sorting.priority_weight)

lkhphuc commented 1 year ago

Thanks for the tips. I tried playing around a bit but sometime it did rank lower, but sometimes it still ranks very high. Feel free to close this issue.