-
Notifications
You must be signed in to change notification settings - Fork 9
Commands
To enhance your editor, you can register custom commands, which can be used from anywhere in the editor, by using the API, e.g.
Create a commands
section to the settings.json
file in the .vscode
sub folder of your workspace and add one or more entry:
{
"ego.power-tools": {
"commands": {
"myCommand": {
"script": "my_command.js",
"button": {
"text": "Click here to start the command."
}
}
}
}
}
For that example, create a my_command.js
file in your .vscode
folder and use the following skeleton:
exports.execute = async (args) => {
// args => https://egomobile.github.io/vscode-powertools/api/interfaces/contracts.workspacecommandscriptarguments.html
// s. https://code.visualstudio.com/api/references/vscode-api
const vscode = args.require('vscode');
vscode.window.showInformationMessage(
`Hello, from '${ args.command }'!`
);
};
Name | Description | Required? |
---|---|---|
button |
Defines an optional button, which executes the command. | no |
description 1
|
A description for the command. | no |
forFile |
Indicates if that command can be executed for a current or selected file or not (s. File explorer and context menus). Default: (false)
|
no |
forFolder |
Indicates if that command can be executed for a current or selected folder or not (s. File explorer and context menus). Default: (false)
|
no |
if |
(JavaScript) Code that checks if command is available or not. s. Conditional Settings | no |
ifFile |
The regular expression, that checks if that button should be visible for an active editor or not. Path separators will always be converted to / , even in Windows. |
no |
importValues |
Defines a list of properties, which uses (external) values for itself. s. Import Settings | no |
name 1 2
|
The (display) name for the GUI. | no |
onCreated |
The (JavaScript) code to executed after command has been created. s. Executable Settings | no |
onDestroyed |
The (JavaScript) code to executed after command has been destroyed. s. Executable Settings | no |
options |
Options for the script. | no |
platforms |
A list of one or more platform IDs, where the button should be available on. s. process.platform | no |
script 1
|
The path to the script that should be invoked. Relative paths will be mapped to the .vscode sub folder of the workspace or the .vscode-powertools sub folder inside the current user's home directory. |
yes |
1 supports placeholders
2 supports icons
Name | Description | Required? |
---|---|---|
color 1
|
The RGB text color. | no |
isRight |
Display button one the right side or not. Default: (false)
|
no |
onEditorChanged |
The (JavaScript) code to executed after active editor has changed. s. Executable Settings | no |
priority |
A (numeric) value that defines the priority, the button should be displayed with. | no |
text 1 2
|
The (display) text. | no |
tooltip 1
|
The tooltip text. | no |
1 supports placeholders
2 supports icons
If you want to make one or more commands available in an active editor, the file explorer or a context menu of an editor, set forFile
and/or forFolder
to (true)
.
Choose Execute Power Command
(or Power Tools: Execute Power Command
from command palette) to execute a command.
For example, add the following entry to your settings.json
inside your workspace's sub folder .vscode
:
{
"ego.power-tools": {
"commands": {
"myCommand": {
"script": "my_command.js",
"forFile": true,
"forFolder": true
}
}
}
}
Then create a my_command.js
file in the same directory and use the following skeleton:
exports.execute = async (args) => {
// args => (if file) https://egomobile.github.io/vscode-powertools/api/interfaces/_contracts_.workspacecommandscriptargumentsforfiles.html
// (if folder) https://egomobile.github.io/vscode-powertools/api/interfaces/_contracts_.workspacecommandscriptargumentsforfolders.html
// https://code.visualstudio.com/api/references/vscode-api
const vscode = args.require('vscode');
if (args.file) {
// file => vscode.Uri
vscode.window.showInformationMessage(
`File: '${ args.file }'`
);
} else if (args.folder) {
// folder => vscode.Uri
vscode.window.showInformationMessage(
`Folder: '${ args.folder }'`
);
}
};
licensed under GDFL 1.3 - © Next.e.GO Mobile SE