Skip to main content
API module

commands API

All 5 public APIs exported from the commands module, with declarations, documentation, and source-backed examples.

Generated from typings/index.d.ts @ 555f5ceon

commands

commands.commandList

Registered commands.

Source

API signature

commands.commandList: CommandItem[]
Returns
CommandItem[]
Declaration
typings/index.d.ts:7982
commands

commands.execute

Execute specified command.

Deprecated use executeCommand() instead.
Source

API signature

commands.execute(command: { name: string, arguments?: any[] }): void

Parameters

ParameterType
command{ name: string, arguments?: any[] }
Returns
void
Declaration
typings/index.d.ts:7989
commands

commands.has

Check if command is registered.

Source

API signature

commands.has(id: string): boolean

Parameters

ParameterTypeDescription
idstring

Unique id of command.

Returns
boolean
Declaration
typings/index.d.ts:7996
commands

commands.registerCommand

Registers a command callable via :CocCommand <id> or programmatically.

Source

API signature

commands.registerCommand(id: string, impl: (...args: any[]) => void, thisArg?: any, internal?: boolean): Disposable

Example

import { commands, window, ExtensionContext } from 'coc.nvim';

export function activate(context: ExtensionContext) {
  context.subscriptions.push(
    commands.registerCommand('myextension.sayHello', async () => {
      window.showInformationMessage('Hello from coc.nvim extension!');
    })
  );
}

Parameters

ParameterTypeDescription
idstring

A unique identifier for the command.

impl(...args: any[]) => void

A command handler function.

thisArg?any

The this context used when invoking the handler function.

internal?boolean
Returns
Disposable

Disposable which unregisters this command on disposal.

Declaration
typings/index.d.ts:8010
commands

commands.executeCommand

Executes the command denoted by the given command identifier.

  • Note 1: When executing an editor command not all types are allowed to be passed as arguments. Allowed are the primitive types string, boolean, number, undefined, and null, as well as Position, Range, URI and Location.
  • Note 2: There are no restrictions when executing commands that have been contributed by extensions.
Source

Overloads (15)

  1. Signature 1
    commands.executeCommand<T>(command: string, ...rest: any[]): Promise<T>
    command: string

    Identifier of the command to execute.

    ...rest?: any[]

    Parameters passed to the command function.

    Returns
    Promise<T>
  2. Signature 2
    commands.executeCommand(command: 'vscode.open', uri: string | Uri): Promise<void>
    command: 'vscode.open'
    No parameter description is present in the pinned declaration.
    uri: string | Uri
    No parameter description is present in the pinned declaration.
    Returns
    Promise<void>
  3. Signature 3
    commands.executeCommand(command: 'workbench.action.reloadWindow'): Promise<void>
    command: 'workbench.action.reloadWindow'
    No parameter description is present in the pinned declaration.
    Returns
    Promise<void>
  4. Signature 4
    commands.executeCommand(command: 'workbench.action.openSettingsJson'): Promise<void>
    command: 'workbench.action.openSettingsJson'
    No parameter description is present in the pinned declaration.
    Returns
    Promise<void>
  5. Signature 5
    commands.executeCommand(command: 'editor.action.insertSnippet', edit: TextEdit, ultisnip?: UltiSnippetOption): Promise<boolean>
    command: 'editor.action.insertSnippet'
    No parameter description is present in the pinned declaration.
    edit: TextEdit

    Contains snippet text and range to replace.

    ultisnip?: UltiSnippetOption
    No parameter description is present in the pinned declaration.
    Returns
    Promise<boolean>
  6. Signature 6
    commands.executeCommand(command: 'editor.action.doCodeAction', action: CodeAction): Promise<void>
    command: 'editor.action.doCodeAction'
    No parameter description is present in the pinned declaration.
    action: CodeAction
    No parameter description is present in the pinned declaration.
    Returns
    Promise<void>
  7. Signature 7
    commands.executeCommand(command: 'editor.action.triggerSuggest', source?: string): Promise<void>
    command: 'editor.action.triggerSuggest'
    No parameter description is present in the pinned declaration.
    source?: string
    No parameter description is present in the pinned declaration.
    Returns
    Promise<void>
  8. Signature 8
    commands.executeCommand(command: 'editor.action.triggerParameterHints'): Promise<void>
    command: 'editor.action.triggerParameterHints'
    No parameter description is present in the pinned declaration.
    Returns
    Promise<void>
  9. Signature 9
    commands.executeCommand(command: 'editor.action.addRanges', ranges: Range[]): Promise<void>
    command: 'editor.action.addRanges'
    No parameter description is present in the pinned declaration.
    ranges: Range[]
    No parameter description is present in the pinned declaration.
    Returns
    Promise<void>
  10. Signature 10
    commands.executeCommand(command: 'editor.action.restart'): Promise<void>
    command: 'editor.action.restart'
    No parameter description is present in the pinned declaration.
    Returns
    Promise<void>
  11. Signature 11
    commands.executeCommand(command: 'editor.action.showReferences', uri: string | Uri, position: Position | undefined, locations: Location[]): Promise<void>
    command: 'editor.action.showReferences'
    No parameter description is present in the pinned declaration.
    uri: string | Uri
    No parameter description is present in the pinned declaration.
    position: Position | undefined
    No parameter description is present in the pinned declaration.
    locations: Location[]
    No parameter description is present in the pinned declaration.
    Returns
    Promise<void>
  12. Signature 12
    commands.executeCommand(command: 'editor.action.rename', uri: string | Uri, position: Position, newName?: string): Promise<void>
    command: 'editor.action.rename'
    No parameter description is present in the pinned declaration.
    uri: string | Uri
    No parameter description is present in the pinned declaration.
    position: Position
    No parameter description is present in the pinned declaration.
    newName?: string
    No parameter description is present in the pinned declaration.
    Returns
    Promise<void>
  13. Signature 13
    commands.executeCommand(command: 'editor.action.format'): Promise<void>
    command: 'editor.action.format'
    No parameter description is present in the pinned declaration.
    Returns
    Promise<void>
  14. Signature 14
    commands.executeCommand(command: 'editor.action.triggerInlineCompletion', option?: InlineCompletionOption): Promise<void>
    command: 'editor.action.triggerInlineCompletion'
    No parameter description is present in the pinned declaration.
    option?: InlineCompletionOption
    No parameter description is present in the pinned declaration.
    Returns
    Promise<void>
  15. Signature 15
    commands.executeCommand(command: 'editor.action.triggerNextEdit', option?: { provider?: string; autoTrigger?: boolean }): Promise<boolean>
    command: 'editor.action.triggerNextEdit'
    No parameter description is present in the pinned declaration.
    option?: { provider?: string; autoTrigger?: boolean }
    No parameter description is present in the pinned declaration.
    Returns
    Promise<boolean>

API signature

commands.executeCommand<T>(command: string, ...rest: any[]): Promise<T>

Parameters

ParameterTypeDescription
commandstring

Identifier of the command to execute.

...rest?any[]

Parameters passed to the command function.

Returns
Promise<T>

A promise that resolves to the returned value of the given command. undefined when the command handler function doesn't return anything.

Declaration
typings/index.d.ts:8026