diff --git a/src/vs/workbench/api/browser/mainThreadTreeViews.ts b/src/vs/workbench/api/browser/mainThreadTreeViews.ts index b8e15a8daad6a..c450a1d69af04 100644 --- a/src/vs/workbench/api/browser/mainThreadTreeViews.ts +++ b/src/vs/workbench/api/browser/mainThreadTreeViews.ts @@ -5,7 +5,7 @@ import { Disposable } from 'vs/base/common/lifecycle'; import { ExtHostContext, MainThreadTreeViewsShape, ExtHostTreeViewsShape, MainContext, CheckboxUpdate } from 'vs/workbench/api/common/extHost.protocol'; -import { ITreeViewDataProvider, ITreeItem, IViewsService, ITreeView, IViewsRegistry, ITreeViewDescriptor, IRevealOptions, Extensions, ResolvableTreeItem, ITreeViewDragAndDropController, IViewBadge } from 'vs/workbench/common/views'; +import { ITreeViewDataProvider, ITreeItem, IViewsService, ITreeView, IViewsRegistry, ITreeViewDescriptor, IRevealOptions, Extensions, ResolvableTreeItem, ITreeViewDragAndDropController, IViewBadge, NoTreeViewError } from 'vs/workbench/common/views'; import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers'; import { distinct } from 'vs/base/common/arrays'; import { INotificationService } from 'vs/platform/notification/common/notification'; @@ -266,7 +266,11 @@ class TreeViewDataProvider implements ITreeViewDataProvider { .then( children => this.postGetChildren(children), err => { - this.notificationService.error(err); + // It can happen that a tree view is disposed right as `getChildren` is called. This results in an error because the data provider gets removed. + // The tree will shortly get cleaned up in this case. We just need to handle the error here. + if (!NoTreeViewError.is(err)) { + this.notificationService.error(err); + } return []; }); } diff --git a/src/vs/workbench/browser/parts/views/treeView.ts b/src/vs/workbench/browser/parts/views/treeView.ts index a6c14ebbbda5c..f7f9dae4a15f4 100644 --- a/src/vs/workbench/browser/parts/views/treeView.ts +++ b/src/vs/workbench/browser/parts/views/treeView.ts @@ -59,7 +59,7 @@ import { API_OPEN_DIFF_EDITOR_COMMAND_ID, API_OPEN_EDITOR_COMMAND_ID } from 'vs/ import { IViewPaneOptions, ViewPane } from 'vs/workbench/browser/parts/views/viewPane'; import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewlet'; import { PANEL_BACKGROUND, SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme'; -import { Extensions, ITreeItem, ITreeItemLabel, ITreeView, ITreeViewDataProvider, ITreeViewDescriptor, ITreeViewDragAndDropController, IViewBadge, IViewDescriptorService, IViewsRegistry, NoTreeViewError, ResolvableTreeItem, TreeCommand, TreeItemCollapsibleState, TreeViewItemHandleArg, TreeViewPaneHandleArg, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views'; +import { Extensions, ITreeItem, ITreeItemLabel, ITreeView, ITreeViewDataProvider, ITreeViewDescriptor, ITreeViewDragAndDropController, IViewBadge, IViewDescriptorService, IViewsRegistry, ResolvableTreeItem, TreeCommand, TreeItemCollapsibleState, TreeViewItemHandleArg, TreeViewPaneHandleArg, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views'; import { IActivityService, NumberBadge } from 'vs/workbench/services/activity/common/activity'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; import { IHoverService } from 'vs/workbench/services/hover/browser/hover'; @@ -346,20 +346,8 @@ abstract class AbstractTreeView extends Disposable implements ITreeView { children = node.children; } else { node = node ?? self.root; - try { - node.children = await (node instanceof Root ? dataProvider.getChildren() : dataProvider.getChildren(node)); - children = node.children ?? []; - } catch (e) { - if (e instanceof NoTreeViewError) { - // It can happen that a tree view is hidden right as `getChildren` is called. This results in an error because the data provider gets removed. - // The tree will shortly get cleaned up in this case. We just need to handle the error here. - node.children = []; - children = []; - return children; - } else { - throw e; - } - } + node.children = await (node instanceof Root ? dataProvider.getChildren() : dataProvider.getChildren(node)); + children = node.children ?? []; } if (node instanceof Root) { const oldEmpty = this._isEmpty; diff --git a/src/vs/workbench/common/views.ts b/src/vs/workbench/common/views.ts index e1da743d1a3c1..46b1315470a4c 100644 --- a/src/vs/workbench/common/views.ts +++ b/src/vs/workbench/common/views.ts @@ -851,9 +851,13 @@ export class ResolvableTreeItem implements ITreeItem { } export class NoTreeViewError extends Error { + override readonly name = 'NoTreeViewError'; constructor(treeViewId: string) { super(localize('treeView.notRegistered', 'No tree view with id \'{0}\' registered.', treeViewId)); } + static is(err: Error): err is NoTreeViewError { + return err.name === 'NoTreeViewError'; + } } export interface ITreeViewDataProvider {