Skip to content

Commit d889c5a

Browse files
committed
Only call refresh on given elements given by plugin
Fixes eclipse-theia#14390 Contributed on behalf of STMicroelectronics Signed-off-by: Thomas Mäder <[email protected]>
1 parent ea87531 commit d889c5a

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

packages/plugin-ext/src/common/plugin-api-rpc.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ export interface TreeViewsMain {
814814
$registerTreeDataProvider(treeViewId: string, options?: RegisterTreeDataProviderOptions): void;
815815
$readDroppedFile(contentId: string): Promise<BinaryBuffer>;
816816
$unregisterTreeDataProvider(treeViewId: string): void;
817-
$refresh(treeViewId: string): Promise<void>;
817+
$refresh(treeViewId: string, itemIds: string[]): Promise<void>;
818818
$reveal(treeViewId: string, elementParentChain: string[], options: TreeViewRevealOptions): Promise<any>;
819819
$setMessage(treeViewId: string, message: string): void;
820820
$setTitle(treeViewId: string, title: string): void;

packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,18 @@ export class PluginTreeModel extends TreeModelImpl {
428428

429429
@injectable()
430430
export class TreeViewWidget extends TreeViewWelcomeWidget {
431+
async refresh(items: string[] | undefined): Promise<void> {
432+
if (items) {
433+
for (const id of items) {
434+
const node = this.model.getNode(id);
435+
if (CompositeTreeNode.is(node)) {
436+
await this.model.refresh(node);
437+
}
438+
};
439+
} else {
440+
this.model.refresh();
441+
}
442+
}
431443

432444
protected _contextSelection = false;
433445

packages/plugin-ext/src/main/browser/view/tree-views-main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ export class TreeViewsMainImpl implements TreeViewsMain, Disposable {
110110
return BinaryBuffer.wrap(new Uint8Array(buffer));
111111
}
112112

113-
async $refresh(treeViewId: string): Promise<void> {
113+
async $refresh(treeViewId: string, items: string[]): Promise<void> {
114114
const viewPanel = await this.viewRegistry.getView(treeViewId);
115115
const widget = viewPanel && viewPanel.widgets[0];
116116
if (widget instanceof TreeViewWidget) {
117-
await widget.model.refresh();
117+
await widget.refresh(items);
118118
}
119119
}
120120

packages/plugin-ext/src/plugin/tree/tree-views.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,20 @@ class TreeViewExtImpl<T> implements Disposable {
252252
dragMimeTypes, dropMimeTypes
253253
});
254254
this.toDispose.push(Disposable.create(() => this.proxy.$unregisterTreeDataProvider(treeViewId)));
255-
options.treeDataProvider.onDidChangeTreeData?.(() => {
256-
this.pendingRefresh = proxy.$refresh(treeViewId);
255+
options.treeDataProvider.onDidChangeTreeData?.(elements => {
256+
const ids = [];
257+
elements = elements || [];
258+
if (!Array.isArray(elements)) {
259+
elements = [elements];
260+
}
261+
for (const element of elements) {
262+
for (const node of this.nodes.values()) {
263+
if (node.value === element) {
264+
ids.push(node.id);
265+
}
266+
}
267+
}
268+
this.pendingRefresh = proxy.$refresh(treeViewId, ids);
257269
});
258270
}
259271

@@ -378,7 +390,7 @@ class TreeViewExtImpl<T> implements Disposable {
378390
let counter = 0;
379391
do {
380392
id = `${prefix}/${counter}:${elementId}`;
381-
if (!mustReturnNew || !this.nodes.has(id) || this.nodes.get(id) === item) {
393+
if (!mustReturnNew || !this.nodes.has(id) || this.nodes.get(id)?.pluginTreeItem === item) {
382394
// Return first if asked for or
383395
// Return if handle does not exist or
384396
// Return if handle is being reused

0 commit comments

Comments
 (0)