-
Notifications
You must be signed in to change notification settings - Fork 29.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
Add optional id property to the tree item #41413
Conversation
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? |
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 |
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 |
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 |
src/vs/vscode.d.ts
Outdated
@@ -4967,6 +4967,11 @@ declare module 'vscode' { | |||
*/ | |||
label: string; | |||
|
|||
/** | |||
* Optional id for the tree item. |
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.
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)
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.
Added more doc to the id
attribute explaining why it is used and the default behaviour.
Added more doc to the id attribute explaining why it is used and the default behaviour. |
src/vs/vscode.d.ts
Outdated
* | ||
* 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. |
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.
Not sure what that mean? With a re-generated id state will reset?
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.
Yes, if the label has changed, new id
(different from old) is generated and as a result previous state is lost.
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.
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.
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 better. Updated.
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
inTreeItem
will be useful to persist the state even if new handle is created for the TreeItem with same id.