diff --git a/lua/lazyvim/plugins/extras/util/mini-hipatterns.lua b/lua/lazyvim/plugins/extras/util/mini-hipatterns.lua index 2d87b734..429c2ccd 100644 --- a/lua/lazyvim/plugins/extras/util/mini-hipatterns.lua +++ b/lua/lazyvim/plugins/extras/util/mini-hipatterns.lua @@ -10,15 +10,25 @@ M.plugin = { local hi = require("mini.hipatterns") return { -- custom LazyVim option to enable the tailwind integration - tailwind = true, + tailwind = { + enabled = true, + ft = { "typescriptreact", "javascriptreact", "css", "javascript", "typescript", "html" }, + -- full: the whole css class will be highlighted + -- compact: only the color will be highlighted + style = "full", + }, highlighters = { hex_color = hi.gen_highlighter.hex_color({ priority = 2000 }), }, } end, config = function(_, opts) - if opts.tailwind then - local tailwind_ft = { "typescriptreact", "javascriptreact", "css", "javascript", "typescript", "html" } + -- backward compatibility + if opts.tailwind == true then + opts.tailwind = + { enabled = true, ft = { "typescriptreact", "javascriptreact", "css", "javascript", "typescript", "html" } } + end + if type(opts.tailwind) == "table" and opts.tailwind.enabled then -- reset hl groups when colorscheme changes vim.api.nvim_create_autocmd("ColorScheme", { callback = function() @@ -27,9 +37,18 @@ M.plugin = { }) opts.highlighters.tailwind = { pattern = function() - return vim.tbl_contains(tailwind_ft, vim.bo.filetype) and "%f[%w:-]()[%w:-]+%-[a-z%-]+%-%d+()%f[^%w:-]" + if not vim.tbl_contains(opts.tailwind.ft, vim.bo.filetype) then + return + end + if opts.tailwind.style == "full" then + return "%f[%w:-]()[%w:-]+%-[a-z%-]+%-%d+()%f[^%w:-]" + elseif opts.tailwind.style == "compact" then + return "%f[%w:-][%w:-]+%-()[a-z%-]+%-%d+()%f[^%w:-]" + end end, - group = function(_, match) + group = function(_, _, m) + ---@type string + local match = m.full_match ---@type string, number local color, shade = match:match("[%w-]+%-([a-z%-]+)%-(%d+)") shade = assert(tonumber(shade))