Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no tree view error when view is disposed during refresh #180415

Merged
merged 1 commit into from Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/vs/workbench/api/browser/mainThreadTreeViews.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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 [];
});
}
Expand Down
18 changes: 3 additions & 15 deletions src/vs/workbench/browser/parts/views/treeView.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/vs/workbench/common/views.ts
Expand Up @@ -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 {
Expand Down