Skip to content

Commit 2d473e0

Browse files
Fix odd v4 behavior with custom @-rules (#1212)
Fixes #1211 --------- Co-authored-by: Jordan Pittman <[email protected]>
1 parent 089c727 commit 2d473e0

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

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

+12-5
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,16 @@ connection.onDocumentSymbol(({ textDocument }) =>
215215
if (symbol.name === `@media (${MEDIA_MARKER})`) {
216216
let doc = documents.get(symbol.location.uri)
217217
let text = doc.getText(symbol.location.range)
218-
let match = text.trim().match(/^(@[^\s]+)([^{]+){/)
218+
let match = text.trim().match(/^(@[^\s]+)(?:([^{]+)[{]|([^;{]+);)/)
219219
if (match) {
220-
symbol.name = `${match[1]} ${match[2].trim()}`
220+
symbol.name = `${match[1]} ${match[2]?.trim() ?? match[3]?.trim()}`
221+
}
222+
} else if (symbol.name === `.placeholder`) {
223+
let doc = documents.get(symbol.location.uri)
224+
let text = doc.getText(symbol.location.range)
225+
let match = text.trim().match(/^(@[^\s]+)(?:([^{]+)[{]|([^;{]+);)/)
226+
if (match) {
227+
symbol.name = `${match[1]} ${match[2]?.trim() ?? match[3]?.trim()}`
221228
}
222229
}
223230
return symbol
@@ -337,7 +344,7 @@ function replace(delta = 0) {
337344
function replaceWithStyleRule(delta = 0) {
338345
return (_match: string, p1: string) => {
339346
let spaces = ' '.repeat(p1.length + delta)
340-
return `.foo${spaces}{`
347+
return `.placeholder${spaces}{`
341348
}
342349
}
343350

@@ -354,9 +361,9 @@ function createVirtualCssDocument(textDocument: TextDocument): TextDocument {
354361
.replace(/@variants(\s+[^{]+){/g, replace())
355362
.replace(/@responsive(\s*){/g, replace())
356363
.replace(/@utility(\s+[^{]+){/g, replaceWithStyleRule())
357-
.replace(/@custom-variant(\s+[^;]+);/g, (match: string) => {
364+
.replace(/@custom-variant(\s+[^;{]+);/g, (match: string) => {
358365
let spaces = ' '.repeat(match.length - 11)
359-
return `@media(p)${spaces}{}`
366+
return `@media (${MEDIA_MARKER})${spaces}{}`
360367
})
361368
.replace(/@custom-variant(\s+[^{]+){/g, replaceWithStyleRule())
362369
.replace(/@variant(\s+[^{]+){/g, replaceWithStyleRule())

packages/vscode-tailwindcss/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
- Show source diagnostics when imports contain a layer ([#1204](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1204))
88
- Only detect project roots in v4 when using certain CSS features ([#1205](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1205))
99
- Update Tailwind CSS v4 version to v4.0.6 ([#1207](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1207))
10+
- Fix parsing of `@custom-variant` block syntax containg declarations and/or `@slot` ([#1212](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1212))
11+
- Fix display of custom at-rules in symbol listing ([#1212](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1212))
1012

1113
## 0.14.4
1214

0 commit comments

Comments
 (0)