Skip to content

Commit

Permalink
update: adjust filetypes
Browse files Browse the repository at this point in the history
Make LSP supported filetypes relative to filetypes supported by the plugin.
  • Loading branch information
luckasRanarison committed Aug 30, 2024
1 parent bf7c891 commit 73125df
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
9 changes: 3 additions & 6 deletions lua/tailwind-tools/classes.lua
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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
Expand Down
32 changes: 31 additions & 1 deletion lua/tailwind-tools/filetypes.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
return {
local M = {}

local config = require("tailwind-tools.config")

local filetypes = {
treesitter = {
"html",
"css",
Expand All @@ -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
2 changes: 2 additions & 0 deletions lua/tailwind-tools/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit 73125df

Please sign in to comment.