Skip to content

Commit 15c0b84

Browse files
Add support for new Tailwind CSS v4.0.0-beta.9 features (#1117)
- [x] Add support for `@reference` (alias for `@import "…" reference`) - [ ] Add support for `--value()` - [x] Completions (functional `@utility` context only) - [ ] Warning when used in non-functional utility context - [ ] Syntax highlighting - [ ] Add support for `--modifier()` - [x] Completions (functional `@utility` context only) - [ ] Warning when used in non-functional utility context - [ ] Syntax highlighting - [ ] Suggestions inside `--value()` and `--modifier()` - [ ] Theme keys - [x] Initial version: Same suggestions as @theme { … } - [ ] Final version: Compute theme key prefixes and suggest these - [ ] Ignore nested theme keys (`--` separated) - [x] Bare value data types - [x] Arbitrary value data types - [ ] Add support for `--spacing()` - [ ] Completions (this maybe doesn't make sense — it just takes a number, variable, or just whatever) - [x] Syntax highlighting - [ ] Add support for `--theme()` - [x] Completions - [x] Syntax highlighting - [ ] Add `theme()` function deprecation warning (v4 only) - [ ] When using modern variable syntax offer quick fix to `--theme(…)`
1 parent 2af2dba commit 15c0b84

File tree

15 files changed

+544
-39
lines changed

15 files changed

+544
-39
lines changed

packages/tailwindcss-language-server/src/css/resolve-css-imports.ts

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ export function resolveCssImports({
1212
loose?: boolean
1313
}) {
1414
return postcss([
15+
// Replace `@reference "…"` with `@import "…" reference`
16+
{
17+
postcssPlugin: 'replace-at-reference',
18+
Once(root) {
19+
root.walkAtRules('reference', (atRule) => {
20+
atRule.name = 'import'
21+
atRule.params += ' reference'
22+
})
23+
},
24+
},
25+
1526
// Hoist imports to the top of the file
1627
{
1728
postcssPlugin: 'hoist-at-import',

packages/tailwindcss-language-server/src/language/cssServer.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -348,17 +348,22 @@ function createVirtualCssDocument(textDocument: TextDocument): TextDocument {
348348
.replace(/@variants(\s+[^{]+){/g, replace())
349349
.replace(/@responsive(\s*){/g, replace())
350350
.replace(/@layer(\s+[^{]{2,}){/g, replace(-3))
351+
.replace(/@reference\s*([^;]{2,})/g, '@import $1')
351352
.replace(
352353
/@media(\s+screen\s*\([^)]+\))/g,
353354
(_match, screen) => `@media (${MEDIA_MARKER})${' '.repeat(screen.length - 4)}`,
354355
)
355-
.replace(/@import\s*("(?:[^"]+)"|'(?:[^']+)')\s*(.*?)(?=;|$)/g, (_match, url, other) => {
356-
// Remove`source(…)`, `theme(…)`, and `prefix(…)` from `@import`s
357-
// otherwise we'll show syntax-error diagnostics which we don't want
358-
other = other.replace(/((source|theme|prefix)\([^)]+\)\s*)+?/g, '')
359-
360-
return `@import "${url.slice(1, -1)}" ${other}`
361-
})
356+
.replace(
357+
/@import(\s*)("(?:[^"]+)"|'(?:[^']+)')\s*(.*?)(?=;|$)/g,
358+
(_match, spaces, url, other) => {
359+
// Remove`source(…)`, `theme(…)`, and `prefix(…)` from `@import`s
360+
// otherwise we'll show syntax-error diagnostics which we don't want
361+
other = other.replace(/((source|theme|prefix)\([^)]+\)\s*)+?/g, '')
362+
363+
// We have to add the spaces here so the character positions line up
364+
return `@import${spaces}"${url.slice(1, -1)}" ${other}`
365+
},
366+
)
362367
.replace(/(?<=\b(?:theme|config)\([^)]*)[.[\]]/g, '_')
363368

364369
return TextDocument.create(

0 commit comments

Comments
 (0)