All files / views/webviews webview-messaging.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                                                                         
/**
 * Interface for sending and receiving messages between a webview and its host.
 * @remarks This interface implements a unified API for webview messaging in webview components or notebook renderers.
 */
export interface WebviewMessaging<T extends WebviewMessage> {
	/**
	 * Sends a message to the webview.
	 * @param message The message to send to the webview.
	 */
	postMessage(message: T): void;
 
	/**
	 * Registers a handler for messages received from the webview.
	 * @param handler The function to call when a message is received.
	 */
	onMessage(handler: (message: T) => void): void;
}
 
/**
 * Base interface for messages sent between the webview and its host.
 */
export interface WebviewMessage {
	/**
	 * The unique identifier for the message.
	 */
	id: string;
}
 
/**
 * Common message type for executing VS Code commands from webviews.
 * Include this in your webview's message union type to enable command execution.
 */
export interface ExecuteCommandMessage extends WebviewMessage {
	id: 'ExecuteCommand';
	command: string;
	args?: any[];
}