feat(extras.ai): blink.cmp source kind overrides

allows multiple ai extras to be enabled at once, and drawn correctly
This commit is contained in:
Stefan Boca 2024-12-02 19:20:44 -08:00
parent 55b7d01e44
commit 069fe153ee
No known key found for this signature in database
5 changed files with 25 additions and 49 deletions

View file

@ -66,18 +66,7 @@ return {
completion = { completion = {
menu = { menu = {
draw = { draw = {
components = { override_kind_by_source_name = { codeium = "Codeium" },
kind = {
text = function(ctx)
return ctx.source_name == "codeium" and "Codeium" or ctx.kind
end,
highlight = function(ctx)
return ctx.source_name == "codeium" and "BlinkCmpKindCodeium"
or require("blink.cmp.completion.windows.render.tailwind").get_hl(ctx)
or ("BlinkCmpKind" .. ctx.kind)
end,
},
},
}, },
}, },
}, },

View file

@ -110,18 +110,7 @@ return {
completion = { completion = {
menu = { menu = {
draw = { draw = {
components = { override_kind_by_source_name = { copilot = "Copilot" },
kind = {
text = function(ctx)
return ctx.source_name == "copilot" and "Copilot" or ctx.kind
end,
highlight = function(ctx)
return ctx.source_name == "copilot" and "BlinkCmpKindCopilot"
or require("blink.cmp.completion.windows.render.tailwind").get_hl(ctx)
or ("BlinkCmpKind" .. ctx.kind)
end,
},
},
}, },
}, },
}, },

View file

@ -54,18 +54,7 @@ return {
completion = { completion = {
menu = { menu = {
draw = { draw = {
components = { override_kind_by_source_name = { supermaven = "Supermaven" },
kind = {
text = function(ctx)
return ctx.source_name == "supermaven" and "Supermaven" or ctx.kind
end,
highlight = function(ctx)
return ctx.source_name == "supermaven" and "BlinkCmpKindSupermaven"
or require("blink.cmp.completion.windows.render.tailwind").get_hl(ctx)
or ("BlinkCmpKind" .. ctx.kind)
end,
},
},
}, },
}, },
}, },

View file

@ -45,18 +45,7 @@ return {
completion = { completion = {
menu = { menu = {
draw = { draw = {
components = { override_kind_by_source_name = { cmp_tabnine = "TabNine" },
kind = {
text = function(ctx)
return ctx.source_name == "cmp_tabnine" and "TabNine" or ctx.kind
end,
highlight = function(ctx)
return ctx.source_name == "cmp_tabnine" and "BlinkCmpKindTabNine"
or require("blink.cmp.completion.windows.render.tailwind").get_hl(ctx)
or ("BlinkCmpKind" .. ctx.kind)
end,
},
},
}, },
}, },
}, },

View file

@ -45,7 +45,10 @@ return {
completion = { completion = {
menu = { menu = {
winblend = vim.o.pumblend, winblend = vim.o.pumblend,
draw = { treesitter = true }, draw = {
override_kind_by_source_name = {},
treesitter = true,
},
}, },
documentation = { documentation = {
auto_show = true, auto_show = true,
@ -93,6 +96,23 @@ return {
table.insert(enabled, source) table.insert(enabled, source)
end end
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,
}
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,
}, },