CommandsRegistry

The CommandsRegistry class is used to register and invoke extension commands. A shared instance of the class is always available as the nova.commands environment property.

Methods

register(name, callable, [thisValue])

Registers a command with the registry, making it available for binding to command palette and menu items declared in the extension’s extension.json file.

If the command should be user-visible, the name argument should match a command declared in the extension manifest.

The callable will be invoked with a different first argument depending on the category / context in which the command is defined:

The optional thisValue argument may be used to set what this is bound to when the callable is invoked. If omitted, this will be undefined.

This method returns a Disposable that can be used to unregister the command.

invoke(name, [argument…])

Invokes the command registered for a given name, if any.

The command’s callback will be invoked as if the user had chosen it from the Extensions menu (or command palette).

The first argument the command’s callback receives will be the current Workspace. Additional arguments provided to this method will be delivered to the command after this workspace argument.

Note: For commands that appear in the editor menu, this can cause a different first object to be delivered, as those commands typically expect a TextEditor object. Commands can test the type of their first argument using the TextEditor.isTextEditor() class method.

This method returns a Promise object that resolves to the result of invoking the command. If no command is registered for the name, the promise will be rejected with an error.