@@ -3,13 +3,11 @@ import * as cp from 'node:child_process'
3
3
import * as rpc from 'vscode-jsonrpc'
4
4
import { beforeAll } from 'vitest'
5
5
6
- let settings = { }
7
- let initPromise
8
- let childProcess
9
- let docSettings = new Map ( )
10
-
11
6
async function init ( fixture ) {
12
- childProcess = cp . fork ( './bin/tailwindcss-language-server' , { silent : true } )
7
+ let settings = { }
8
+ let docSettings = new Map ( )
9
+
10
+ let childProcess = cp . fork ( './bin/tailwindcss-language-server' , { silent : true } )
13
11
14
12
const capabilities = {
15
13
textDocument : {
@@ -116,7 +114,7 @@ async function init(fixture) {
116
114
} )
117
115
} )
118
116
119
- initPromise = new Promise ( ( resolve ) => {
117
+ let initPromise = new Promise ( ( resolve ) => {
120
118
connection . onRequest ( new rpc . RequestType ( 'client/registerCapability' ) , ( { registrations } ) => {
121
119
if ( registrations . findIndex ( ( r ) => r . method === 'textDocument/completion' ) > - 1 ) {
122
120
resolve ( )
@@ -177,33 +175,18 @@ async function init(fixture) {
177
175
}
178
176
179
177
export function withFixture ( fixture , callback ) {
180
- let c
178
+ let c = { }
181
179
182
180
beforeAll ( async ( ) => {
183
- c = await init ( fixture )
181
+ // Using the connection object as the prototype lets us access the connection
182
+ // without defining getters for all the methods and also lets us add helpers
183
+ // to the connection object without having to resort to using a Proxy
184
+ Object . setPrototypeOf ( c , await init ( fixture ) )
185
+
184
186
return ( ) => c . connection . end ( )
185
187
} )
186
188
187
- callback ( {
188
- get connection ( ) {
189
- return c . connection
190
- } ,
191
- get sendRequest ( ) {
192
- return c . sendRequest
193
- } ,
194
- get onNotification ( ) {
195
- return c . onNotification
196
- } ,
197
- get openDocument ( ) {
198
- return c . openDocument
199
- } ,
200
- get updateSettings ( ) {
201
- return c . updateSettings
202
- } ,
203
- get updateFile ( ) {
204
- return c . updateFile
205
- } ,
206
- } )
189
+ callback ( c )
207
190
}
208
191
209
192
// let counter = 0
0 commit comments