@@ -44,6 +44,7 @@ export class TestClient<Configuration> {
4444 private openDocuments : Set < string > ;
4545 private workspaceFolder : Promise < string > ;
4646 private watchEnabled : boolean ;
47+ private builds : Promise < void > [ ] ;
4748
4849 onRequest : Connection [ "onRequest" ] ;
4950 sendRequest : Connection [ "sendRequest" ] ;
@@ -97,8 +98,15 @@ export class TestClient<Configuration> {
9798 }
9899 } ) ;
99100
100- this . client . onRequest ( WorkDoneProgressCreateRequest . type , ( ) => {
101- // Nothing to do
101+ this . builds = [ ] ;
102+ this . client . onRequest ( WorkDoneProgressCreateRequest . type , ( { token } ) => {
103+ this . builds . push ( new Promise ( ( resolve ) => {
104+ this . client . onProgress ( WorkDoneProgress . type , token , ( { kind } ) => {
105+ if ( kind === "end" ) {
106+ resolve ( ) ;
107+ }
108+ } ) ;
109+ } ) ) ;
102110 } ) ;
103111
104112 this . client . onRequest ( ConfigurationRequest . type , ( params ) => {
@@ -221,8 +229,6 @@ export class TestClient<Configuration> {
221229 async changeConfiguration ( settings : Partial < Configuration > ) {
222230 this . _settings = settings ;
223231
224- const buildCompleted = this . buildCompleted ( ) ;
225-
226232 if ( this . configurationChangeNotificationOptions === null ) {
227233 await this . client . sendNotification ( DidChangeConfigurationNotification . type , {
228234 settings : null
@@ -235,7 +241,7 @@ export class TestClient<Configuration> {
235241 } ) ;
236242 }
237243
238- await buildCompleted ;
244+ await this . buildCompleted ( ) ;
239245 }
240246
241247 async writeDocument ( uri : string , text : string ) {
@@ -244,8 +250,6 @@ export class TestClient<Configuration> {
244250
245251 await writeFile ( fileURLToPath ( fullUri ) , text , "utf-8" ) ;
246252
247- const buildCompleted = this . buildCompleted ( ) ;
248-
249253 if ( this . watchEnabled ) {
250254 await this . client . sendNotification ( DidChangeWatchedFilesNotification . type , {
251255 changes : [ {
@@ -255,7 +259,7 @@ export class TestClient<Configuration> {
255259 } ) ;
256260 }
257261
258- await buildCompleted ;
262+ await this . buildCompleted ( ) ;
259263
260264 return fullUri ;
261265 }
@@ -265,8 +269,6 @@ export class TestClient<Configuration> {
265269
266270 await rm ( fileURLToPath ( fullUri ) ) ;
267271
268- const buildCompleted = this . buildCompleted ( ) ;
269-
270272 if ( this . watchEnabled ) {
271273 await this . client . sendNotification ( DidChangeWatchedFilesNotification . type , {
272274 changes : [ {
@@ -276,7 +278,7 @@ export class TestClient<Configuration> {
276278 } ) ;
277279 }
278280
279- await buildCompleted ;
281+ await this . buildCompleted ( ) ;
280282
281283 return fullUri ;
282284 }
@@ -308,17 +310,9 @@ export class TestClient<Configuration> {
308310 } ) ;
309311 }
310312
311- // TODO: Duplicated code
312- private buildCompleted ( ) {
313- return new Promise < void > ( ( resolve ) => {
314- this . client . onRequest ( WorkDoneProgressCreateRequest . type , ( { token } ) => {
315- this . client . onProgress ( WorkDoneProgress . type , token , ( { kind } ) => {
316- if ( kind === "end" ) {
317- resolve ( ) ;
318- }
319- } ) ;
320- } ) ;
321- } ) ;
313+ private async buildCompleted ( ) {
314+ await wait ( 100 ) ;
315+ return Promise . all ( this . builds ) ;
322316 }
323317}
324318
0 commit comments