Skip to content

Commit 32d1e17

Browse files
committed
Add tests for the CSS language server
1 parent e3005f1 commit 32d1e17

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export class CssServer {
4040
const stylesheets = getLanguageModelCache<Stylesheet>(10, 60, (document) =>
4141
cssLanguageService.parseStylesheet(document),
4242
)
43+
documents.onDidOpen(({ document }) => {
44+
connection.sendNotification('@/tailwindCSS/documentReady', {
45+
uri: document.uri,
46+
})
47+
})
4348
documents.onDidClose(({ document }) => {
4449
stylesheets.onDocumentRemoved(document)
4550
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { expect } from 'vitest'
2+
import { css, defineTest } from '../../src/testing'
3+
import { createClient } from '../utils/client'
4+
5+
defineTest({
6+
name: 'css language handles custom-variant at-rule',
7+
fs: {
8+
//
9+
},
10+
prepare: async ({ root }) => ({
11+
client: await createClient({
12+
server: 'css',
13+
root,
14+
}),
15+
}),
16+
handle: async ({ client }) => {
17+
let doc = await client.open({
18+
lang: 'tailwindcss',
19+
name: 'file-1.css',
20+
text: css`
21+
@import 'tailwindcss';
22+
@custom-variant foo (&:hover);
23+
@custom-variant bar {
24+
&:hover {
25+
@slot;
26+
}
27+
}
28+
`,
29+
})
30+
31+
expect(await doc.diagnostics()).toEqual([])
32+
},
33+
})

packages/tailwindcss-language-server/tests/utils/connection.ts

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createConnection } from 'vscode-languageserver/node'
33
import type { ProtocolConnection } from 'vscode-languageclient/node'
44
import { Duplex, type Readable, type Writable } from 'node:stream'
55
import { TW } from '../../src/tw'
6+
import { CssServer } from '../../src/language/css-server'
67

78
class TestStream extends Duplex {
89
_write(chunk: string, _encoding: string, done: () => void) {
@@ -18,6 +19,10 @@ const SERVERS = {
1819
ServerClass: TW,
1920
binaryPath: './bin/tailwindcss-language-server',
2021
},
22+
css: {
23+
ServerClass: CssServer,
24+
binaryPath: './bin/css-language-server',
25+
},
2126
}
2227

2328
export interface ConnectOptions {

0 commit comments

Comments
 (0)