From 1853b72a81c1cd37965df115a3f8c75520bc6618 Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Wed, 8 Jan 2025 09:17:33 -0500 Subject: [PATCH] perf(blink-cmp): performance improvements and refactor to icon/highlight providing --- .../completion/blink-cmp/init.lua | 65 +++++++++---------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/lua/astrocommunity/completion/blink-cmp/init.lua b/lua/astrocommunity/completion/blink-cmp/init.lua index 9b7b72e76..89f70c554 100644 --- a/lua/astrocommunity/completion/blink-cmp/init.lua +++ b/lua/astrocommunity/completion/blink-cmp/init.lua @@ -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") @@ -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 @@ -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 {