Skip to content

Commit 5c50de2

Browse files
committed
feat(blink-cmp): add formatting of kind icon
1 parent 7eb383b commit 5c50de2

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

lua/astrocommunity/completion/blink-cmp/init.lua

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,41 @@ local function has_words_before()
33
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match "%s" == nil
44
end
55

6+
local function get_icon_provider()
7+
local _, mini_icons = pcall(require, "mini.icons")
8+
if _G.MiniIcons then
9+
return function(kind) return mini_icons.get("lsp", kind or "") end
10+
end
11+
local lspkind_avail, lspkind = pcall(require, "lspkind")
12+
if lspkind_avail then
13+
return function(kind) return lspkind.symbolic(kind, { mode = "symbol" }) end
14+
end
15+
end
16+
---@type function|false|nil
17+
local icon_provider = false
18+
19+
local function get_icon(ctx)
20+
ctx.kind_hl_group = "BlinkCmpKind" .. ctx.kind
21+
if ctx.item.source_name == "LSP" then
22+
-- TODO: uncomment after nvim-highlight-colors PR merged: https://github.com/brenoprata10/nvim-highlight-colors/pull/135
23+
-- local highlight_colors_avail, highlight_colors = pcall(require, "nvim-highlight-colors")
24+
-- local color_item = highlight_colors_avail and highlight_colors.format(ctx.item.documentation, { kind = ctx.kind })
25+
if icon_provider == false then icon_provider = get_icon_provider() end
26+
if icon_provider then
27+
local icon = icon_provider(ctx.kind)
28+
if icon then ctx.kind_icon = icon end
29+
end
30+
-- if color_item and color_item.abbr and color_item.abbr_hl_group then
31+
-- ctx.kind_icon, ctx.kind_hl_group = color_item.abbr, color_item.abbr_hl_group
32+
-- end
33+
end
34+
return ctx
35+
end
36+
637
return {
738
"Saghen/blink.cmp",
8-
event = "InsertEnter",
9-
-- TODO: replace build with 'version = "*"' after the next release
10-
build = "cargo build --release",
39+
event = { "InsertEnter", "CmdlineEnter" },
40+
version = "0.*",
1141
dependencies = { "rafamadriz/friendly-snippets" },
1242
opts_extend = { "sources.default", "sources.cmdline" },
1343
opts = {
@@ -52,6 +82,17 @@ return {
5282
menu = {
5383
border = "rounded",
5484
winhighlight = "Normal:NormalFloat,FloatBorder:FloatBorder,CursorLine:PmenuSel,Search:None",
85+
draw = {
86+
components = {
87+
kind_icon = {
88+
text = function(ctx)
89+
get_icon(ctx)
90+
return ctx.kind_icon .. ctx.icon_gap
91+
end,
92+
highlight = function(ctx) return get_icon(ctx).kind_hl_group end,
93+
},
94+
},
95+
},
5596
},
5697
accept = {
5798
auto_brackets = { enabled = true },

0 commit comments

Comments
 (0)