Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source priority #1098

Open
nexxai opened this issue Jan 27, 2025 · 4 comments
Open

Source priority #1098

nexxai opened this issue Jan 27, 2025 · 4 comments
Labels
feature New feature or request sources Specific source provider or the system as a whole

Comments

@nexxai
Copy link

nexxai commented Jan 27, 2025

I want to be able to choose which order suggestions appear based on their source. Specifically, I want any snippets that match to appear higher than anything else, the idea being that if I have a snippet that matches, it's because I manually created one for that specific use case.

What I don't understand is how I'd actually go about setting the order.

In my config, I already have:

snippets = { preset = "luasnip" },
sources = {
      default = { "snippets", "lsp", "path", "buffer" },
},

with "snippets" being at the front of the line, but this seems to make no difference to where the suggestions actually end up.

Is there something I'm doing wrong here?

@FerretDetective
Copy link
Contributor

FerretDetective commented Jan 28, 2025

I believe you can accomplish this with sources.providers.score_offset. See https://cmp.saghen.dev/configuration/reference.html#providers, and #1096.

@Saghen
Copy link
Owner

Saghen commented Jan 28, 2025

You may also achieve this with a custom sort function fuzzy.sorts. I'll leave this open since we should probably support a priority system in blink.cmp directly

local source_priority = {
  snippets = 4,
  lsp = 3,
  path = 2,
  buffer = 1
}
  
fuzzy.sorts = {
  function(a, b)
    return source_priority[a.source_id] > source_priority[b.source_id]
  end,
  -- defaults
  'score',
  'sort_text'
}

@Saghen Saghen changed the title How to define source sort order Source priority Jan 28, 2025
@Saghen Saghen added feature New feature or request sources Specific source provider or the system as a whole labels Jan 28, 2025
@nexxai
Copy link
Author

nexxai commented Jan 28, 2025

@Saghen Just to clarify, I had to replace the < comparison in the return statement with a > but otherwise, this seems to work awesome. Leaving this here for anyone else who encounters the same issue until source priority sorting is officially supported.

Thank you so much for all the work you put in to this package! ❤️

@Saghen
Copy link
Owner

Saghen commented Jan 28, 2025

Fixed, thank you!

@Saghen Saghen mentioned this issue Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request sources Specific source provider or the system as a whole
Projects
None yet
Development

No branches or pull requests

3 participants