• Public
  • Public/Protected
  • All

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 using the registerCommand and registerTextEditorCommand functions. Registration can be split in two step: first register command without handler, second register handler by command id.

Any contributed command are available to any plugin, command can be invoked by executeCommand function.

Simple example that register command:

theia.commands.registerCommand({id:'say.hello.command'}, ()=>{
    console.log("Hello World!");

Simple example that invoke command:





  • executeCommand<T>(commandId: string, ...args: any[]): PromiseLike<T | undefined>
  • Execute the active handler for the given command and arguments.

    Reject if a command cannot be executed.

    Type parameters

    • T


    • commandId: string
    • Rest ...args: any[]

    Returns PromiseLike<T | undefined>


  • getCommands(filterInternal?: undefined | false | true): PromiseLike<string[]>
  • Retrieve the list of all available commands. Commands starting an underscore are treated as internal commands.


    • Optional filterInternal: undefined | false | true

      Set true to not see internal commands (starting with an underscore)

    Returns PromiseLike<string[]>

    Thenable that resolves to a list of command ids.



  • registerHandler(commandId: string, handler: function, thisArg?: any): Disposable
  • Register the given handler for the given command identifier.


    • commandId: string

      a given command id

    • handler: function

      a command handler

      Throw if a handler for the given command identifier is already registered.

        • (...args: any[]): any
        • Parameters

          • Rest ...args: any[]

          Returns any

    • Optional thisArg: any

    Returns Disposable


  • registerTextEditorCommand(command: string, callback: function, thisArg?: any): Disposable
  • Registers a text editor command that can be invoked via a keyboard shortcut, a menu item, an action, or directly.

    Text editor commands are different from ordinary commands as they only execute when there is an active editor when the command is called. Also, the command handler of an editor command has access to the active editor and to an edit-builder.


    • command: string

      A unique identifier for the command.

    • callback: function

      A command handler function with access to an editor and an edit.

    • Optional thisArg: any

      The this context used when invoking the handler function.

    Returns Disposable

    Disposable which unregisters this command on disposal.