Skip to content

Commit

Permalink
perf(blink-cmp): performance improvements and refactor to icon/highli…
Browse files Browse the repository at this point in the history
…ght providing
  • Loading branch information
mehalter committed Jan 8, 2025
1 parent da1600a commit 1853b72
Showing 1 changed file with 30 additions and 35 deletions.
65 changes: 30 additions & 35 deletions lua/astrocommunity/completion/blink-cmp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,9 @@ end
local icon_provider
---@type function?
local hl_provider
---@type table?
local kinds

local function get_hl(CTX)
if not hl_provider then
local highlight_colors_avail, highlight_colors = pcall(require, "nvim-highlight-colors")
if highlight_colors_avail then
hl_provider = function(ctx)
if not kinds then kinds = require("blink.cmp.types").CompletionItemKind end
if ctx.item.kind == kinds.Color then
local doc = vim.tbl_get(ctx, "item", "documentation")
if doc then
local color_item = highlight_colors_avail and highlight_colors.format(doc, { kind = kinds[kinds.Color] })
if color_item and color_item.abbr_hl_group then
if color_item.abbr then ctx.kind_icon = color_item.abbr end
ctx.kind_hl_group = color_item.abbr_hl_group
end
end
end
end
end
if not hl_provider then
hl_provider = function(ctx)
ctx.kind_hl_group = require("blink.cmp.completion.windows.render.tailwind").get_hl(ctx) or ctx.kind_hl_group
end
end
end
hl_provider(CTX)
end

local function get_icon(CTX)
-- Evaluate icon provider
if not icon_provider then
local base = function(ctx) ctx.kind_hl_group = "BlinkCmpKind" .. ctx.kind end
local _, mini_icons = pcall(require, "mini.icons")
Expand All @@ -53,7 +25,6 @@ local function get_icon(CTX)
elseif ctx.item.source_name == "Path" then
ctx.kind_icon, ctx.kind_hl_group = mini_icons.get(ctx.kind == "Folder" and "directory" or "file", ctx.label)
end
get_hl(ctx)
end
end
if not icon_provider then
Expand All @@ -65,16 +36,40 @@ local function get_icon(CTX)
local icon = lspkind.symbolic(ctx.kind, { mode = "symbol" })
if icon then ctx.kind_icon = icon end
end
get_hl(ctx)
end
end
end
if not icon_provider then icon_provider = function(ctx)
base(ctx)
get_hl(ctx)
end end
if not icon_provider then icon_provider = function(ctx) base(ctx) end end
end
-- Evaluate highlight provider
if not hl_provider then
local highlight_colors_avail, highlight_colors = pcall(require, "nvim-highlight-colors")
if highlight_colors_avail then
local kinds
hl_provider = function(ctx)
if not kinds then kinds = require("blink.cmp.types").CompletionItemKind end
if ctx.item.kind == kinds.Color then
local doc = vim.tbl_get(ctx, "item", "documentation")
if doc then
local color_item = highlight_colors_avail and highlight_colors.format(doc, { kind = kinds[kinds.Color] })
if color_item and color_item.abbr_hl_group then
if color_item.abbr then ctx.kind_icon = color_item.abbr end
ctx.kind_hl_group = color_item.abbr_hl_group
end
end
end
end
end
if not hl_provider then
hl_provider = function(ctx)
local tailwind_hl = require("blink.cmp.completion.windows.render.tailwind").get_hl(ctx)
if tailwind_hl then ctx.kind_hl_group = tailwind_hl end
end
end
end
-- Call resolved providers
icon_provider(CTX)
hl_provider(CTX)
end

return {
Expand Down

0 comments on commit 1853b72

Please sign in to comment.