Ship a css-custom-data.json so editors stop reporting @theme as an unknown at-rule #20430
Replies: 1 comment
|
One more argument for putting this in the package rather than leaving it to each project, from hitting it again this week in a setup where the workaround was already fully in place. The custom data workaround is scope-fragile, and fails silently.
Nothing indicates that a settings file exists one level down and is being ignored. And because VS Code doesn't warn about an unresolvable So the workaround isn't just boilerplate — it's boilerplate that works in a single-repo checkout and quietly stops working the moment the folder layout changes, with no diagnostic to tell you which of the three things went wrong. Anything shipped with the framework is immune to that, since the path is resolved through (Separately, worth knowing for anyone writing this up: changing |
Uh oh!
There was an error while loading. Please reload this page.
What I'd like to see
Ship a
css-custom-data.jsonin thetailwindcsspackage, so any project can do this:…and have VS Code's built-in CSS language service understand
@theme,@utility,@variant,@custom-variant,@source,@reference,@apply,@pluginand@config— automatically staying in sync with whatever version of Tailwind is installed.Following CONTRIBUTING.md, which asks for an idea here before a PR for anything that isn't a bug fix.
The problem
vscode-css-languageservice— which backs VS Code's built-in CSS support, and also Zed and most Neovim LSP setups — doesn't know Tailwind's at-rules. A valid v4 stylesheet reports seven problems:That's measured, not hypothetical — it's
tailwindcss@4.3.3compiling that exact file without complaint.The two workarounds people land on each cost something real:
"css.lint.unknownAtRules": "ignore"turns off the whole lint. You also stop being told about@medai (min-width: 40rem)."files.associations": { "*.css": "tailwindcss" }moves your CSS files to a different language ID.css.customDatano longer applies to them, and other tooling keyed oncssquietly stops working. This is what the docs currently steer people toward, and it's why threads like #18556 keep appearing.Why custom data is the right shape of fix
CSS Custom Data is VS Code's supported extension point for exactly this. It's declarative JSON, has zero runtime cost, and — unlike
ignore— it's additive: the language service learns the at-rules and keeps validating everything else.I checked what that actually does. Same stylesheet, same language service, with a custom data file loaded:
…while
colr: redand@medaiare both still reported. You also get hover documentation and completion on the directives, whichignoreobviously can't give you.Why in the
tailwindcsspackage specificallyThe file itself is easy to write by hand — plenty of people already have. The part that doesn't work is keeping it correct. Which at-rules exist is a property of the installed version (
@themedoesn't exist in v3;@tailwinddoesn't in v4), so a hand-maintained copy is wrong the moment someone upgrades, and it fails in the most confusing possible way: a warning on a directive that's real.Shipping it in the package makes the path a version-pinned dependency. Upgrade Tailwind, the file updates with it. Nothing to regenerate, nothing to drift.
It also makes it discoverable. Right now this is folklore spread across blog posts.
On the earlier PR
tailwindlabs/tailwindcss-intellisense#237 proposed this in the extension in 2021 and was declined, for two stated reasons. Both were about the extension, and I think the situation reads differently now:
@applyclass list errors" — I couldn't reproduce this on v4 syntax. Once@applyis declared,@apply rounded-lg bg-brand px-4 py-2 font-semibold;produces no diagnostics at all. I think the v3-era@applyforms that caused parse errors are gone..cssfiles stop being marked up.Putting the file in the framework package rather than the extension also covers editors that aren't VS Code, and projects that don't have the extension installed.
Happy to send a PR
It's an additive JSON file plus a
filesentry — no runtime impact, and I'd include tests asserting the emitted directives match what the version actually supports. Only if you'd want it, per CONTRIBUTING.In the meantime I put the same idea in a standalone tool (tailwind-custom-data) that generates the file from the installed version, with a
--checkmode for CI. Itssrc/directives.tsis basically the catalogue this proposal would move upstream, if that's a useful starting point.All reactions