Commit 8caef47
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
37 | 10 | | |
38 | | - | |
39 | | - | |
| 11 | + | |
40 | 12 | | |
41 | 13 | | |
42 | 14 | | |
| |||
136 | 108 | | |
137 | 109 | | |
138 | 110 | | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
152 | 114 | | |
153 | 115 | | |
154 | 116 | | |
| |||
0 commit comments