Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

commands

Marcel Kloubert edited this page Feb 13, 2018 · 7 revisions

Home >> Settings >> Commands

Commands

Defines one or more commands that should be available in VS Code.

The following example will register the commands mkloubert.mycommand and mkloubert.mycommand2.

{
    "deploy.reloaded": {
        "commands": {
            "mkloubert.mycommand": {
                "script": "./my-command-script.js",
                "options": {
                    "MK": 23979,
                    "TM": "5979"
                },

                "button": {
                    "text": "My command",
                    "tooltip": "An optional button for the command"
                }
            },

            "mkloubert.mycommand2": "E:/test/my-command-script2.js"
        }
    }
}
Name Description
button Settings for optional button in the status bar.
cache Cache script or not. Default: (false)
noFirstArgument Do not submit a ScriptCommandExecutionContext object as first argument. Default (false)
options Optional data for the execution.
script* The path of the script that is executed when command is invoked. If you use a relative path, the path will be mapped to an existing file inside the .vscode or current user's home directory (.vscode-deploy-reloaded sub folder).
show Show button on startup or not. Default: (true)

* supports placeholders

button

Name Description
color* The custom (text) color for the button. Default #ffffff
enabled Enable button or not. Default (true)
isRight Set button on the right side or not. Default (false)
priority The custom priority.
show Show button on startup or not. Default (true)
text* The caption for the button.
tooltip* The tooltip for the button.

* supports placeholders

Example

exports.execute = async function(context) {
    // s. https://code.visualstudio.com/Docs/extensionAPI/vscode-api
    var vscode = context.require('vscode');

    vscode.window.showInformationMessage('Hello, TM: ' + context.options.TM);
    vscode.window.showInformationMessage('Hello, MK: ' + context.options.MK);

    // this property can be used to store
    // data for this command only
    // 
    // this data will be available at the next execution(s)
    // while the current session
    context.state = 22121986;

    // this property can be used to store
    // data for this command and all the others commands
    // registrated by that extension
    // 
    // this data will be available at the next execution(s)
    // while the current session
    // 
    // HINT: the 'globalState' itself cannot be changed, but its properties!
    context.globalState.mycommand = 171081; 

    return 666;
}

The context parameter implements the ScriptCommandExecutionContext interface.

Clone this wiki locally