Skip to content

Commit b044195

Browse files
Remove the update method from the Discovery class
See #2490 (comment) for more explanation. This will make the class more useful for future usecases where we don't want the behaviour of only calling update when there isn't another refresh scheduled. I also think it doesn't negatively affect other users such as the query test discovery. The effect should be that we'll see more updates to the UI. These updates will get overwritten quickly, but they are all genuine snapshots of the filesystem at the point the discovery process ran, so they aren't incorrect, or aren't more incorrect than continuing to show the old state before any discovery ran.
1 parent 8803433 commit b044195

3 files changed

Lines changed: 16 additions & 71 deletions

File tree

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Logger } from "./logging";
77
* files. This class automatically prevents more than one discovery operation from running at the
88
* same time.
99
*/
10-
export abstract class Discovery<T> extends DisposableObject {
10+
export abstract class Discovery extends DisposableObject {
1111
private restartWhenFinished = false;
1212
private currentDiscoveryPromise: Promise<void> | undefined;
1313

@@ -64,14 +64,12 @@ export abstract class Discovery<T> extends DisposableObject {
6464
* discovery.
6565
*/
6666
private async launchDiscovery(): Promise<void> {
67-
let results: T | undefined;
6867
try {
69-
results = await this.discover();
68+
await this.discover();
7069
} catch (err) {
7170
void this.logger.log(
7271
`${this.name} failed. Reason: ${getErrorMessage(err)}`,
7372
);
74-
results = undefined;
7573
}
7674

7775
if (this.restartWhenFinished) {
@@ -82,24 +80,11 @@ export abstract class Discovery<T> extends DisposableObject {
8280
// succeeded or failed.
8381
this.restartWhenFinished = false;
8482
await this.launchDiscovery();
85-
} else {
86-
// If the discovery was successful, then update any listeners with the results.
87-
if (results !== undefined) {
88-
this.update(results);
89-
}
9083
}
9184
}
9285

9386
/**
9487
* Overridden by the derived class to spawn the actual discovery operation, returning the results.
9588
*/
96-
protected abstract discover(): Promise<T>;
97-
98-
/**
99-
* Overridden by the derived class to atomically update the `Discovery` object with the results of
100-
* the discovery operation, and to notify any listeners that the discovery results may have
101-
* changed.
102-
* @param results The discovery results returned by the `discover` function.
103-
*/
104-
protected abstract update(results: T): void;
89+
protected abstract discover(): Promise<void>;
10590
}

extensions/ql-vscode/src/queries-panel/query-discovery.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@ export interface QueryDiscoveryResults {
3737
/**
3838
* Discovers all query files contained in the QL packs in a given workspace folder.
3939
*/
40-
export class QueryDiscovery
41-
extends Discovery<QueryDiscoveryResults>
42-
implements QueryDiscoverer
43-
{
44-
private results: QueryDiscoveryResults | undefined;
40+
export class QueryDiscovery extends Discovery implements QueryDiscoverer {
41+
private results: Array<FileTreeDirectory<string>> | undefined;
4542

4643
private readonly onDidChangeQueriesEmitter: AppEventEmitter<void>;
4744
private readonly watcher: MultiFileSystemWatcher = this.push(
@@ -60,7 +57,7 @@ export class QueryDiscovery
6057
}
6158

6259
public get queries(): Array<FileTreeDirectory<string>> | undefined {
63-
return this.results?.queries;
60+
return this.results;
6461
}
6562

6663
/**
@@ -70,28 +67,13 @@ export class QueryDiscovery
7067
return this.onDidChangeQueriesEmitter.event;
7168
}
7269

73-
protected async discover(): Promise<QueryDiscoveryResults> {
70+
protected async discover() {
7471
const workspaceFolders = getOnDiskWorkspaceFoldersObjects();
75-
if (workspaceFolders.length === 0) {
76-
return {
77-
queries: [],
78-
watchPaths: [],
79-
};
80-
}
81-
82-
const queries = await this.discoverQueries(workspaceFolders);
83-
84-
return {
85-
queries,
86-
watchPaths: workspaceFolders.map((f) => f.uri),
87-
};
88-
}
8972

90-
protected update(results: QueryDiscoveryResults): void {
91-
this.results = results;
73+
this.results = await this.discoverQueries(workspaceFolders);
9274

9375
this.watcher.clear();
94-
for (const watchPath of results.watchPaths) {
76+
for (const watchPath of workspaceFolders.map((f) => f.uri)) {
9577
// Watch for changes to any `.ql` file
9678
this.watcher.addWatch(new RelativePattern(watchPath, "**/*.{ql}"));
9779
// need to explicitly watch for changes to directories themselves.

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

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,10 @@ import { pathExists } from "fs-extra";
1414
import { FileTreeDirectory, FileTreeLeaf } from "../common/file-tree-nodes";
1515
import { extLogger } from "../common";
1616

17-
/**
18-
* The results of discovering QL tests.
19-
*/
20-
interface QLTestDiscoveryResults {
21-
/**
22-
* A directory that contains one or more QL Tests, or other QLTestDirectories.
23-
*/
24-
testDirectory: FileTreeDirectory | undefined;
25-
26-
/**
27-
* The file system path to a directory to watch. If any ql or qlref file changes in
28-
* this directory, then this signifies a change in tests.
29-
*/
30-
watchPath: string;
31-
}
32-
3317
/**
3418
* Discovers all QL tests contained in the QL packs in a given workspace folder.
3519
*/
36-
export class QLTestDiscovery extends Discovery<QLTestDiscoveryResults> {
20+
export class QLTestDiscovery extends Discovery {
3721
private readonly _onDidChangeTests = this.push(new EventEmitter<void>());
3822
private readonly watcher: MultiFileSystemWatcher = this.push(
3923
new MultiFileSystemWatcher(),
@@ -69,24 +53,18 @@ export class QLTestDiscovery extends Discovery<QLTestDiscoveryResults> {
6953
void this.refresh();
7054
}
7155
}
72-
protected async discover(): Promise<QLTestDiscoveryResults> {
73-
const testDirectory = await this.discoverTests();
74-
return {
75-
testDirectory,
76-
watchPath: this.workspaceFolder.uri.fsPath,
77-
};
78-
}
79-
80-
protected update(results: QLTestDiscoveryResults): void {
81-
this._testDirectory = results.testDirectory;
56+
protected async discover() {
57+
this._testDirectory = await this.discoverTests();
8258

8359
this.watcher.clear();
8460
// Watch for changes to any `.ql` or `.qlref` file in any of the QL packs that contain tests.
8561
this.watcher.addWatch(
86-
new RelativePattern(results.watchPath, "**/*.{ql,qlref}"),
62+
new RelativePattern(this.workspaceFolder.uri.fsPath, "**/*.{ql,qlref}"),
8763
);
8864
// need to explicitly watch for changes to directories themselves.
89-
this.watcher.addWatch(new RelativePattern(results.watchPath, "**/"));
65+
this.watcher.addWatch(
66+
new RelativePattern(this.workspaceFolder.uri.fsPath, "**/"),
67+
);
9068
this._onDidChangeTests.fire(undefined);
9169
}
9270

0 commit comments

Comments
 (0)