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

Only call refresh on given elements given by plugin #14697

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tsmaeder
Copy link
Contributor

@tsmaeder tsmaeder commented Jan 6, 2025

What it does

In the scenario from the issue, the extensions calls onDidChangeTreeData?: [Event]<void | T | T[]> on some elements. However, Theia disregards the elements to be refreshed and always refreshes from the root. Since the TreeItem instances furnished by the extensions seem to be new each time, we cannot associate the refreshed items with cached tree nodes and therefore we lose the expansion state: for us, it looks like we have a completely new tree that starts out collapsed.
This PR implements the refresh of only a given elemement. This prevents the refresh from the root and thus fixes the problem.

Fixes #14390

How to test

Make sure other contributed views still work the same as before, for example views from gitlens, reference, etc.

Follow-ups

Breaking changes

  • This PR introduces breaking changes and requires careful review. If yes, the breaking changes section in the changelog has been updated.

Attribution

Contributed on behalf of STMicroelectronics

Review checklist

Reminder for reviewers

Fixes eclipse-theia#14390

Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <[email protected]>
@tsmaeder tsmaeder requested a review from rschnekenbu January 6, 2025 14:28
@msujew
Copy link
Member

msujew commented Jan 6, 2025

@tsmaeder Does this also fix #13946?

Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I've tried it out with the maven plugin, and everything seems to work perfectly. No regressions as far as I could tell as well.

@@ -428,6 +428,18 @@ export class PluginTreeModel extends TreeModelImpl {

@injectable()
export class TreeViewWidget extends TreeViewWelcomeWidget {
async refresh(items: string[] | undefined): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: It might make more sense to use ? here, as I would much rather call tree.refresh() than tree.refresh(undefined).

Suggested change
async refresh(items: string[] | undefined): Promise<void> {
async refresh(items?: string[]): Promise<void> {

Comment on lines +261 to +267
for (const element of elements) {
for (const node of this.nodes.values()) {
if (node.value === element) {
ids.push(node.id);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: I'm not sure how bad this can get in reality, but this is O(n * m) behavior. We can cut this down to O(n + m).

Suggested change
for (const element of elements) {
for (const node of this.nodes.values()) {
if (node.value === element) {
ids.push(node.id);
}
}
}
const set = new Set<T>();
for (const element of elements) {
set.add(element);
}
for (const node of this.nodes.values()) {
if (set.has(node.value)) {
ids.push(node.id);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs merge
Development

Successfully merging this pull request may close these issues.

In TheiaIDE the "Plugins" items are not unwrap in a multi-module MAVEN JAVA project
2 participants