@kkdev92/vscode-ext-kit - v4.1.1
    Preparing search index...

    Interface CommandsService

    Invoking commands — the platform's, and the application's own.

    Registering is the other direction and belongs to a module (module.commands.handle); this is only for calling one. Most of what an extension reaches for beyond the framework's models is a built-in command — workbench.action.openSettings, setContext, vscode.open — and routing those through the same capability the framework registers against keeps them out of the fakes' blind spot.

    module.commands.handle(ShowSetting, {
    inject: { commands: Commands },
    execute: async (_context, _args, { commands }) => {
    await commands.execute('workbench.action.openSettings', 'sample.timeout');
    },
    });
    interface CommandsService {
        execute<T = void>(id: string, ...args: readonly unknown[]): Promise<T>;
        invoke<TArgs extends readonly unknown[], TResult>(
            contract: CommandContract<TArgs, TResult>,
            ...args: TArgs,
        ): Promise<TResult>;
    }
    Index
    • Runs a command by id, resolving with what it returned and rejecting with what it threw.

      Untyped on purpose: an id typed as a bare string is a platform command, whose signature the framework cannot know. For the application's own commands use CommandsService.invoke, which does know. Arguments and results cross the platform command boundary unchanged; this method performs no runtime validation.

      Type Parameters

      • T = void

      Parameters

      • id: string

        Command id

      • ...args: readonly unknown[]

        Arguments, passed through untouched

      Returns Promise<T>

    • Runs one of the application's own commands, typed by its contract.

      The contract carries the argument tuple and the result type, so a changed signature fails to compile at every call site rather than at runtime in whichever one the user hits first.

      Type Parameters

      • TArgs extends readonly unknown[]
      • TResult

      Parameters

      Returns Promise<TResult>

      const count = await commands.invoke(Refresh, true);