-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use block icon for tailwind items (#544)
* style(tailwind): use block icon for Color items, cleanup * feat: hard code kind icon to block for tailwind * refactor: clean up highlight.lua --------- Co-authored-by: Liam Dyer <liamcdyer@gmail.com>
- Loading branch information
Showing
4 changed files
with
40 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
local tailwind = {} | ||
|
||
--- @param item blink.cmp.CompletionItem | ||
--- @return string|nil | ||
function tailwind.get_hex_color(item) | ||
local doc = item.documentation | ||
if item.kind ~= 'Color' or not doc then return end | ||
local content = type(doc) == 'string' and doc or doc.value | ||
if content and content:match('^#%x%x%x%x%x%x$') then return content end | ||
end | ||
|
||
--- @param item blink.cmp.CompletionItem | ||
--- @return string? | ||
function tailwind.get_kind_icon(item) | ||
if tailwind.get_hex_color(item) then return '██' end | ||
end | ||
|
||
--- @param ctx blink.cmp.DrawItemContext | ||
--- @return string|nil | ||
function tailwind.get_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 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 | ||
end | ||
end | ||
local hex_color = tailwind.get_hex_color(ctx.item) | ||
if not hex_color then return end | ||
|
||
local hl_name = 'HexColor' .. hex_color:sub(2) | ||
if #vim.api.nvim_get_hl(0, { name = hl_name }) == 0 then vim.api.nvim_set_hl(0, hl_name, { fg = hex_color }) end | ||
return hl_name | ||
end | ||
|
||
return tailwind |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters