diff --git a/lua/lazyvim/plugins/extras/util/mini-hipatterns.lua b/lua/lazyvim/plugins/extras/util/mini-hipatterns.lua index 64abb63f..2d87b734 100644 --- a/lua/lazyvim/plugins/extras/util/mini-hipatterns.lua +++ b/lua/lazyvim/plugins/extras/util/mini-hipatterns.lua @@ -19,22 +19,27 @@ M.plugin = { config = function(_, opts) if opts.tailwind then local tailwind_ft = { "typescriptreact", "javascriptreact", "css", "javascript", "typescript", "html" } + -- reset hl groups when colorscheme changes + vim.api.nvim_create_autocmd("ColorScheme", { + callback = function() + M.hl = {} + end, + }) opts.highlighters.tailwind = { pattern = function() - if not vim.tbl_contains(tailwind_ft, vim.bo.filetype) then - return - end - return "%f[%w:-]()[%w:-]+%-[a-z%-]+%-%d+()%f[^%w:-]" + return vim.tbl_contains(tailwind_ft, vim.bo.filetype) and "%f[%w:-]()[%w:-]+%-[a-z%-]+%-%d+()%f[^%w:-]" end, group = function(_, match) - ---@type string,string + ---@type string, number local color, shade = match:match("[%w-]+%-([a-z%-]+)%-(%d+)") - local bg = vim.tbl_get(M.colors, color, tonumber(shade)) + shade = assert(tonumber(shade)) + local bg = vim.tbl_get(M.colors, color, shade) if bg then local hl = "MiniHipatternsTailwind" .. color .. shade if not M.hl[hl] then M.hl[hl] = true - local fg = vim.tbl_get(M.colors, color, tonumber(shade) >= 500 and 100 or 900) + local bg_shade = shade == 500 and 950 or shade < 500 and 900 or 100 + local fg = vim.tbl_get(M.colors, color, bg_shade) vim.api.nvim_set_hl(0, hl, { bg = "#" .. bg, fg = "#" .. fg }) end return hl