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

    Interface FakeCommands

    In-memory command capability for tests.

    Mirrors the command port's observable behavior rather than being lenient: a duplicate id throws, an unknown id rejects, and both return values and rejections propagate. Shared contract tests pin the real adapter behavior represented here; VS Code behavior outside the port is not implied.

    interface FakeCommands {
        registeredIds: readonly string[];
        execute<T>(id: string, ...args: readonly unknown[]): Promise<T>;
        executeTextEditor(
            id: string,
            editor: ActiveTextEditor,
            ...args: readonly unknown[],
        ): Promise<{ settled: Promise<unknown> }>;
        invocationCount(id: string): number;
        register(
            id: string,
            handler: (...args: readonly unknown[]) => unknown,
        ): PlatformRegistration;
        registerTextEditor(
            id: string,
            handler: (editor: ActiveTextEditor, args: readonly unknown[]) => unknown,
        ): PlatformRegistration;
    }

    Hierarchy

    • CommandCapability
      • FakeCommands
    Index
    registeredIds: readonly string[]

    Ids currently registered, in registration order.

    • Invokes a command, resolving with whatever the handler returned and rejecting with whatever it threw.

      Type Parameters

      • T

      Parameters

      • id: string
      • ...args: readonly unknown[]

      Returns Promise<T>

    • Invokes a text editor command with a scripted editor, standing in for VS Code invoking it against the focused one.

      Returns the fake-only { settled } hook after the handler returns. The text-editor command port exposes no command result; settled separately tracks the handler value or promise so a test can await framework work. A synchronous handler throw escapes before this hook can be returned.

      Takes the editor port rather than a whole fake editor: a test that only cares that the command ran can pass createFakeEditor().active as ActiveTextEditor.

      Parameters

      Returns Promise<{ settled: Promise<unknown> }>

    • Registers one handler for id. The returned registration removes it; a platform conflict may throw synchronously during registration.

      Parameters

      • id: string
      • handler: (...args: readonly unknown[]) => unknown

      Returns PlatformRegistration

    • Registers a text editor command.

      VS Code only invokes it with an editor focused; with none it logs "no active text editor" and skips the handler. It does not grey the command out in the palette — that is the enablement / commandPalette when clause in package.json.

      Fire-and-forget, unlike CommandCapability.register. VS Code's wrapper runs the handler inside activeTextEditor.edit(...) and discards what it returned, logging a rejection rather than propagating it So execute on such a command may resolve undefined while an async handler is still running. A command whose caller needs the result or the failure must be a plain one.

      The editor arrives as the same port active returns, so a handler works with one editor shape however its command was declared. VS Code's synchronous TextEditorEdit builder is deliberately not passed through: it validates its arguments with instanceof Range, so it cannot cross a port, and it is closed by the time an operation-wrapped handler resumes.

      Parameters

      • id: string
      • handler: (editor: ActiveTextEditor, args: readonly unknown[]) => unknown

      Returns PlatformRegistration