Executable Settings - egomobile/vscode-powertools GitHub Wiki
Settings, like if, execute JavaScript code, the time, when they are handled.
The following example, runs a npm install
on startup, only if node_modules
folder does not exist.
{
"ego.power-tools": {
"startup": [
{
"command": "npm install",
"if": " !$fs.existsSync( $v['workspaceRoot'] + '/node_modules' ) "
}
]
}
}
Keep in mind: Any code needs to be executed synchronously and does NOT support async patterns, like Promises!
onCreated and onDestroyed
For settings like apps, buttons, commands, events and jobs, you can define the onCreated
and/or onDestroyed
settings, which execute code, after an item has been created or destroyed:
{
"ego.power-tools": {
"buttons": [
{
"text": "Button 1",
"action": {
"type": "script",
"script": "mybutton.js"
},
"if": " !$s['mybutton'] ",
"onCreated": " $s['mybutton'] = true ",
"onDestroyed": " delete $s['mybutton'] "
},
{
"text": "Button 2 (will not be created)",
"action": {
"type": "script",
"script": "mybutton.js"
},
"if": " !$s['mybutton'] ",
"onCreated": " $s['mybutton'] = true ",
"onDestroyed": " delete $s['mybutton'] "
}
]
}
}
onEditorChanged
The (JavaScript) code to executed after active editor has changed.
That event is available for buttons and command buttons.
{
"ego.power-tools": {
"buttons": [
{
"text": "Button: ${activeFile}",
"action": {
"type": "script",
"script": "mybutton.js"
},
"onEditorChanged": " $v['button'].update() "
}
]
}
}
The event provides an additional value, called button
, which can be accessed via $v and implements the CodeButton interface.
Documentation
Constants
$s
The current session storage, which is available while the extension is running.
$v
All available values as key/value pair.
!$fs.existsSync( $v['workspaceRoot'] + '/node_modules' )
Functions
$r( moduleId )
Can (also) access any module of that extension.
$r('moment')().format('YYYY-MM-DD') === '1979-09-05'
Modules
Name | Description |
---|---|
_ |
lodash |
$fs |
fs-extra |
$h |
vscode-helpers |
$m |
Moment.js with timezone support |
$p |
Node.js path module |
$vs |
Visual Studio Code API |