diff --git a/lua/tailwind-tools/classes.lua b/lua/tailwind-tools/classes.lua index 9b31753..94eae7f 100644 --- a/lua/tailwind-tools/classes.lua +++ b/lua/tailwind-tools/classes.lua @@ -1,6 +1,5 @@ local M = {} -local config = require("tailwind-tools.config") local patterns = require("tailwind-tools.patterns") local filetypes = require("tailwind-tools.filetypes") local tresitter = require("tailwind-tools.treesitter") @@ -14,18 +13,16 @@ local tresitter = require("tailwind-tools.treesitter") M.get_ranges = function(bufnr, filters) local results = {} local ft = vim.bo[bufnr].ft - local extension = config.options.extension - local query_list = vim.tbl_extend("force", filetypes.treesitter, extension.queries) - local pattern_list = vim.tbl_extend("force", filetypes.luapattern, extension.patterns) + local pattern_list = filetypes.get_patterns(ft) filters = filters or {} - for _, pattern in pairs(pattern_list[ft] or {}) do + for _, pattern in pairs(pattern_list) do local ranges = patterns.find_class_ranges(bufnr, pattern) vim.list_extend(results, ranges) end - if vim.tbl_contains(query_list, ft) then + if filetypes.has_queries(ft) then local ranges = tresitter.find_class_ranges(bufnr, ft, filters) vim.list_extend(results, ranges) end diff --git a/lua/tailwind-tools/filetypes.lua b/lua/tailwind-tools/filetypes.lua index 713040b..16f696e 100644 --- a/lua/tailwind-tools/filetypes.lua +++ b/lua/tailwind-tools/filetypes.lua @@ -1,4 +1,8 @@ -return { +local M = {} + +local config = require("tailwind-tools.config") + +local filetypes = { treesitter = { "html", "css", @@ -20,3 +24,29 @@ return { rust = { "class=[\"']([^\"']+)[\"']" }, }, } + +---@param ft string +M.get_patterns = function(ft) + return filetypes.luapattern[ft] or config.options.extension.patterns[ft] or {} +end + +---@param ft string +M.has_queries = function(ft) + return vim.tbl_contains(filetypes.treesitter, ft) + or vim.tbl_contains(config.options.extension.queries, ft) +end + +---@return string[] +M.get_all = function() + local result = {} + local extension = config.options.extension + + vim.list_extend(result, filetypes.treesitter) + vim.list_extend(result, extension.queries) + vim.list_extend(result, vim.tbl_keys(filetypes.luapattern)) + vim.list_extend(result, vim.tbl_keys(extension.patterns)) + + return result +end + +return M diff --git a/lua/tailwind-tools/lsp.lua b/lua/tailwind-tools/lsp.lua index 7def8ea..0d03675 100644 --- a/lua/tailwind-tools/lsp.lua +++ b/lua/tailwind-tools/lsp.lua @@ -5,6 +5,7 @@ local utils = require("tailwind-tools.utils") local state = require("tailwind-tools.state") local config = require("tailwind-tools.config") local classes = require("tailwind-tools.classes") +local filetypes = require("tailwind-tools.filetypes") local color_events = { "BufEnter", @@ -127,6 +128,7 @@ M.setup = function(opts, lspconfig) lspconfig.tailwindcss.setup({ capabilities = capabilities, on_attach = opts.on_attach, + filetypes = filetypes.get_all(), settings = { tailwindCSS = opts.settings, },