diff --git a/src/vs/workbench/contrib/scm/browser/scmViewPane.ts b/src/vs/workbench/contrib/scm/browser/scmViewPane.ts index b3dfe57947dc9..c41a9bdbefff1 100644 --- a/src/vs/workbench/contrib/scm/browser/scmViewPane.ts +++ b/src/vs/workbench/contrib/scm/browser/scmViewPane.ts @@ -2294,7 +2294,6 @@ export class SCMViewPane extends ViewPane { private treeScrollTop: number | undefined; private treeContainer!: HTMLElement; private tree!: WorkbenchCompressibleAsyncDataTree; - private treeDataSource!: SCMTreeDataSource; private listLabels!: ResourceLabels; private inputRenderer!: InputRenderer; @@ -2529,7 +2528,8 @@ export class SCMViewPane extends ViewPane { actionRunner.onWillRun(() => this.tree.domFocus(), this, this.disposables); this.disposables.add(actionRunner); - this.treeDataSource = this.instantiationService.createInstance(SCMTreeDataSource, () => this.viewMode, () => this.alwaysShowRepositories, () => this.showActionButton, () => this.showIncomingChanges, () => this.showOutgoingChanges); + const treeDataSource = this.instantiationService.createInstance(SCMTreeDataSource, () => this.viewMode, () => this.alwaysShowRepositories, () => this.showActionButton, () => this.showIncomingChanges, () => this.showOutgoingChanges); + this.disposables.add(treeDataSource); this.tree = this.instantiationService.createInstance( WorkbenchCompressibleAsyncDataTree, @@ -2548,7 +2548,7 @@ export class SCMViewPane extends ViewPane { this.instantiationService.createInstance(HistoryItemChangeRenderer, () => this.viewMode, this.listLabels), this.instantiationService.createInstance(SeparatorRenderer) ], - this.treeDataSource, + treeDataSource, { horizontalScrolling: false, setRowLineHeight: false, @@ -2717,10 +2717,7 @@ export class SCMViewPane extends ViewPane { })); if (repository.provider.historyProvider) { - repositoryDisposables.add(repository.provider.historyProvider.onDidChangeCurrentHistoryItemGroup(() => { - this.treeDataSource.deleteCacheEntry(repository); - this.updateChildren(repository); - })); + repositoryDisposables.add(repository.provider.historyProvider.onDidChangeCurrentHistoryItemGroup(() => this.updateChildren(repository))); } const resourceGroupDisposables = repositoryDisposables.add(new DisposableMap()); @@ -2754,7 +2751,6 @@ export class SCMViewPane extends ViewPane { // Removed repositories for (const repository of removed) { - this.treeDataSource.deleteCacheEntry(repository); this.items.deleteAndDispose(repository); } @@ -2973,6 +2969,8 @@ export class SCMViewPane extends ViewPane { class SCMTreeDataSource implements IAsyncDataSource { private readonly historyProviderCache = new Map(); + private readonly repositoryDisposables = new DisposableMap(); + private readonly disposables = new DisposableStore(); constructor( private readonly viewMode: () => ViewMode, @@ -2982,7 +2980,10 @@ class SCMTreeDataSource implements IAsyncDataSource ShowChangesSetting, @ISCMViewService private readonly scmViewService: ISCMViewService, @IUriIdentityService private uriIdentityService: IUriIdentityService, - ) { } + ) { + this.scmViewService.onDidChangeVisibleRepositories(this.onDidChangeVisibleRepositories, this, this.disposables); + this.onDidChangeVisibleRepositories({ added: this.scmViewService.visibleRepositories, removed: Iterable.empty() }); + } hasChildren(inputOrElement: ISCMViewService | TreeElement): boolean { if (isSCMViewService(inputOrElement)) { @@ -3212,13 +3213,6 @@ class SCMTreeDataSource implements IAsyncDataSource(), - historyItemChanges: new Map() - }; - } - getParent(element: TreeElement): ISCMViewService | TreeElement { if (isSCMResourceNode(element)) { if (element.parent === element.context.resourceTree.root) { @@ -3250,8 +3244,36 @@ class SCMTreeDataSource implements IAsyncDataSource this.historyProviderCache.delete(repository))); + } + + this.repositoryDisposables.set(repository, repositoryDisposables); + } + + // Removed repositories + for (const repository of removed) { + this.repositoryDisposables.deleteAndDispose(repository); + this.historyProviderCache.delete(repository); + } + } + + private getHistoryProviderCacheEntry(repository: ISCMRepository): ISCMHistoryProviderCacheEntry { + return this.historyProviderCache.get(repository) ?? { + historyItemGroupDetails: undefined, + historyItems: new Map(), + historyItemChanges: new Map() + }; + } + + dispose(): void { + this.repositoryDisposables.dispose(); + this.disposables.dispose(); } }