Skip to content

Commit 22d7403

Browse files
committed
Show @theme in symbol list
1 parent 58e0be9 commit 22d7403

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

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

+24
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

+1
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

+40
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 @custom-variant
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 }) => ({

0 commit comments

Comments
 (0)