Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode extension TreeView set selected

I have created a TreeDataProvider and populated it with TreeItem s. I would like to be able to set the TreeItem that is selected based on the current editor window, like happens in the Explorer/Open Editors view.

I have looked through the API but cannot find any way to do this.

like image 819
Andrew McCormick-Smith Avatar asked Dec 12 '17 14:12

Andrew McCormick-Smith


People also ask

What is Uri VS Code?

@:jsRequire("vscode","Uri") A universal resource identifier representing either a file on disk or another resource, like untitled resources.

How do you open code in VS Code?

VS Code provides two powerful commands to navigate in and across files with easy-to-use key bindings. Hold Ctrl and press Tab to view a list of all files open in an editor group. To open one of these files, use Tab again to pick the file you want to navigate to, then release Ctrl to open it.


1 Answers

You can use the reveal() API that was added in VSCode 1.21.0 (February 2018) for this.

This requires you to first obtain a TreeView instance using createTreeView():

const treeView = vscode.window.createTreeView("viewId", {treeDataProvider: provider});
treeView.reveal(item, {select: true});
like image 93
Gama11 Avatar answered Oct 19 '22 23:10

Gama11