Skip to content

Commit 4463556

Browse files
authored
Actually dispose internal tree when extension disposes tree (microsoft#210226)
1 parent 9deb01d commit 4463556

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/vs/workbench/browser/parts/views/media/views.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
padding-left: 24px;
4747
}
4848

49-
.monaco-workbench .tree-explorer-viewlet-tree-view .message a {
49+
.monaco-workbench .tree-explorer-viewlet-tree-view .message p > a {
5050
color: var(--vscode-textLink-foreground);
5151
}
5252

src/vs/workbench/browser/parts/views/treeView.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
394394
this.refresh();
395395
} else {
396396
this._dataProvider = undefined;
397+
this.treeDisposables.clear();
398+
this.activated = false;
397399
this.updateMessage();
398400
}
399401

@@ -602,6 +604,7 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
602604
}
603605
}
604606

607+
protected activated: boolean = false;
605608
protected abstract activate(): void;
606609

607610
focus(reveal: boolean = true, revealItem?: ITreeItem): void {
@@ -637,19 +640,21 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
637640
this._register(focusTracker.onDidBlur(() => this.focused = false));
638641
}
639642

643+
private readonly treeDisposables: DisposableStore = this._register(new DisposableStore());
640644
protected createTree() {
645+
this.treeDisposables.clear();
641646
const actionViewItemProvider = createActionViewItem.bind(undefined, this.instantiationService);
642-
const treeMenus = this._register(this.instantiationService.createInstance(TreeMenus, this.id));
643-
this.treeLabels = this._register(this.instantiationService.createInstance(ResourceLabels, this));
647+
const treeMenus = this.treeDisposables.add(this.instantiationService.createInstance(TreeMenus, this.id));
648+
this.treeLabels = this.treeDisposables.add(this.instantiationService.createInstance(ResourceLabels, this));
644649
const dataSource = this.instantiationService.createInstance(TreeDataSource, this, <T>(task: Promise<T>) => this.progressService.withProgress({ location: this.id }, () => task));
645650
const aligner = new Aligner(this.themeService);
646-
const checkboxStateHandler = this._register(new CheckboxStateHandler());
651+
const checkboxStateHandler = this.treeDisposables.add(new CheckboxStateHandler());
647652
const renderer = this.instantiationService.createInstance(TreeRenderer, this.id, treeMenus, this.treeLabels, actionViewItemProvider, aligner, checkboxStateHandler, () => this.manuallyManageCheckboxes);
648-
this._register(renderer.onDidChangeCheckboxState(e => this._onDidChangeCheckboxState.fire(e)));
653+
this.treeDisposables.add(renderer.onDidChangeCheckboxState(e => this._onDidChangeCheckboxState.fire(e)));
649654

650655
const widgetAriaLabel = this._title;
651656

652-
this.tree = this._register(this.instantiationService.createInstance(Tree, this.id, this.treeContainer!, new TreeViewDelegate(), [renderer],
657+
this.tree = this.treeDisposables.add(this.instantiationService.createInstance(Tree, this.id, this.treeContainer!, new TreeViewDelegate(), [renderer],
653658
dataSource, {
654659
identityProvider: new TreeViewIdentityProvider(),
655660
accessibilityProvider: {
@@ -698,6 +703,7 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
698703
dnd: this.treeViewDnd,
699704
overrideStyles: getLocationBasedViewColors(this.viewLocation).listOverrideStyles
700705
}) as WorkbenchAsyncDataTree<ITreeItem, ITreeItem, FuzzyScore>);
706+
this.treeDisposables.add(this.tree);
701707
treeMenus.setContextKeyService(this.tree.contextKeyService);
702708
aligner.tree = this.tree;
703709
const actionRunner = new MultipleSelectionActionRunner(this.notificationService, () => this.tree!.getSelection());
@@ -706,21 +712,21 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
706712
this.tree.contextKeyService.createKey<boolean>(this.id, true);
707713
const customTreeKey = RawCustomTreeViewContextKey.bindTo(this.tree.contextKeyService);
708714
customTreeKey.set(true);
709-
this._register(this.tree.onContextMenu(e => this.onContextMenu(treeMenus, e, actionRunner)));
715+
this.treeDisposables.add(this.tree.onContextMenu(e => this.onContextMenu(treeMenus, e, actionRunner)));
710716

711-
this._register(this.tree.onDidChangeSelection(e => {
717+
this.treeDisposables.add(this.tree.onDidChangeSelection(e => {
712718
this.lastSelection = e.elements;
713719
this.lastActive = this.tree?.getFocus()[0] ?? this.lastActive;
714720
this._onDidChangeSelectionAndFocus.fire({ selection: this.lastSelection, focus: this.lastActive });
715721
}));
716-
this._register(this.tree.onDidChangeFocus(e => {
722+
this.treeDisposables.add(this.tree.onDidChangeFocus(e => {
717723
if (e.elements.length && (e.elements[0] !== this.lastActive)) {
718724
this.lastActive = e.elements[0];
719725
this.lastSelection = this.tree?.getSelection() ?? this.lastSelection;
720726
this._onDidChangeSelectionAndFocus.fire({ selection: this.lastSelection, focus: this.lastActive });
721727
}
722728
}));
723-
this._register(this.tree.onDidChangeCollapseState(e => {
729+
this.treeDisposables.add(this.tree.onDidChangeCollapseState(e => {
724730
if (!e.node.element) {
725731
return;
726732
}
@@ -734,7 +740,7 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
734740
}));
735741
this.tree.setInput(this.root).then(() => this.updateContentAreas());
736742

737-
this._register(this.tree.onDidOpen(async (e) => {
743+
this.treeDisposables.add(this.tree.onDidOpen(async (e) => {
738744
if (!e.browserEvent) {
739745
return;
740746
}
@@ -760,7 +766,7 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
760766
}
761767
}));
762768

763-
this._register(treeMenus.onDidChange((changed) => {
769+
this.treeDisposables.add(treeMenus.onDidChange((changed) => {
764770
if (this.tree?.hasNode(changed)) {
765771
this.tree?.rerender(changed);
766772
}
@@ -1615,8 +1621,6 @@ class TreeMenus implements IDisposable {
16151621

16161622
export class CustomTreeView extends AbstractTreeView {
16171623

1618-
private activated: boolean = false;
1619-
16201624
constructor(
16211625
id: string,
16221626
title: string,
@@ -1670,8 +1674,6 @@ export class CustomTreeView extends AbstractTreeView {
16701674

16711675
export class TreeView extends AbstractTreeView {
16721676

1673-
private activated: boolean = false;
1674-
16751677
protected activate() {
16761678
if (!this.activated) {
16771679
this.createTree();

0 commit comments

Comments
 (0)