Skip to content

Commit

Permalink
fix: set states values on setup() (#19)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
UserIsntAvailable and luckasRanarison authored Apr 3, 2024
1 parent 87b507e commit 2a23bc6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
17 changes: 9 additions & 8 deletions lua/tailwind-tools/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion lua/tailwind-tools/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions lua/tailwind-tools/state.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
local config = require("tailwind-tools.config")

return {
conceal = {
enabled = false,
active_buffers = {},
},
color = {
request_timer = nil,
enabled = config.options.document_color.enabled,
enabled = false,
active_buffers = {},
},
}

0 comments on commit 2a23bc6

Please sign in to comment.