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

    Interface WebviewRpc<S>

    A typed, bidirectional request/response + event channel layered over a vscode.Webview's raw postMessage/onDidReceiveMessage. See createWebviewRpc.

    interface WebviewRpc<S extends WebviewRpcSchema = WebviewRpcSchema> {
        dispose(): void;
        emit<K extends string | number | symbol>(
            event: K,
            payload: NonNullable<S["hostEvents"]>[K],
        ): void;
        onEvent<K extends string | number | symbol>(
            event: K,
            handler: (payload: NonNullable<S["webviewEvents"]>[K]) => void,
        ): { dispose(): void };
        onRequest<K extends string | number | symbol>(
            method: K,
            handler: (
                params: NonNullable<S["hostRequests"]>[K]["params"],
                ctx: { signal: AbortSignal },
            ) =>
                | NonNullable<S["hostRequests"]>[K]["result"]
                | Promise<NonNullable<S["hostRequests"]>[K]["result"]>,
        ): { dispose(): void };
        request<K extends string | number | symbol>(
            method: K,
            params: NonNullable<S["webviewRequests"]>[K]["params"],
            options?: WebviewRpcRequestOptions,
        ): Promise<NonNullable<S["webviewRequests"]>[K]["result"]>;
    }

    Type Parameters

    Index
    • Stops listening, rejects every in-flight request, and aborts every running onRequest handler. Safe to call more than once. Other methods are not valid after disposal; only request has a defined post-disposal result (a rejected promise).

      Returns void

    • Sends a one-way event to the webview. Does not wait for acknowledgement.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K
      • payload: NonNullable<S["hostEvents"]>[K]

      Returns void

    • Subscribes to a one-way event sent by the webview. Payloads are untrusted at runtime. Handlers run synchronously; an exception propagates through the platform message callback and prevents later handlers for that event from running, so handle expected failures inside the callback.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K
      • handler: (payload: NonNullable<S["webviewEvents"]>[K]) => void

      Returns { dispose(): void }

    • Registers the handler for a request the webview may send. The handler's ctx.signal aborts if the webview cancels the request (or the RPC is disposed) before the handler settles.

      One handler is stored per method. Registering another replaces it; dispose the earlier registration first, because either registration's disposer removes the method entry.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • method: K
      • handler: (
            params: NonNullable<S["hostRequests"]>[K]["params"],
            ctx: { signal: AbortSignal },
        ) =>
            | NonNullable<S["hostRequests"]>[K]["result"]
            | Promise<NonNullable<S["hostRequests"]>[K]["result"]>

      Returns { dispose(): void }

    • Sends a request to the webview and resolves with its response. Rejects if the webview responds with an error, if the message could not be delivered, if options.signal aborts, if options.timeoutMs elapses, or if the RPC is disposed while the request is in flight.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      Returns Promise<NonNullable<S["webviewRequests"]>[K]["result"]>