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 = { sources = {
compat = { "codeium" }, compat = { "codeium" },
}, },
completion = { providers = { codeium = { kind = "Codeium" } },
menu = {
draw = {
override_kind_by_source_name = { codeium = "Codeium" },
},
},
},
}, },
} or nil, } or nil,
} }

View file

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

View file

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

View file

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

View file

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