I would like to run a command on the click of a tree view item, rather than in a menu that comes up. Right now in my package.json, I have this:
{
"command": "test.view.showError",
"when": "view == test.view && viewItem == test",
"group": "inline"
}
Right now, "inline" will put an icon next to the words which you have to click to run the command, but I would like the command to run when I click on the node itself.
What do I change "group" to? Or do I do something different entirely?
Thanks
You have to set the command
property on the TreeItem
instance.
command?: Command
The command that should be executed when the tree item is selected.
https://code.visualstudio.com/docs/extensionAPI/vscode-api#TreeItem
Pass a vscode.Command
object to your TreeItem
like in the snippet below. Make sure you have defined your command in package.json
and extension.ts
.
class TreeItem extends vscode.TreeItem {
command = {
"title": "Show error",
"command": "test.view.showError",
}
constructor(label: string) {
super(label);
}
}
Here's the complete type definition for vscode.Command
:
/**
* Represents a reference to a command. Provides a title which
* will be used to represent a command in the UI and, optionally,
* an array of arguments which will be passed to the command handler
* function when invoked.
*/
export interface Command {
/**
* Title of the command, like `save`.
*/
title: string;
/**
* The identifier of the actual command handler.
* @see [commands.registerCommand](#commands.registerCommand).
*/
command: string;
/**
* A tooltip for the command, when represented in the UI.
*/
tooltip?: string;
/**
* Arguments that the command handler should be
* invoked with.
*/
arguments?: any[];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With