Introduce recomputeAllData to avoid mutating pathData from outside of FilePathDiscovery
This commit is contained in:
@@ -89,6 +89,16 @@ export abstract class FilePathDiscovery<T extends PathData> extends Discovery {
|
||||
existingData: T,
|
||||
): boolean;
|
||||
|
||||
/**
|
||||
* Update the data for every path by calling `getDataForPath`.
|
||||
*/
|
||||
protected async recomputeAllData() {
|
||||
this.pathData = await Promise.all(
|
||||
this.pathData.map((p) => this.getDataForPath(p.path)),
|
||||
);
|
||||
this.onDidChangePathDataEmitter.fire();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the initial scan of the entire workspace and set up watchers for future changes.
|
||||
*/
|
||||
|
||||
@@ -39,7 +39,7 @@ export class QueryDiscovery
|
||||
|
||||
this.push(
|
||||
this.queryPackDiscovery.onDidChangeQueryPacks(
|
||||
this.recomputeAllQueryLanguages.bind(this),
|
||||
this.recomputeAllData.bind(this),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -103,15 +103,6 @@ export class QueryDiscovery
|
||||
return newData.language !== existingData.language;
|
||||
}
|
||||
|
||||
private recomputeAllQueryLanguages() {
|
||||
// All we know is that something has changed in the set of known query packs.
|
||||
// We have no choice but to recompute the language for all queries.
|
||||
for (const query of this.pathData) {
|
||||
query.language = this.determineQueryLanguage(query.path);
|
||||
}
|
||||
this.onDidChangePathDataEmitter.fire();
|
||||
}
|
||||
|
||||
private determineQueryLanguage(path: string): QueryLanguage | undefined {
|
||||
return this.queryPackDiscovery.getLanguageForQueryFile(path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user