Skip to content

Commit 23bfb2a

Browse files
authored
fix(tailwindcss_ls): add experimental.configFile to support Tailwind v4 #4222
1 parent 9d28ece commit 23bfb2a

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

lsp/tailwindcss.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,39 @@
66
--- npm install -g @tailwindcss/language-server
77
local util = require 'lspconfig.util'
88

9+
local function find_tailwind_global_css()
10+
local target = "@import 'tailwindcss';"
11+
12+
-- Find project root using `.git`
13+
local buf = vim.api.nvim_get_current_buf()
14+
local root = vim.fs.root(buf, function(name)
15+
return name == '.git'
16+
end)
17+
18+
if not root then
19+
return nil -- no project root found
20+
end
21+
22+
-- Find stylesheet files in the project root (recursively)
23+
local files = vim.fs.find(function(name)
24+
return name:match('%.css$') or name:match('%.scss$') or name:match('%.pcss$')
25+
end, {
26+
path = root,
27+
type = 'file',
28+
limit = math.huge, -- search full tree
29+
})
30+
31+
for _, path in ipairs(files) do
32+
local content = vim.fn.readblob(path)
33+
34+
if content:find(target, 1, true) then
35+
return path -- return first match
36+
end
37+
end
38+
39+
return nil
40+
end
41+
942
---@type vim.lsp.Config
1043
return {
1144
cmd = { 'tailwindcss-language-server', '--stdio' },
@@ -113,6 +146,10 @@ return {
113146
if not config.settings.editor.tabSize then
114147
config.settings.editor.tabSize = vim.lsp.util.get_effective_tabstop()
115148
end
149+
config.settings.tailwindCSS = config.settings.tailwindCSS or {}
150+
config.settings.tailwindCSS.experimental = config.settings.tailwindCSS.experimental or {}
151+
config.settings.tailwindCSS.experimental.configFile = config.settings.tailwindCSS.experimental.configFile
152+
or find_tailwind_global_css()
116153
end,
117154
workspace_required = true,
118155
root_dir = function(bufnr, on_dir)

0 commit comments

Comments
 (0)