Introduce recomputeAllData to avoid mutating pathData from outside of FilePathDiscovery

This commit is contained in:
Robert
2023-06-16 16:35:58 +01:00
parent c6a7e1fb3c
commit da92a67834
2 changed files with 11 additions and 10 deletions

View File

@@ -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.
*/

View File

@@ -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);
}