Skip to content

Commit 5405b1b

Browse files
Convert refresh to return a promise
1 parent 5a2cb8b commit 5405b1b

5 files changed

Lines changed: 12 additions & 10 deletions

File tree

extensions/ql-vscode/src/common/discovery.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { getErrorMessage } from "../pure/helpers-pure";
99
*/
1010
export abstract class Discovery<T> extends DisposableObject {
1111
private retry = false;
12-
private discoveryInProgress = false;
12+
private currentDiscoveryPromise: Promise<void> | undefined;
1313

1414
constructor(private readonly name: string) {
1515
super();
@@ -18,8 +18,10 @@ export abstract class Discovery<T> extends DisposableObject {
1818
/**
1919
* Force the discovery process to run. Normally invoked by the derived class when a relevant file
2020
* system change is detected.
21+
*
22+
* Returns a promise that resolves when the refresh is complete, including any retries.
2123
*/
22-
public refresh(): void {
24+
public refresh(): Promise<void> {
2325
// We avoid having multiple discovery operations in progress at the same time. Otherwise, if we
2426
// got a storm of refresh requests due to, say, the copying or deletion of a large directory
2527
// tree, we could potentially spawn a separate simultaneous discovery operation for each
@@ -36,14 +38,14 @@ export abstract class Discovery<T> extends DisposableObject {
3638
// other change notifications that might be coming along. However, this would create more
3739
// latency in the common case, in order to save a bit of latency in the uncommon case.
3840

39-
if (this.discoveryInProgress) {
41+
if (this.currentDiscoveryPromise !== undefined) {
4042
// There's already a discovery operation in progress. Tell it to restart when it's done.
4143
this.retry = true;
4244
} else {
4345
// No discovery in progress, so start one now.
44-
this.discoveryInProgress = true;
45-
void this.launchDiscovery();
46+
this.currentDiscoveryPromise = this.launchDiscovery();
4647
}
48+
return this.currentDiscoveryPromise;
4749
}
4850

4951
/**
@@ -71,7 +73,7 @@ export abstract class Discovery<T> extends DisposableObject {
7173
this.retry = false;
7274
await this.launchDiscovery();
7375
} else {
74-
this.discoveryInProgress = false;
76+
this.currentDiscoveryPromise = undefined;
7577

7678
// If the discovery was successful, then update any listeners with the results.
7779
if (results !== undefined) {

extensions/ql-vscode/src/queries-panel/queries-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class QueriesModule extends DisposableObject {
2121

2222
const queryDiscovery = new QueryDiscovery(app, cliServer);
2323
this.push(queryDiscovery);
24-
queryDiscovery.refresh();
24+
void queryDiscovery.refresh();
2525

2626
const queriesPanel = new QueriesPanel(queryDiscovery);
2727
this.push(queriesPanel);

extensions/ql-vscode/src/query-testing/qltest-discovery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class QLTestDiscovery extends Discovery<QLTestDiscoveryResults> {
6464

6565
private handleDidChange(uri: Uri): void {
6666
if (!QLTestDiscovery.ignoreTestPath(uri.fsPath)) {
67-
this.refresh();
67+
void this.refresh();
6868
}
6969
}
7070
protected async discover(): Promise<QLTestDiscoveryResults> {

extensions/ql-vscode/src/query-testing/test-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class QLTestAdapter extends DisposableObject implements TestAdapter {
115115
this.qlTestDiscovery = this.push(
116116
new QLTestDiscovery(workspaceFolder, cliServer),
117117
);
118-
this.qlTestDiscovery.refresh();
118+
void this.qlTestDiscovery.refresh();
119119

120120
this.push(this.qlTestDiscovery.onDidChangeTests(this.discoverTests, this));
121121
}

extensions/ql-vscode/src/query-testing/test-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class WorkspaceFolderHandler extends DisposableObject {
9292
this.push(
9393
this.testDiscovery.onDidChangeTests(this.handleDidChangeTests, this),
9494
);
95-
this.testDiscovery.refresh();
95+
void this.testDiscovery.refresh();
9696
}
9797

9898
private handleDidChangeTests(): void {

0 commit comments

Comments
 (0)