Skip to content

Add support for new Tailwind CSS v4.0.0-beta.9 features #1117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 21, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ export function resolveCssImports({
loose?: boolean
}) {
return postcss([
// Replace `@reference "…"` with `@import "…" reference`
{
postcssPlugin: 'replace-at-reference',
Once(root) {
root.walkAtRules('reference', (atRule) => {
atRule.name = 'import'
atRule.params += ' reference'
})
},
},

// Hoist imports to the top of the file
{
postcssPlugin: 'hoist-at-import',
Expand Down
19 changes: 12 additions & 7 deletions packages/tailwindcss-language-server/src/language/cssServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,22 @@ function createVirtualCssDocument(textDocument: TextDocument): TextDocument {
.replace(/@variants(\s+[^{]+){/g, replace())
.replace(/@responsive(\s*){/g, replace())
.replace(/@layer(\s+[^{]{2,}){/g, replace(-3))
.replace(/@reference\s*([^;]{2,})/g, '@import $1')
.replace(
/@media(\s+screen\s*\([^)]+\))/g,
(_match, screen) => `@media (${MEDIA_MARKER})${' '.repeat(screen.length - 4)}`,
)
.replace(/@import\s*("(?:[^"]+)"|'(?:[^']+)')\s*(.*?)(?=;|$)/g, (_match, url, other) => {
// Remove`source(…)`, `theme(…)`, and `prefix(…)` from `@import`s
// otherwise we'll show syntax-error diagnostics which we don't want
other = other.replace(/((source|theme|prefix)\([^)]+\)\s*)+?/g, '')

return `@import "${url.slice(1, -1)}" ${other}`
})
.replace(
/@import(\s*)("(?:[^"]+)"|'(?:[^']+)')\s*(.*?)(?=;|$)/g,
(_match, spaces, url, other) => {
// Remove`source(…)`, `theme(…)`, and `prefix(…)` from `@import`s
// otherwise we'll show syntax-error diagnostics which we don't want
other = other.replace(/((source|theme|prefix)\([^)]+\)\s*)+?/g, '')

// We have to add the spaces here so the character positions line up
return `@import${spaces}"${url.slice(1, -1)}" ${other}`
},
)
.replace(/(?<=\b(?:theme|config)\([^)]*)[.[\]]/g, '_')

return TextDocument.create(
Expand Down
Loading