diff --git a/packages/plugin-ext/src/common/plugin-api-rpc.ts b/packages/plugin-ext/src/common/plugin-api-rpc.ts index 8a549b7e4f840..026ad4d5e05d3 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc.ts @@ -822,7 +822,7 @@ export interface TreeViewsMain { $registerTreeDataProvider(treeViewId: string, options?: RegisterTreeDataProviderOptions): void; $readDroppedFile(contentId: string): Promise; $unregisterTreeDataProvider(treeViewId: string): void; - $refresh(treeViewId: string): Promise; + $refresh(treeViewId: string, itemIds: string[]): Promise; $reveal(treeViewId: string, elementParentChain: string[], options: TreeViewRevealOptions): Promise; $setMessage(treeViewId: string, message: string): void; $setTitle(treeViewId: string, title: string): void; diff --git a/packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx b/packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx index ad09bf104ba6f..6593bc9711c87 100644 --- a/packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx +++ b/packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx @@ -428,6 +428,18 @@ export class PluginTreeModel extends TreeModelImpl { @injectable() export class TreeViewWidget extends TreeViewWelcomeWidget { + async refresh(items: string[] | undefined): Promise { + if (items) { + for (const id of items) { + const node = this.model.getNode(id); + if (CompositeTreeNode.is(node)) { + await this.model.refresh(node); + } + }; + } else { + this.model.refresh(); + } + } protected _contextSelection = false; diff --git a/packages/plugin-ext/src/main/browser/view/tree-views-main.ts b/packages/plugin-ext/src/main/browser/view/tree-views-main.ts index 4d875798d5c09..74993d2c14cfe 100644 --- a/packages/plugin-ext/src/main/browser/view/tree-views-main.ts +++ b/packages/plugin-ext/src/main/browser/view/tree-views-main.ts @@ -110,11 +110,11 @@ export class TreeViewsMainImpl implements TreeViewsMain, Disposable { return BinaryBuffer.wrap(new Uint8Array(buffer)); } - async $refresh(treeViewId: string): Promise { + async $refresh(treeViewId: string, items: string[]): Promise { const viewPanel = await this.viewRegistry.getView(treeViewId); const widget = viewPanel && viewPanel.widgets[0]; if (widget instanceof TreeViewWidget) { - await widget.model.refresh(); + await widget.refresh(items); } } diff --git a/packages/plugin-ext/src/plugin/tree/tree-views.ts b/packages/plugin-ext/src/plugin/tree/tree-views.ts index 5dec3ca816fdd..3213cf1c47504 100644 --- a/packages/plugin-ext/src/plugin/tree/tree-views.ts +++ b/packages/plugin-ext/src/plugin/tree/tree-views.ts @@ -252,8 +252,20 @@ class TreeViewExtImpl implements Disposable { dragMimeTypes, dropMimeTypes }); this.toDispose.push(Disposable.create(() => this.proxy.$unregisterTreeDataProvider(treeViewId))); - options.treeDataProvider.onDidChangeTreeData?.(() => { - this.pendingRefresh = proxy.$refresh(treeViewId); + options.treeDataProvider.onDidChangeTreeData?.(elements => { + const ids = []; + elements = elements || []; + if (!Array.isArray(elements)) { + elements = [elements]; + } + for (const element of elements) { + for (const node of this.nodes.values()) { + if (node.value === element) { + ids.push(node.id); + } + } + } + this.pendingRefresh = proxy.$refresh(treeViewId, ids); }); } @@ -378,7 +390,7 @@ class TreeViewExtImpl implements Disposable { let counter = 0; do { id = `${prefix}/${counter}:${elementId}`; - if (!mustReturnNew || !this.nodes.has(id) || this.nodes.get(id) === item) { + if (!mustReturnNew || !this.nodes.has(id) || this.nodes.get(id)?.pluginTreeItem === item) { // Return first if asked for or // Return if handle does not exist or // Return if handle is being reused