From 28c07e522a144ecdee428ec639e55264b56c1b79 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Tue, 22 Aug 2023 03:04:09 -0500 Subject: [PATCH] feat(nvim): support rgb rgba in cmp colors --- dots/.config/nvim/lua/plugins/configs/cmp.lua | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/dots/.config/nvim/lua/plugins/configs/cmp.lua b/dots/.config/nvim/lua/plugins/configs/cmp.lua index 19f88be4..d363b8f9 100644 --- a/dots/.config/nvim/lua/plugins/configs/cmp.lua +++ b/dots/.config/nvim/lua/plugins/configs/cmp.lua @@ -98,8 +98,27 @@ return { maxwidth = 50, })(entry, vim_item) if string.match(kind.kind, ".* Color$") then - kind.kind_hl_group = - handle_color_hl(entry.cache.entries.get_completion_item.label) + ---@type string + local hl = nil + local cmp_item = entry.cache.entries.get_completion_item + if cmp_item.documentation ~= nil then + hl = cmp_item.documentation + elseif cmp_item.label ~= nil then + hl = cmp_item.label + end + + local s, _, red, green, blue = string.find(hl, "rgba%((%d+), (%d+), (%d+), .*%)") + if s ~= nil then + hl = string.format("#%x%x%x", red, green, blue) + end + + s, _, red, green, blue = string.find(hl, "rgb%((%d+), (%d+), (%d+))") + if s ~= nil then + hl = string.format("#%x%x%x", red, green, blue) + end + + + kind.kind_hl_group = handle_color_hl(hl) end local strings = vim.split(kind.kind, "%s", { trimempty = true })