Skip to content

Commit

Permalink
Fix odd v4 behavior with custom @-rules (#1212)
Browse files Browse the repository at this point in the history
Fixes #1211

---------

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
  • Loading branch information
tizu69 and thecrypticace authored Feb 17, 2025
1 parent 089c727 commit 2d473e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/tailwindcss-language-server/src/language/cssServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,16 @@ connection.onDocumentSymbol(({ textDocument }) =>
if (symbol.name === `@media (${MEDIA_MARKER})`) {
let doc = documents.get(symbol.location.uri)
let text = doc.getText(symbol.location.range)
let match = text.trim().match(/^(@[^\s]+)([^{]+){/)
let match = text.trim().match(/^(@[^\s]+)(?:([^{]+)[{]|([^;{]+);)/)
if (match) {
symbol.name = `${match[1]} ${match[2].trim()}`
symbol.name = `${match[1]} ${match[2]?.trim() ?? match[3]?.trim()}`
}
} else if (symbol.name === `.placeholder`) {
let doc = documents.get(symbol.location.uri)
let text = doc.getText(symbol.location.range)
let match = text.trim().match(/^(@[^\s]+)(?:([^{]+)[{]|([^;{]+);)/)
if (match) {
symbol.name = `${match[1]} ${match[2]?.trim() ?? match[3]?.trim()}`
}
}
return symbol
Expand Down Expand Up @@ -337,7 +344,7 @@ function replace(delta = 0) {
function replaceWithStyleRule(delta = 0) {
return (_match: string, p1: string) => {
let spaces = ' '.repeat(p1.length + delta)
return `.foo${spaces}{`
return `.placeholder${spaces}{`
}
}

Expand All @@ -354,9 +361,9 @@ function createVirtualCssDocument(textDocument: TextDocument): TextDocument {
.replace(/@variants(\s+[^{]+){/g, replace())
.replace(/@responsive(\s*){/g, replace())
.replace(/@utility(\s+[^{]+){/g, replaceWithStyleRule())
.replace(/@custom-variant(\s+[^;]+);/g, (match: string) => {
.replace(/@custom-variant(\s+[^;{]+);/g, (match: string) => {
let spaces = ' '.repeat(match.length - 11)
return `@media(p)${spaces}{}`
return `@media (${MEDIA_MARKER})${spaces}{}`
})
.replace(/@custom-variant(\s+[^{]+){/g, replaceWithStyleRule())
.replace(/@variant(\s+[^{]+){/g, replaceWithStyleRule())
Expand Down
2 changes: 2 additions & 0 deletions packages/vscode-tailwindcss/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- Show source diagnostics when imports contain a layer ([#1204](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1204))
- Only detect project roots in v4 when using certain CSS features ([#1205](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1205))
- Update Tailwind CSS v4 version to v4.0.6 ([#1207](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1207))
- Fix parsing of `@custom-variant` block syntax containg declarations and/or `@slot` ([#1212](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1212))
- Fix display of custom at-rules in symbol listing ([#1212](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1212))

## 0.14.4

Expand Down

0 comments on commit 2d473e0

Please sign in to comment.