Allow access to LSP completion item in sort comparator implementation
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?
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.
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'
}
}
Awesome, thank you very much!