Skip to content

Commit 8caef47

Browse files
authored
fix(tailwindcss): revert broken config detection #4376
Problem: `find_tailwind_global_css` attempted to address #4204, where `experimental.configFile` was set using the return value of `vim.fs.find()`. The language server rejected this with `Invalid experimental.configFile configuration, not initializing` because `configFile` expects either a string or a key-value record (object), not an array/list. This was a syntax issue, not a detection issue. Using the correct syntax for `configFile` in Lua should be sufficient to address the original issue. Right now, `find_tailwind_global_css` always runs for users who haven't explicitly set `configFile` — overriding the LSP's native detection and **forcing anyone who wants to opt out to manually set all entry-points by hand.** Solution: - Remove `find_tailwind_global_css` entirely and restores `configFile` to its default `nil` so the `tailwindcss` LSP handles project detection natively. - Simplify `before_init` based on [this suggestion from the initial PR](#4222 (comment)). The following syntax worked for me while testing to explicitly set the `configFile` based on the [official docs](https://github.com/tailwindlabs/tailwindcss-intellisense#tailwindcssexperimentalconfigfile) for single entry-point: > [!NOTE] > Single entry-point is resolved relative to the workspace root (`root_dir` — verify with `:checkhealth vim.lsp`) ```lua vim.lsp.config('tailwindcss', { settings = { tailwindCSS = { experimental = { -- v3: config file configFile = 'tailwind.config.js', -- v4: CSS entry-point -- configFile = 'src/styles/app.css', }, }, }, }) ``` For projects with multiple entry-points, or different projects, the following syntax can be used for multiple entry-points: > [!NOTE] > Keys are relative to `root_dir` as above, but from my testing on macOS, absolute paths worked better ```lua vim.lsp.config('tailwindcss', { settings = { tailwindCSS = { experimental = { configFile = { ['tailwind.config.js'] = '/Users/username/path/to/project-a/**', ['src/main.css'] = '/Users/username/path/to/project-b/**', }, }, }, }, }) ``` #### Project or Local Configuration For project-specific settings without modifying your global Neovim config: 1. Enable in your Neovim config: ```lua vim.o.exrc = true ``` 2. Create `.nvim.lua` in the project root: ```lua vim.lsp.config('tailwindcss', { settings = { tailwindCSS = { experimental = { configFile = 'tailwind.config.ts', }, }, }, }) ``` 3. Open `.nvim.lua` and run `:trust` to allow the file, then restart Neovim. 4. Verify with `:checkhealth vim.lsp`.
1 parent 9ccd58a commit 8caef47

1 file changed

Lines changed: 7 additions & 45 deletions

File tree

lsp/tailwindcss.lua

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,11 @@
44
--- Tailwind CSS Language Server can be installed via npm:
55
---
66
--- npm install -g @tailwindcss/language-server
7-
local util = require 'lspconfig.util'
8-
9-
local function find_tailwind_global_css()
10-
local target = [[%@import ['"]tailwindcss['"]%;]]
11-
-- Find project root using `.git`
12-
local buf = vim.api.nvim_get_current_buf()
13-
local root = vim.fs.root(buf, function(name)
14-
return name == '.git'
15-
end)
16-
17-
if not root then
18-
return nil -- no project root found
19-
end
20-
21-
-- Find stylesheet files in the project root (recursively)
22-
local files = vim.fs.find(function(name)
23-
return name:match('%.css$') or name:match('%.scss$') or name:match('%.pcss$')
24-
end, {
25-
path = root,
26-
type = 'file',
27-
limit = math.huge, -- search full tree
28-
})
29-
30-
for _, path in ipairs(files) do
31-
local content = vim.fn.readblob(path)
32-
33-
if content:find(target, 1, true) then
34-
return path -- return first match
35-
end
36-
end
7+
---
8+
--- To manually set the config file or CSS entry-point, see:
9+
--- https://github.com/tailwindlabs/tailwindcss-intellisense#tailwindcssexperimentalconfigfile
3710

38-
return nil
39-
end
11+
local util = require('lspconfig.util')
4012

4113
---@type vim.lsp.Config
4214
return {
@@ -136,19 +108,9 @@ return {
136108
},
137109
},
138110
before_init = function(_, config)
139-
if not config.settings then
140-
config.settings = {}
141-
end
142-
if not config.settings.editor then
143-
config.settings.editor = {}
144-
end
145-
if not config.settings.editor.tabSize then
146-
config.settings.editor.tabSize = vim.lsp.util.get_effective_tabstop()
147-
end
148-
config.settings.tailwindCSS = config.settings.tailwindCSS or {}
149-
config.settings.tailwindCSS.experimental = config.settings.tailwindCSS.experimental or {}
150-
config.settings.tailwindCSS.experimental.configFile = config.settings.tailwindCSS.experimental.configFile
151-
or find_tailwind_global_css()
111+
config.settings = vim.tbl_deep_extend('keep', config.settings, {
112+
editor = { tabSize = vim.lsp.util.get_effective_tabstop() },
113+
})
152114
end,
153115
workspace_required = true,
154116
root_dir = function(bufnr, on_dir)

0 commit comments

Comments
 (0)