Skip to content

Commit e3c7c61

Browse files
committed
Fix build detection
1 parent 212245e commit e3c7c61

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

language-server/src/services/schemas-neovim.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe("Feature - workspace (neovim)", () => {
3939
});
4040
});
4141

42-
test("a change to a watched file should validate the workspace", async () => {
42+
test("a change to a watched file should validate the workspace", { retry: 3 }, async () => {
4343
const schemaUris: string[] = [];
4444

4545
client.onNotification(PublishDiagnosticsNotification.type, (params) => {

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

Lines changed: 16 additions & 22 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 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(10);
315+
return Promise.all(this.builds);
322316
}
323317
}
324318

0 commit comments

Comments
 (0)