diff options
author | Akianonymus <anonymus.aki@gmail.com> | 2022-09-04 18:32:02 +0530 |
---|---|---|
committer | Akianonymus <anonymus.aki@gmail.com> | 2022-09-06 15:06:14 +0530 |
commit | 5f7680e7e7ccad68bd9962bcbb40dfde1c3669a1 (patch) | |
tree | 0345c3393e3f64d77042224dc6b3e4672b1e901e /lua/colorizer/color_utils.lua | |
parent | colorizer: 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/color_utils.lua')
-rw-r--r-- | lua/colorizer/color_utils.lua | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/lua/colorizer/color_utils.lua b/lua/colorizer/color_utils.lua index 433cea7..b90c108 100644 --- a/lua/colorizer/color_utils.lua +++ b/lua/colorizer/color_utils.lua @@ -60,13 +60,15 @@ local COLOR_MAP local COLOR_TRIE local COLOR_NAME_MINLEN, COLOR_NAME_MAXLEN local COLOR_NAME_SETTINGS = { lowercase = true, strip_digits = false } +local TAILWIND_ENABLED = false --- Grab all the colour values from `vim.api.nvim_get_color_map` and create a lookup table. -- COLOR_MAP is used to store the colour values ---@param line string: Line to parse ---@param i number: Index of line from where to start parsing -local function color_name_parser(line, i) +---@param opts table: Currently contains whether tailwind is enabled or not +local function color_name_parser(line, i, opts) --- Setup the COLOR_MAP and COLOR_TRIE - if not COLOR_TRIE then + if not COLOR_TRIE or opts.tailwind ~= TAILWIND_ENABLED then COLOR_MAP = {} COLOR_TRIE = Trie() for k, v in pairs(api.nvim_get_color_map()) do @@ -83,8 +85,23 @@ local function color_name_parser(line, i) end end end + if opts and opts.tailwind then + if opts.tailwind == "normal" or opts.tailwind == "both" then + local tailwind = require "colorizer.tailwind_colors" + -- setup tailwind colors + for k, v in pairs(tailwind.colors) do + for _, pre in ipairs(tailwind.prefixes) do + local name = pre .. "-" .. k + COLOR_NAME_MINLEN = COLOR_NAME_MINLEN and min(#name, COLOR_NAME_MINLEN) or #name + COLOR_NAME_MAXLEN = COLOR_NAME_MAXLEN and max(#name, COLOR_NAME_MAXLEN) or #name + COLOR_MAP[name] = v + COLOR_TRIE:insert(name) + end + end + end + end + TAILWIND_ENABLED = opts.tailwind end - if #line < i + COLOR_NAME_MINLEN - 1 then return end |