refactor: allow overriding a provider's symbol kinds

This commit is contained in:
Folke Lemaitre 2024-12-03 11:28:13 +01:00
parent df4771ff79
commit 04b51bfbd2
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
5 changed files with 22 additions and 44 deletions

View file

@ -63,13 +63,7 @@ return {
sources = {
compat = { "codeium" },
},
completion = {
menu = {
draw = {
override_kind_by_source_name = { codeium = "Codeium" },
},
},
},
providers = { codeium = { kind = "Codeium" } },
},
} or nil,
}

View file

@ -104,13 +104,10 @@ return {
enabled_providers = { "copilot" },
},
providers = {
copilot = { name = "copilot", module = "blink-cmp-copilot" },
},
},
completion = {
menu = {
draw = {
override_kind_by_source_name = { copilot = "Copilot" },
copilot = {
name = "copilot",
module = "blink-cmp-copilot",
kind = "Copilot",
},
},
},

View file

@ -51,13 +51,7 @@ return {
sources = {
compat = { "supermaven" },
},
completion = {
menu = {
draw = {
override_kind_by_source_name = { supermaven = "Supermaven" },
},
},
},
providers = { supermaven = { kind = "Supermaven" } },
},
} or nil,

View file

@ -42,13 +42,7 @@ return {
sources = {
compat = { "cmp_tabnine" },
},
completion = {
menu = {
draw = {
override_kind_by_source_name = { cmp_tabnine = "TabNine" },
},
},
},
providers = { cmp_tabnine = { kind = "TabNine" } },
},
},

View file

@ -45,7 +45,6 @@ return {
completion = {
menu = {
draw = {
override_kind_by_source_name = {},
treesitter = true,
},
},
@ -96,22 +95,22 @@ return {
end
end
local override_kind_by_source_name = opts.completion.menu.draw.override_kind_by_source_name or {}
local kind = {
text = function(ctx)
local kind_override = override_kind_by_source_name[ctx.source_name]
return kind_override and kind_override or ctx.kind
end,
highlight = function(ctx)
local kind_override = override_kind_by_source_name[ctx.source_name]
return kind_override and "BlinkCmpKind" .. kind_override
or require("blink.cmp.completion.windows.render.tailwind").get_hl(ctx)
or ("BlinkCmpKind" .. ctx.kind)
end,
}
-- check if we need to override symbol kinds
for _, provider in pairs(opts.sources.providers or {}) do
---@cast provider blink.cmp.SourceProviderConfig|{kind?:string}
if provider.kind then
require("blink.cmp.types").CompletionItemKind[provider.kind] = provider.kind
---@param ctx blink.cmp.Context
---@param items blink.cmp.CompletionItem[]
provider.transform_items = function(ctx, items)
for _, item in ipairs(items) do
item.kind = provider.kind or item.kind
end
return items
end
end
end
opts.completion.menu.draw.components =
vim.tbl_deep_extend("force", { kind = kind }, opts.completion.menu.draw.components or {})
require("blink.cmp").setup(opts)
end,
},