Skip to content

Commit

Permalink
Only call refresh on given elements given by plugin
Browse files Browse the repository at this point in the history
Fixes eclipse-theia#14390

Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <[email protected]>
  • Loading branch information
tsmaeder committed Jan 6, 2025
1 parent ea87531 commit d889c5a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ export interface TreeViewsMain {
$registerTreeDataProvider(treeViewId: string, options?: RegisterTreeDataProviderOptions): void;
$readDroppedFile(contentId: string): Promise<BinaryBuffer>;
$unregisterTreeDataProvider(treeViewId: string): void;
$refresh(treeViewId: string): Promise<void>;
$refresh(treeViewId: string, itemIds: string[]): Promise<void>;
$reveal(treeViewId: string, elementParentChain: string[], options: TreeViewRevealOptions): Promise<any>;
$setMessage(treeViewId: string, message: string): void;
$setTitle(treeViewId: string, title: string): void;
Expand Down
12 changes: 12 additions & 0 deletions packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,18 @@ export class PluginTreeModel extends TreeModelImpl {

@injectable()
export class TreeViewWidget extends TreeViewWelcomeWidget {
async refresh(items: string[] | undefined): Promise<void> {
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;

Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-ext/src/main/browser/view/tree-views-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ export class TreeViewsMainImpl implements TreeViewsMain, Disposable {
return BinaryBuffer.wrap(new Uint8Array(buffer));
}

async $refresh(treeViewId: string): Promise<void> {
async $refresh(treeViewId: string, items: string[]): Promise<void> {
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);
}
}

Expand Down
18 changes: 15 additions & 3 deletions packages/plugin-ext/src/plugin/tree/tree-views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,20 @@ class TreeViewExtImpl<T> 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);
});
}

Expand Down Expand Up @@ -378,7 +390,7 @@ class TreeViewExtImpl<T> 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
Expand Down

0 comments on commit d889c5a

Please sign in to comment.