From 2a23bc6ea5fe5f6fc2125d381d0c9525e9a3738b Mon Sep 17 00:00:00 2001 From: Angel Pineda <57047985+UserIsntAvailable@users.noreply.github.com> Date: Wed, 3 Apr 2024 09:56:16 -0400 Subject: [PATCH] fix: set `state`s values on `setup()` (#19) * fix: set `state`s values on `setup()`. Previously, the `state` table values wasn't being updated with the values provided from the `config` table, which forced to manually run `Tailwind{Conceal,Color}{Disable,Enabled}` to actually active/deactivate the option. * fix: `conceal.enabled` boolean logic. * update: remove condition * fix: lint --------- Co-authored-by: Luckas --- lua/tailwind-tools/init.lua | 17 +++++++++-------- lua/tailwind-tools/lsp.lua | 2 +- lua/tailwind-tools/state.lua | 4 +--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lua/tailwind-tools/init.lua b/lua/tailwind-tools/init.lua index a0f29e8..0bafeac 100644 --- a/lua/tailwind-tools/init.lua +++ b/lua/tailwind-tools/init.lua @@ -11,6 +11,9 @@ local motions = require("tailwind-tools.motions") M.setup = function(options) config.options = vim.tbl_deep_extend("keep", options, config.options) + state.conceal.enabled = config.options.conceal.enabled + state.color.enabled = config.options.document_color.enabled + if vim.version().minor < 10 and config.options.document_color.kind == "inline" then log.warn( "Neovim nightly is required for inline color hints, using fallback option." @@ -43,14 +46,12 @@ M.setup = function(options) callback = lsp.on_attach, }) - if config.options.conceal.enabled then - vim.api.nvim_create_autocmd("BufEnter", { - group = vim.g.tailwind_tools.conceal_au, - callback = function() - if not state.conceal.enabled then conceal.enable() end - end, - }) - end + vim.api.nvim_create_autocmd("BufEnter", { + group = vim.g.tailwind_tools.conceal_au, + callback = function() + if state.conceal.enabled then conceal.enable() end + end, + }) end return M diff --git a/lua/tailwind-tools/lsp.lua b/lua/tailwind-tools/lsp.lua index 19d4936..9e9acb4 100644 --- a/lua/tailwind-tools/lsp.lua +++ b/lua/tailwind-tools/lsp.lua @@ -92,7 +92,7 @@ M.on_attach = function(args) end, }) - M.color_request(bufnr) + if state.color.enabled then M.color_request(bufnr) end end ---@param bufnr number diff --git a/lua/tailwind-tools/state.lua b/lua/tailwind-tools/state.lua index 83f565e..35fa6c9 100644 --- a/lua/tailwind-tools/state.lua +++ b/lua/tailwind-tools/state.lua @@ -1,5 +1,3 @@ -local config = require("tailwind-tools.config") - return { conceal = { enabled = false, @@ -7,7 +5,7 @@ return { }, color = { request_timer = nil, - enabled = config.options.document_color.enabled, + enabled = false, active_buffers = {}, }, }