blink.cmp icon indicating copy to clipboard operation
blink.cmp copied to clipboard

Allow access to LSP completion item in sort comparator implementation

Open tom-anders opened this issue 7 months ago • 1 comments

Feature Description

clangd has an extension where it adds it's own score to the LSP CompletionItem (based on things like number of usages, see https://clangd.llvm.org/extensions) - In nvim cmp the comparator had access to this field, so we could support the clangd extension like this: https://github.com/hrsh7th/nvim-cmp/issues/277#issuecomment-936315287 (via entry.completion_item)

With blink, I don't see any way to access the CompletionItem - Any chance this could be added?

tom-anders avatar May 16 '25 11:05 tom-anders

The argument passed to the sort comparator is the LSP completionItem with some additional blink.cmp specific fields. Unfortunately, we also have a .score field that we add so we end up overriding the clangd one. We should move our fields to .blink but this would be a breaking change so it would need to wait for v2.

saghen avatar May 28 '25 20:05 saghen

Added a hack specific for clangd to move the field to .lsp_score so you can use it in your sorting.

fuzzy = {
  sorts = {
    -- custom sort using clangd `.lsp_score` property
    function(a, b)
      if not a.lsp_score or not b.lsp_score then return end

      if a.lsp_score > b.lsp_score then return true
      elseif a.lsp_score < b.lsp_score then return false end
    end,

    -- your other sorts, below are defaults
    'score',
    'sort_text'
  }
}

saghen avatar Jun 24 '25 14:06 saghen

Awesome, thank you very much!

tom-anders avatar Jun 25 '25 08:06 tom-anders