diff --git a/extensions/ql-vscode/src/common/discovery.ts b/extensions/ql-vscode/src/common/discovery.ts index 8f5ef1406..735177008 100644 --- a/extensions/ql-vscode/src/common/discovery.ts +++ b/extensions/ql-vscode/src/common/discovery.ts @@ -9,7 +9,7 @@ import { getErrorMessage } from "../pure/helpers-pure"; */ export abstract class Discovery extends DisposableObject { private retry = false; - private discoveryInProgress = false; + private currentDiscoveryPromise: Promise | undefined; constructor(private readonly name: string) { super(); @@ -18,8 +18,10 @@ export abstract class Discovery extends DisposableObject { /** * Force the discovery process to run. Normally invoked by the derived class when a relevant file * system change is detected. + * + * Returns a promise that resolves when the refresh is complete, including any retries. */ - public refresh(): void { + public refresh(): Promise { // We avoid having multiple discovery operations in progress at the same time. Otherwise, if we // got a storm of refresh requests due to, say, the copying or deletion of a large directory // tree, we could potentially spawn a separate simultaneous discovery operation for each @@ -36,14 +38,14 @@ export abstract class Discovery extends DisposableObject { // other change notifications that might be coming along. However, this would create more // latency in the common case, in order to save a bit of latency in the uncommon case. - if (this.discoveryInProgress) { + if (this.currentDiscoveryPromise !== undefined) { // There's already a discovery operation in progress. Tell it to restart when it's done. this.retry = true; } else { // No discovery in progress, so start one now. - this.discoveryInProgress = true; - void this.launchDiscovery(); + this.currentDiscoveryPromise = this.launchDiscovery(); } + return this.currentDiscoveryPromise; } /** @@ -71,7 +73,7 @@ export abstract class Discovery extends DisposableObject { this.retry = false; await this.launchDiscovery(); } else { - this.discoveryInProgress = false; + this.currentDiscoveryPromise = undefined; // If the discovery was successful, then update any listeners with the results. if (results !== undefined) { diff --git a/extensions/ql-vscode/src/queries-panel/queries-module.ts b/extensions/ql-vscode/src/queries-panel/queries-module.ts index d62812f46..aede56a8d 100644 --- a/extensions/ql-vscode/src/queries-panel/queries-module.ts +++ b/extensions/ql-vscode/src/queries-panel/queries-module.ts @@ -21,7 +21,7 @@ export class QueriesModule extends DisposableObject { const queryDiscovery = new QueryDiscovery(app, cliServer); this.push(queryDiscovery); - queryDiscovery.refresh(); + void queryDiscovery.refresh(); const queriesPanel = new QueriesPanel(queryDiscovery); this.push(queriesPanel); diff --git a/extensions/ql-vscode/src/query-testing/qltest-discovery.ts b/extensions/ql-vscode/src/query-testing/qltest-discovery.ts index b7d333ff6..6775b9611 100644 --- a/extensions/ql-vscode/src/query-testing/qltest-discovery.ts +++ b/extensions/ql-vscode/src/query-testing/qltest-discovery.ts @@ -64,7 +64,7 @@ export class QLTestDiscovery extends Discovery { private handleDidChange(uri: Uri): void { if (!QLTestDiscovery.ignoreTestPath(uri.fsPath)) { - this.refresh(); + void this.refresh(); } } protected async discover(): Promise { diff --git a/extensions/ql-vscode/src/query-testing/test-adapter.ts b/extensions/ql-vscode/src/query-testing/test-adapter.ts index 86c37b845..85b30a47c 100644 --- a/extensions/ql-vscode/src/query-testing/test-adapter.ts +++ b/extensions/ql-vscode/src/query-testing/test-adapter.ts @@ -115,7 +115,7 @@ export class QLTestAdapter extends DisposableObject implements TestAdapter { this.qlTestDiscovery = this.push( new QLTestDiscovery(workspaceFolder, cliServer), ); - this.qlTestDiscovery.refresh(); + void this.qlTestDiscovery.refresh(); this.push(this.qlTestDiscovery.onDidChangeTests(this.discoverTests, this)); } diff --git a/extensions/ql-vscode/src/query-testing/test-manager.ts b/extensions/ql-vscode/src/query-testing/test-manager.ts index 94b79432b..073cc7170 100644 --- a/extensions/ql-vscode/src/query-testing/test-manager.ts +++ b/extensions/ql-vscode/src/query-testing/test-manager.ts @@ -92,7 +92,7 @@ class WorkspaceFolderHandler extends DisposableObject { this.push( this.testDiscovery.onDidChangeTests(this.handleDidChangeTests, this), ); - this.testDiscovery.refresh(); + void this.testDiscovery.refresh(); } private handleDidChangeTests(): void {