-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
base: master
Are you sure you want to change the base?
Conversation
Fixes eclipse-theia#14390 Contributed on behalf of STMicroelectronics Signed-off-by: Thomas Mäder <[email protected]>
There was a problem hiding this 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> { |
There was a problem hiding this comment.
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)
.
async refresh(items: string[] | undefined): Promise<void> { | |
async refresh(items?: string[]): Promise<void> { |
for (const element of elements) { | ||
for (const node of this.nodes.values()) { | ||
if (node.value === element) { | ||
ids.push(node.id); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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)
.
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); | |
} | |
} |
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 theTreeItem
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
Attribution
Contributed on behalf of STMicroelectronics
Review checklist
Reminder for reviewers