Skip to content

Commit 26b004f

Browse files
Show @theme in symbol list (#1227)
Right now `@theme` is treated as an opaque at-rule by the CSS language server and it doesn't show up in symbol navigation. This PR addresses this by performing the same type of replacement we do for `@utility`, `@variant`, and `@custom-variant`. --------- Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
1 parent f37a144 commit 26b004f

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

packages/tailwindcss-language-server/src/language/rewriting.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,30 @@ test('@utility', () => {
6565
expect(rewriteCss(input.join('\n'))).toBe(output.join('\n'))
6666
})
6767

68+
test('@theme', () => {
69+
let input = [
70+
//
71+
'@theme {',
72+
' color: red;',
73+
'}',
74+
'@theme inline reference static default {',
75+
' color: red;',
76+
'}',
77+
]
78+
79+
let output = [
80+
//
81+
'.placeholder {', // wrong
82+
' color: red;',
83+
'}',
84+
'.placeholder {', // wrong
85+
' color: red;',
86+
'}',
87+
]
88+
89+
expect(rewriteCss(input.join('\n'))).toBe(output.join('\n'))
90+
})
91+
6892
test('@custom-variant', () => {
6993
let input = [
7094
//

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function rewriteCss(css: string) {
3737
css = css.replace(/@variants(\s+[^{]+){/g, replaceWithAtRule())
3838
css = css.replace(/@responsive(\s*){/g, replaceWithAtRule())
3939
css = css.replace(/@utility(\s+[^{]+){/g, replaceWithStyleRule())
40+
css = css.replace(/@theme(\s+[^{]*){/g, replaceWithStyleRule())
4041

4142
css = css.replace(/@custom-variant(\s+[^;{]+);/g, (match: string) => {
4243
let spaces = ' '.repeat(match.length - 11)

packages/tailwindcss-language-server/tests/css/css-server.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,46 @@ defineTest({
202202
},
203203
})
204204

205+
defineTest({
206+
name: '@theme',
207+
prepare: async ({ root }) => ({
208+
client: await createClient({
209+
server: 'css',
210+
root,
211+
}),
212+
}),
213+
handle: async ({ client }) => {
214+
let doc = await client.open({
215+
lang: 'tailwindcss',
216+
name: 'file-1.css',
217+
text: css`
218+
@import 'tailwindcss';
219+
@theme {
220+
--color-primary: #333;
221+
}
222+
`,
223+
})
224+
225+
// No errors
226+
expect(await doc.diagnostics()).toEqual([])
227+
228+
// Symbols show up for @theme
229+
expect(await doc.symbols()).toMatchObject([
230+
{
231+
kind: SymbolKind.Class,
232+
name: '@theme ',
233+
location: {
234+
uri: '{workspace:default}/file-1.css',
235+
range: {
236+
start: { line: 1, character: 0 },
237+
end: { line: 3, character: 1 },
238+
},
239+
},
240+
},
241+
])
242+
},
243+
})
244+
205245
defineTest({
206246
name: '@layer statement',
207247
prepare: async ({ root }) => ({

packages/vscode-tailwindcss/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- LSP: Declare capability for handling workspace folder change notifications ([#1223](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1223))
66
- Don't throw when resolving paths containing a `#` character ([#1225](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1225))
7+
- Show `@theme` in symbol list in CSS language mode ([#1227](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1227))
78

89
## 0.14.6
910

0 commit comments

Comments
 (0)