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

    Interface CommandCollection<TUses>

    Records command handlers for the Module.

    Each invocation runs as an Operation. Dependencies are resolved for that Operation, disposable transients are owned by its ResourceScope, and a plain command handler's value or rejection is preserved for its caller. The text editor-specific registration below documents its narrower platform contract.

    interface CommandCollection<TUses extends ServiceMap = Record<never, never>> {
        handle<TArgs extends readonly unknown[], TResult>(
            contract: CommandContract<TArgs, TResult>,
            execute: (
                context: OperationContext,
                args: TArgs,
                injected: Injected<TUses>,
            ) => TResult | Promise<TResult>,
        ): void;
        handle<
            TArgs extends readonly unknown[],
            TResult,
            TMap extends Readonly<Record<string, ServiceToken<unknown>>>,
        >(
            contract: CommandContract<TArgs, TResult>,
            registration: {
                execute: (
                    context: OperationContext,
                    args: TArgs,
                    injected: Injected<TUses & TMap>,
                ) => TResult | Promise<TResult>;
                inject: TMap;
            },
        ): void;
        handleTextEditor<
            TArgs extends readonly unknown[],
            TResult,
            TMap extends Readonly<Record<string, ServiceToken<unknown>>>,
        >(
            contract: CommandContract<TArgs, TResult>,
            registration: {
                execute: (
                    context: OperationContext,
                    editor: ActiveEditor,
                    args: TArgs,
                    injected: Injected<TUses & TMap>,
                ) => TResult | Promise<TResult>;
                inject: TMap;
            },
        ): void;
        handleTextEditor<TArgs extends readonly unknown[], TResult>(
            contract: CommandContract<TArgs, TResult>,
            execute: (
                context: OperationContext,
                editor: ActiveEditor,
                args: TArgs,
                injected: Injected<TUses>,
            ) => TResult | Promise<TResult>,
        ): void;
    }

    Type Parameters

    Index
    • Handles a command that needs an editor.

      Registered with registerTextEditorCommand, so VS Code only invokes it with an editor focused and skips it otherwise, rather than calling a handler that has to give up. Prefer it for anything that edits or reads the current document.

      The trade is real, and it is VS Code's, not the framework's: the registered callback has a void contract and runs inside the platform's edit transaction. The framework can start an asynchronous Operation there, but its result or rejection does not become the result of commands.execute. Operation failures are still logged by the framework. Declare a command with CommandCollection.handle instead when a caller must await the result, and take the editor from Editors.active.

      It also does not grey the palette entry out; that is the enablement / commandPalette when clause in package.json.

      The editor is the same ActiveEditor the Editors service hands out, so a feature written against one works with either declaration.

      The dependency-declaring overload is listed first: overload resolution takes the first match, and the no-dependency shape would otherwise absorb the call.

      Type Parameters

      • TArgs extends readonly unknown[]
      • TResult
      • TMap extends Readonly<Record<string, ServiceToken<unknown>>>

      Parameters

      Returns void

      module.handleTextEditor(UpperCase, {
      inject: { history: History },
      execute: async (_context, editor, _args, { history }) => {
      await editor.transformSelections((text) => text.toUpperCase());
      await history.record('case.upper');
      },
      });
    • Handles a text editor command with no dependencies.

      Type Parameters

      • TArgs extends readonly unknown[]
      • TResult

      Parameters

      Returns void