Skip to content

Commit

Permalink
Improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Sep 30, 2024
1 parent 04e6644 commit 8df5467
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/langium/src/utils/caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,20 @@ export class DocumentCache<K, V> extends ContextCache<URI | string, K, V, string
*/
constructor(sharedServices: LangiumSharedCoreServices, state?: DocumentState) {
super(uri => uri.toString());
let disposable: Disposable;
if (state) {
this.onDispose(sharedServices.workspace.DocumentBuilder.onDocumentPhase(state, document => {
disposable = sharedServices.workspace.DocumentBuilder.onDocumentPhase(state, document => {
this.clear(document.uri.toString());
}));
});
} else {
this.onDispose(sharedServices.workspace.DocumentBuilder.onUpdate((changed, deleted) => {
disposable = sharedServices.workspace.DocumentBuilder.onUpdate((changed, deleted) => {
const allUris = changed.concat(deleted);
for (const uri of allUris) {
this.clear(uri);
}
}));
});
}
this.toDispose.push(disposable);
}
}

Expand All @@ -187,14 +189,16 @@ export class WorkspaceCache<K, V> extends SimpleCache<K, V> {
*/
constructor(sharedServices: LangiumSharedCoreServices, state?: DocumentState) {
super();
let disposable: Disposable;
if (state) {
this.onDispose(sharedServices.workspace.DocumentBuilder.onBuildPhase(state, () => {
disposable = sharedServices.workspace.DocumentBuilder.onBuildPhase(state, () => {
this.clear();
}));
});
} else {
this.onDispose(sharedServices.workspace.DocumentBuilder.onUpdate(() => {
disposable = sharedServices.workspace.DocumentBuilder.onUpdate(() => {
this.clear();
}));
});
}
this.toDispose.push(disposable);
}
}

0 comments on commit 8df5467

Please sign in to comment.