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

Add optional id property to the tree item #41413

Merged
merged 4 commits into from
Jan 16, 2018
Merged

Add optional id property to the tree item #41413

merged 4 commits into from
Jan 16, 2018

Conversation

sandy081
Copy link
Member

Tree view associates the tree node state (expansion & selection) to the handle provided by the Tree item providers. Some of the tree view providers uses TreeItem as handle and they do not store it. They always create new TreeItems when asked for the children handles. State is not persisted for such trees as the handle changes always.

As we already maintain the map of handles, allowing to provide an optional id in TreeItem will be useful to persist the state even if new handle is created for the TreeItem with same id.

@sandy081 sandy081 requested a review from jrieken January 10, 2018 17:46
@sandy081 sandy081 self-assigned this Jan 10, 2018
@sandy081 sandy081 added this to the January 2018 milestone Jan 10, 2018
@jrieken
Copy link
Member

jrieken commented Jan 11, 2018

They always create new TreeItems when asked for the children handles

The new TreeItems, will they be different as such that they have a different label, icon etc? Could you not just compare them on the properties we have defined (and we will use to render) and use that as 'synthetic' id?

@jrieken jrieken added api under-discussion Issue is under discussion for relevance, priority, approach tree-widget Tree widget issues labels Jan 11, 2018
@eamodio
Copy link
Contributor

eamodio commented Jan 11, 2018

In GitLens for example, the vast majority of my TreeItem's are regenerated on refresh and will have the same properties (label, icon, etc), but there are some that are regenerated that will have the label changed (e.g. the label has a count in it). GitLens also can have duplicate (identical properties) TreeItems in the lists (as commits can be in multiple branches, etc) so parenting should be taken into account.

I liked the behavior of the synthetic id, that was based on something like parent and label for the vast majority of my TreeItems, but then to have the option be able to set an id property merely as a replacement for the label (in the synthetic computation) , for the items where the label is know to be unstable.

@sandy081
Copy link
Member Author

sandy081 commented Jan 12, 2018

Thanks @eamodio for chiming in.

@jrieken I am already generating an artificial id from the parent's id and item's label. I am using the incremental counter for duplicated labels. As @eamodio mentioned, if there are changing labels for the same item, there is a need for identity that is defined by the extensions.

This was discussed in the issue #40018 and we ended upon following strategy:

If TreeItem provides id, then this will be used as id which has to be unique for the complete tree. Otherwise, a unique id will be generated from its parent id and its label.

@jrieken
Copy link
Member

jrieken commented Jan 12, 2018

this will be used as id which has to be unique for the complete tree.

And that's massive pita if you ask me. Our internal tree widget has that constraint and error telemetry is usually full of duplicate id errors... Anyways, I see the need for this. 🚢 it

@@ -4967,6 +4967,11 @@ declare module 'vscode' {
*/
label: string;

/**
* Optional id for the tree item.
Copy link
Member

@jrieken jrieken Jan 12, 2018

Choose a reason for hiding this comment

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

This needs a lot more documentation which explains what the id is and what it is used for, why it's optional etc. I'd say much of this: #40018 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added more doc to the id attribute explaining why it is used and the default behaviour.

@sandy081
Copy link
Member Author

Added more doc to the id attribute explaining why it is used and the default behaviour.

*
* This is used by the view to preserve the selection and expansion state of the tree item.
*
* *Note:* With generated id, tree item's view state will be reset when label is changed.
Copy link
Member

Choose a reason for hiding this comment

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

Not sure what that mean? With a re-generated id state will reset?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, if the label has changed, new id (different from old) is generated and as a result previous state is lost.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, how about merging that with sentence about how an id will be generated.

Optional id for the tree item that has to be unique across tree. The id is used to preserve the selection and expansion state of the tree item.

If not provided, an id is generated using the tree item's label. **Note** that when labels change, ids will change and that selection and expansion state cannot be kept stable anymore. 

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks better. Updated.

@sandy081 sandy081 merged commit dc13183 into master Jan 16, 2018
@sandy081 sandy081 deleted the sandy081/40018 branch January 16, 2018 16:06
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api tree-widget Tree widget issues under-discussion Issue is under discussion for relevance, priority, approach
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants