Skip to content

Commit

Permalink
fix: tailwind colors (#306)
Browse files Browse the repository at this point in the history
Co-authored-by: Liam Dyer <liamcdyer@gmail.com>
  • Loading branch information
lopi-py and Saghen authored Nov 10, 2024
1 parent 371ad28 commit 8e3af0e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,14 @@ MiniDeps.add({
kind_icon = {
ellipsis = false,
text = function(ctx) return ctx.kind_icon end,
highlight = function(ctx) return 'BlinkCmpKind' .. ctx.kind end,
highlight = function(ctx) return utils.get_tailwind_hl(ctx) or 'BlinkCmpKind' .. ctx.kind end,
},

kind = {
ellipsis = false,
width = { fill = true },
text = function(ctx) return ctx.kind end,
highlight = function(ctx) return 'BlinkCmpKind' .. ctx.kind end,
highlight = function(ctx) return utils.get_tailwind_hl(ctx) or 'BlinkCmpKind' .. ctx.kind end,
},

label = {
Expand Down
6 changes: 4 additions & 2 deletions lua/blink/cmp/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@
--- @field kind_icons? table<string, string>
--- @field blocked_filetypes? string[]

local utils = require('blink.cmp.utils')

--- @type blink.cmp.Config
local config = {
-- the keymap may be a preset ('default' | 'super-tab' | 'enter') OR a table of keys => command[]
Expand Down Expand Up @@ -408,14 +410,14 @@ local config = {
kind_icon = {
ellipsis = false,
text = function(ctx) return ctx.kind_icon end,
highlight = function(ctx) return 'BlinkCmpKind' .. ctx.kind end,
highlight = function(ctx) return utils.get_tailwind_hl(ctx) or 'BlinkCmpKind' .. ctx.kind end,
},

kind = {
ellipsis = false,
width = { fill = true },
text = function(ctx) return ctx.kind end,
highlight = function(ctx) return 'BlinkCmpKind' .. ctx.kind end,
highlight = function(ctx) return utils.get_tailwind_hl(ctx) or 'BlinkCmpKind' .. ctx.kind end,
},

label = {
Expand Down
4 changes: 2 additions & 2 deletions lua/blink/cmp/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ end

--- @param ctx blink.cmp.DrawItemContext
--- @return string|nil
function utils.try_get_tailwind_hl(ctx)
function utils.get_tailwind_hl(ctx)
local doc = ctx.item.documentation
if ctx.kind == 'Color' and doc then
local content = type(doc) == 'string' and doc or doc.value
if ctx.kind == 'Color' and content and content:match('^#%x%x%x%x%x%x$') then
if content and content:match('^#%x%x%x%x%x%x$') then
local hl_name = 'HexColor' .. content:sub(2)
if #vim.api.nvim_get_hl(0, { name = hl_name }) == 0 then vim.api.nvim_set_hl(0, hl_name, { fg = content }) end
return hl_name
Expand Down

0 comments on commit 8e3af0e

Please sign in to comment.