Skip to content

Commit da92a67

Browse files
Introduce recomputeAllData to avoid mutating pathData from outside of FilePathDiscovery
1 parent c6a7e1f commit da92a67

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ export abstract class FilePathDiscovery<T extends PathData> extends Discovery {
8989
existingData: T,
9090
): boolean;
9191

92+
/**
93+
* Update the data for every path by calling `getDataForPath`.
94+
*/
95+
protected async recomputeAllData() {
96+
this.pathData = await Promise.all(
97+
this.pathData.map((p) => this.getDataForPath(p.path)),
98+
);
99+
this.onDidChangePathDataEmitter.fire();
100+
}
101+
92102
/**
93103
* Do the initial scan of the entire workspace and set up watchers for future changes.
94104
*/

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class QueryDiscovery
3939

4040
this.push(
4141
this.queryPackDiscovery.onDidChangeQueryPacks(
42-
this.recomputeAllQueryLanguages.bind(this),
42+
this.recomputeAllData.bind(this),
4343
),
4444
);
4545
}
@@ -103,15 +103,6 @@ export class QueryDiscovery
103103
return newData.language !== existingData.language;
104104
}
105105

106-
private recomputeAllQueryLanguages() {
107-
// All we know is that something has changed in the set of known query packs.
108-
// We have no choice but to recompute the language for all queries.
109-
for (const query of this.pathData) {
110-
query.language = this.determineQueryLanguage(query.path);
111-
}
112-
this.onDidChangePathDataEmitter.fire();
113-
}
114-
115106
private determineQueryLanguage(path: string): QueryLanguage | undefined {
116107
return this.queryPackDiscovery.getLanguageForQueryFile(path);
117108
}

0 commit comments

Comments
 (0)