How can I add decorations beside my TreeItem
s like how it is done with the built-in git tracker with the M
symbol here?:

How can I add decorations beside my TreeItem
s like how it is done with the built-in git tracker with the M
symbol here?:
This can be done through the use of inline
view actions. Tree View View Actions VSCode Docs Link
An example of how to do this:
package.json
{
...,
commands: {
{
"command": "myCommand",
"title": "Command title",
"icon": "images/some-icon.svg" // this is in the root of your extension project
}
},
menus: {
"view/item/context": [
{
"command": "myCommand",
"when": "viewItem == myTreeItemContextValue", // Make sure to sync this value on each TreeItem to fulfill the "when" check
"group": "inline"
}
]
}
}
Your TreeItem
definition
export class MyTreeItem extends TreeItem {
constructor(
public readonly name: string,
public readonly collapsibleState: TreeItemCollapsibleState,
public readonly contextValue: string = 'myTreeItemContextValue'
) {
super(name, collapsibleState);
}
}
From what I know this is currently not possible. There's no public API for that.
If I understand correctly from reading this, you can use FileDecorationProvider
and implement provideFileDecoration(uri: Uri, token: CancellationToken): ProviderResult<FileDecoration>
to provide decorations for TreeItem
s based on their resourceUri
properties. For example, you can take a look at how the builtin Git extension does it for repositories in VS Code 1.80.