Skip to content

Commit e18feb9

Browse files
committed
Windows sucks
1 parent 212245e commit e18feb9

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

language-server/src/test/test-client.ts

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class TestClient<Configuration> {
4444
private openDocuments: Set<string>;
4545
private workspaceFolder: Promise<string>;
4646
private watchEnabled: boolean;
47+
private buildCompleted;
4748

4849
onRequest: Connection["onRequest"];
4950
sendRequest: Connection["sendRequest"];
@@ -97,8 +98,22 @@ export class TestClient<Configuration> {
9798
}
9899
});
99100

100-
this.client.onRequest(WorkDoneProgressCreateRequest.type, () => {
101-
// Nothing to do
101+
this.buildCompleted = createPromise();
102+
let builds = 0;
103+
104+
this.client.onRequest(WorkDoneProgressCreateRequest.type, ({ token }) => {
105+
this.client.onProgress(WorkDoneProgress.type, token, ({ kind }) => {
106+
if (kind === "begin") {
107+
builds++;
108+
} else if (kind === "end") {
109+
builds--;
110+
if (builds === 0) {
111+
// @ts-expect-error Foo
112+
this.buildCompleted.resolve();
113+
this.buildCompleted = createPromise();
114+
}
115+
}
116+
});
102117
});
103118

104119
this.client.onRequest(ConfigurationRequest.type, (params) => {
@@ -221,8 +236,6 @@ export class TestClient<Configuration> {
221236
async changeConfiguration(settings: Partial<Configuration>) {
222237
this._settings = settings;
223238

224-
const buildCompleted = this.buildCompleted();
225-
226239
if (this.configurationChangeNotificationOptions === null) {
227240
await this.client.sendNotification(DidChangeConfigurationNotification.type, {
228241
settings: null
@@ -235,7 +248,7 @@ export class TestClient<Configuration> {
235248
});
236249
}
237250

238-
await buildCompleted;
251+
await this.buildCompleted.promise;
239252
}
240253

241254
async writeDocument(uri: string, text: string) {
@@ -244,8 +257,6 @@ export class TestClient<Configuration> {
244257

245258
await writeFile(fileURLToPath(fullUri), text, "utf-8");
246259

247-
const buildCompleted = this.buildCompleted();
248-
249260
if (this.watchEnabled) {
250261
await this.client.sendNotification(DidChangeWatchedFilesNotification.type, {
251262
changes: [{
@@ -255,7 +266,7 @@ export class TestClient<Configuration> {
255266
});
256267
}
257268

258-
await buildCompleted;
269+
await this.buildCompleted.promise;
259270

260271
return fullUri;
261272
}
@@ -265,8 +276,6 @@ export class TestClient<Configuration> {
265276

266277
await rm(fileURLToPath(fullUri));
267278

268-
const buildCompleted = this.buildCompleted();
269-
270279
if (this.watchEnabled) {
271280
await this.client.sendNotification(DidChangeWatchedFilesNotification.type, {
272281
changes: [{
@@ -276,7 +285,7 @@ export class TestClient<Configuration> {
276285
});
277286
}
278287

279-
await buildCompleted;
288+
await this.buildCompleted.promise;
280289

281290
return fullUri;
282291
}
@@ -307,19 +316,6 @@ export class TestClient<Configuration> {
307316
}
308317
});
309318
}
310-
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-
});
322-
}
323319
}
324320

325321
export class TestStream extends Duplex {
@@ -331,3 +327,14 @@ export class TestStream extends Duplex {
331327
_read() {
332328
}
333329
}
330+
331+
const createPromise = () => {
332+
let resolve;
333+
let reject;
334+
const promise = new Promise<void>((resolveFn, rejectFn) => {
335+
resolve = resolveFn;
336+
reject = rejectFn;
337+
});
338+
339+
return { promise, resolve, reject };
340+
};

0 commit comments

Comments
 (0)