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

    Function createWebviewRpcClient

    • Creates the webview-side endpoint of a createWebviewRpc channel — the import that replaces the hand-copied postMessage plumbing a webview bundle otherwise needs.

      Wire-compatible with the extension host side by construction: both are built on the same protocol.ts, and the direction conventions of WebviewRpcSchema apply symmetrically (this side sends hostRequests and answers webviewRequests).

      Type Parameters

      Parameters

      • options: WebviewRpcClientOptions = {}

        Pass vscodeApi if your code already called acquireVsCodeApi() (VS Code permits only one call); target is for tests

      Returns WebviewRpcClient<S>

      import { createWebviewRpcClient } from '@kkdev92/vscode-ext-kit/webview-client';
      import type { MyRpcSchema } from '../../shared/rpc-schema.js';

      const vscodeApi = acquireVsCodeApi(); // you keep it for getState/setState
      const rpc = createWebviewRpcClient<MyRpcSchema>({ vscodeApi });

      rpc.onRequest('getSelection', () => ({ text: document.getSelection()?.toString() ?? '' }));
      rpc.onEvent('theme', ({ kind }) => applyTheme(kind));

      const { ok } = await rpc.request('save', { content: editor.value }, { timeoutMs: 5000 });
      rpc.emit('dirty', { isDirty: false });