You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I played around with the API and here is some feedback:
overall love the simplicity of the API 👍
not restoring the UI state on restart is a very tough one for me. at the minimum I think we should restore the view expansion state and size. my scenario is a FTP explorer and always having to click it to show the contents is very annoying at times
in my case I am showing files in the same way the explorer does. I would like to reuse the same icons the explorer uses for files without me having to introduce new icons. for that, maybe the API should allow a TreeItem to have a resource URI that we then simply take as ResourceLabel and support icons with? Even more, if we had an associated resource, we could automatically open a document with that resource on click?
API: registerTreeDataProvider is not really related to the view in terms of naming, I suggest registerView (similar to registerCommand)
having a generic onDidChange on both text document provider and tree data provider is odd, because that way I cannot have my class implement both interfaces (their type is different)
suggestion: we should probably come up with a way to contribute views to a specific position in the same way I can set the location of an action when contributed into a menu. people will have the desire to put a view to the top or in between opened editors and the explorer itself
Agreed that, we need to support persisting view state. There are multiple use cases, one is what you mentioned and other is if there is a view that shows different tree based on the document opened. Then state should be stored when switching back and forth.
Good point to include resourceUri for enabling file icon themes
I see your point about registerTreeDataProvider. I think what we are using this API is to register a data provider for a view. So we can name it registerTreeDataProviderForView. View is already registered in package.json and having registerView again might be confusing
Reason to have a generic onDidChange listener is to support change on both element and root. To make it more specific and align with the provider, I can call onDidTreeDataChange.
Yes, you can contribute actions to the following locations: view/title and view/resource by giving proper when clause. Eg:
I just like the symmetry between contributing a command via package.json and having a method registerCommand
Re: onDidChange
That is fine, I am more concerned about the name clash with the text document provider. If all providers have the same event onDidChange, you cannot implement all the interfaces in one class in my extension. I suggest onDidChangeTextDocument (unfortunately we cannot change this anymore as it already is API) and onDidChangeTreeData.
Re: Positioning of views
Instead of introducing a new concept with index, why not reuse what we do for menus where you have menu item groups?
Another thing that might come up is being able to change the view label dynamically. For example for the ftp explorer I could maybe show the currently connected host in there.
I am having an idea to expose Views as an API just like other objects (editors, extensions, documents) and have some methods to control the view. This would be next step.
in my case I am showing files in the same way the explorer does [...]
I have a very similar use case - I want to implement a tree view that shows a few folders (of dependencies) outside of the current workspace. That means tree view items should otherwise behave exactly like those in the existing file explorer. They should:
have a tooltip showing the URI
have the usual context menu for rename / delete / etc
support drag and drop into editor tabs or to move them around between folders
there might be more I'm not aware of
Maybe this could be tied to the planned resourceUri?
TreeItemCollapsibleState should have a third state, ie, NotExpandable. It's confusing/unexpected that undefined carries unique semantic meaning.
This is good one. Added a new entry called None.
Expanding/collapsing a tree view node with the mouse always invokes the associated command. This is not the case with keyboard navigation (always invoking is a bit strange, since in my integration it jumps to a code location - but I suppose I'm not using the API for the intended purpose :))
You can contribute commands only to those items you want to. These commands gets called when an user selects an item. This should be true with mouse and keyboard. (Will check if it is not working with keyboard).
Commands arguments are ignored, instead, the tree node instance is passed as the first argument.
Tree commands are triggered by the platform and it only knows the node the command belongs to. Hence only the item model is passed as an argument.
It'd be really nice to reuse the standard vscode icons that are used in, ie, document outline or code completion.
Yes, there is a plan to reuse file based icons provided that item gives a file uri. Will think about the other icons too.
Is there a plan to provide virtualization support for this tree views? I would love to connect this to trees that may have 100k+ nodes or even 1million nodes under a single folder. It would be nice to be able to load more items on demand using either ranges (e.g. give me items 101 to 200) and/or using continuation tokens to get the next page when needed.
Activity
[-]Implement Tree API [/-][+]Implement contributable tree views[/+]Implement #26948
formulahendry commentedon May 21, 2017
Awesome! Look forward to this API! 😃
bpasero commentedon May 22, 2017
FTP Explorer:

I played around with the API and here is some feedback:
TreeItemto have a resourceURIthat we then simply take asResourceLabeland support icons with? Even more, if we had an associated resource, we could automatically open a document with that resource on click?registerTreeDataProvideris not really related to the view in terms of naming, I suggestregisterView(similar toregisterCommand)onDidChangeon both text document provider and tree data provider is odd, because that way I cannot have my class implement both interfaces (their type is different)sandy081 commentedon May 22, 2017
Benjamin Pasero (@bpasero) Thanks for the feedback.
Agreed that, we need to support persisting view state. There are multiple use cases, one is what you mentioned and other is if there is a view that shows different tree based on the document opened. Then state should be stored when switching back and forth.
Good point to include
resourceUrifor enabling file icon themesI see your point about
registerTreeDataProvider. I think what we are using this API is to register a data provider for a view. So we can name itregisterTreeDataProviderForView. View is already registered inpackage.jsonand havingregisterViewagain might be confusingReason to have a generic
onDidChangelistener is to support change on bothelementandroot. To make it more specific and align with the provider, I can callonDidTreeDataChange.Yes, you can contribute actions to the following locations:
view/titleandview/resourceby giving properwhenclause. Eg:indexin view contribution for the position of the view.bpasero commentedon May 22, 2017
I just like the symmetry between contributing a
commandviapackage.jsonand having a methodregisterCommandThat is fine, I am more concerned about the name clash with the text document provider. If all providers have the same event
onDidChange, you cannot implement all the interfaces in one class in my extension. I suggestonDidChangeTextDocument(unfortunately we cannot change this anymore as it already is API) andonDidChangeTreeData.Instead of introducing a new concept with
index, why not reuse what we do for menus where you have menu item groups?bpasero commentedon May 22, 2017
Another thing that might come up is being able to change the view label dynamically. For example for the ftp explorer I could maybe show the currently connected host in there.
sandy081 commentedon May 22, 2017
I am having an idea to expose Views as an API just like other objects (editors, extensions, documents) and have some methods to control the view. This would be next step.
Gama11 commentedon May 22, 2017
I have a very similar use case - I want to implement a tree view that shows a few folders (of dependencies) outside of the current workspace. That means tree view items should otherwise behave exactly like those in the existing file explorer. They should:
Maybe this could be tied to the planned
resourceUri?#26948 Remember the view collapsible state and size
sandy081 commentedon May 22, 2017
Benjamin Pasero (@bpasero) FYI Implemented remembering the view collapsible state and size.
3 remaining items
#26948 Provide none collapsible state
#26948 Update the doc for view data provider in API
#26948 Fix the TreeItemCollapsibleState ext host type
#26948 Update documentation
#26948 Update doc
#26948 document view locations in menu entry contributions
sandy081 commentedon May 30, 2017
Jacob Dufault (@jacobdufault) Thanks for the feedback
This is good one. Added a new entry called
None.You can contribute commands only to those items you want to. These commands gets called when an user selects an item. This should be true with mouse and keyboard. (Will check if it is not working with keyboard).
Tree commands are triggered by the platform and it only knows the node the command belongs to. Hence only the item model is passed as an argument.
Yes, there is a plan to reuse file based icons provided that item gives a file uri. Will think about the other icons too.
sandy081 commentedon May 30, 2017
Jacob Dufault (@jacobdufault)
Ignore my previous comment regarding this. I am mistaken. Yes this is a bug which will be fixed here #27535
alvarorahul commentedon May 30, 2017
Is there a plan to provide virtualization support for this tree views? I would love to connect this to trees that may have 100k+ nodes or even 1million nodes under a single folder. It would be nice to be able to load more items on demand using either ranges (e.g. give me items 101 to 200) and/or using continuation tokens to get the next page when needed.
sandy081 commentedon May 31, 2017
Alvaro Dias (@alvarorahul) It is paging support and mentioned in the list in the description. There are no plans as of now.
#26948 Publish tree api
sandy081 commentedon Jun 1, 2017
Closing this and further improvements will be tracked under #27823