aboutsummaryrefslogtreecommitdiff
path: root/lua/colorizer/matcher_utils.lua
diff options
context:
space:
mode:
authorAkianonymus <anonymus.aki@gmail.com>2022-09-04 18:32:02 +0530
committerAkianonymus <anonymus.aki@gmail.com>2022-09-06 15:06:14 +0530
commit5f7680e7e7ccad68bd9962bcbb40dfde1c3669a1 (patch)
tree0345c3393e3f64d77042224dc6b3e4672b1e901e /lua/colorizer/matcher_utils.lua
parentcolorizer: Make sure it works without giving any config (diff)
Fix https://github.com/NvChad/nvim-colorizer.lua/issues/12 | Add support for tailwind colors
Three methods normal: Use the hardcoded colors lsp: Use lsp to fetch colors both: Use the hardcoded colors and use lsp too if available although this is hardcoding, but working with what we got, has all the colors tailwind provides, atleast the prebuilt ones for new defined colors, have to enable the lsp method Generated using https://github.com/tailwindlabs/tailwindcss/raw/master/src/public/colors.js and https://github.com/tailwindlabs/tailwindcss/raw/master/src/corePlugins.js use a different namespace than default for tailwind lsp method only try to use lsp method if attached Misc changes export the user_default_settings to doc clear name space after the lines are processed for a smooth transition cleanup some code
Diffstat (limited to 'lua/colorizer/matcher_utils.lua')
-rw-r--r--lua/colorizer/matcher_utils.lua12
1 files changed, 9 insertions, 3 deletions
diff --git a/lua/colorizer/matcher_utils.lua b/lua/colorizer/matcher_utils.lua
index 84ddece..11e56f6 100644
--- a/lua/colorizer/matcher_utils.lua
+++ b/lua/colorizer/matcher_utils.lua
@@ -34,12 +34,14 @@ local function compile_matcher(matchers, matchers_trie)
local prefix = trie:longest_prefix(line, i)
if prefix then
local fn = "_" .. prefix
- return parser[fn](line, i, matchers[fn])
+ if parser[fn] then
+ return parser[fn](line, i, matchers[fn])
+ end
end
-- Colour names
if matchers.color_name_parser then
- return color_name_parser(line, i)
+ return color_name_parser(line, i, matchers.color_name_parser)
end
end
return parse_fn
@@ -53,6 +55,7 @@ local MATCHER_CACHE = {}
---@return function|boolean: function which will just parse the line for enabled parsers
local function make_matcher(options)
local enable_names = options.css or options.names
+ local enable_tailwind = options.tailwind
local enable_RGB = options.css or options.RGB
local enable_RRGGBB = options.css or options.RRGGBB
local enable_RRGGBBAA = options.css or options.RRGGBBAA
@@ -68,6 +71,9 @@ local function make_matcher(options)
+ (enable_AARRGGBB and 1 or 4)
+ (enable_rgb and 1 or 5)
+ (enable_hsl and 1 or 6)
+ + (enable_tailwind == "normal" and 1 or 7)
+ + (enable_tailwind == "lsp" and 1 or 8)
+ + (enable_tailwind == "both" and 1 or 9)
if matcher_key == 0 then
return false
@@ -83,7 +89,7 @@ local function make_matcher(options)
matchers.max_prefix_length = 0
if enable_names then
- matchers.color_name_parser = true
+ matchers.color_name_parser = { tailwind = options.tailwind }
end
local valid_lengths = { [3] = enable_RGB, [6] = enable_RRGGBB, [8] = enable_RRGGBBAA }