commands

Namespace for dealing with commands. In short, a command is a function with a unique identifier. The function is sometimes also called command handler.

Commands can be added to the editor using the registerCommand and registerTextEditorCommand functions. Commands can be executed manually or from a UI gesture. Those are:

  • palette - Use the commands-section in package.json to make a command show in the command palette.

  • keybinding - Use the keybindings-section in package.json to enable keybindings for your extension.

Commands from other extensions and from the editor itself are accessible to an extension. However, when invoking an editor command not all argument types are supported.

This is a sample that registers a command handler and adds an entry for that command to the palette. First register a command handler with the identifier extension.sayHello.

commands.registerCommand('extension.sayHello', () => {
	window.showInformationMessage('Hello World!');
});

Second, bind the command identifier to a title under which it will show in the palette (package.json).

{
	"contributes": {
		"commands": [{
			"command": "extension.sayHello",
			"title": "Hello World"
		}]
	}
}

Online Documentation

Functions

Link copied to clipboard
fun <T : JsAny?> executeCommand(command: String, vararg rest: JsAny?): PromiseLike<T>

Executes the command denoted by the given command identifier.

Link copied to clipboard
fun getCommands(filterInternal: Boolean = definedExternally): PromiseLike<ReadonlyArray<JsString>>

Retrieve the list of all available commands. Commands starting with an underscore are treated as internal commands.

Link copied to clipboard
fun registerCommand(command: String, callback: () -> Unit, thisArg: JsAny? = definedExternally): Disposable

Registers a command that can be invoked via a keyboard shortcut, a menu item, an action, or directly.

Link copied to clipboard
fun registerTextEditorCommand(    command: String,     callback: (textEditor: TextEditor, edit: TextEditorEdit) -> Unit,     thisArg: JsAny = definedExternally): Disposable

Registers a text editor command that can be invoked via a keyboard shortcut, a menu item, an action, or directly.