|
6 | 6 | */ |
7 | 7 |
|
8 | 8 | import { Context, type Effect } from "effect"; |
9 | | -import type { IDisposable } from "vscode"; |
| 9 | +import type { Disposable } from "vscode"; |
10 | 10 |
|
11 | 11 | import type { IPCError } from "../Error.js"; |
12 | 12 |
|
13 | | -export interface Interface { |
14 | | - /** |
15 | | - * Dispatches an incoming request from the host. |
16 | | - * It will first check for a custom invoke handler, then fall back to the |
17 | | - * main VS Code RPCProtocol. |
18 | | - * @param Method The name of the method being invoked. |
19 | | - * @param Parameters The arguments for the method. |
20 | | - * @returns An `Effect` that resolves with the result of the handler. |
21 | | - */ |
22 | | - readonly DispatchRequest: ( |
23 | | - Method: string, |
24 | | - Parameters: any[], |
25 | | - ) => Effect.Effect<any, Error>; |
26 | | - |
27 | | - /** |
28 | | - * Dispatches an incoming fire-and-forget notification from the host. |
29 | | - * @param Method The name of the notification. |
30 | | - * @param Parameters The arguments for the notification. |
31 | | - */ |
32 | | - readonly DispatchNotification: ( |
33 | | - Method: string, |
34 | | - Parameters: any[], |
35 | | - ) => Effect.Effect<void, never>; |
36 | | - |
37 | | - /** |
38 | | - * Dispatches an incoming cancellation signal from the host. |
39 | | - * @param RequestID The ID of the request to cancel. |
40 | | - */ |
41 | | - readonly CancelOperation: (RequestID: number) => Effect.Effect<void, never>; |
42 | | - |
43 | | - /** |
44 | | - * Processes raw binary data for the VS Code RPCProtocol by passing it to |
45 | | - * the underlying protocol adapter. |
46 | | - * @param Data The raw Uint8Array from the host. |
47 | | - */ |
48 | | - readonly ProcessIncomingData: ( |
49 | | - Data: Uint8Array, |
50 | | - ) => Effect.Effect<void, never>; |
51 | | - |
52 | | - /** |
53 | | - * Registers a custom handler for a specific invoke method from the host. |
54 | | - * This is used for top-level methods like `initExtensionHost` that are |
55 | | - * not part of the standard VS Code RPC protocol. |
56 | | - * @param Channel The channel/method name. |
57 | | - * @param Handler An async function that handles the request. |
58 | | - * @returns A `Disposable` to unregister the handler. |
59 | | - */ |
60 | | - readonly RegisterInvokeHandler: ( |
61 | | - Channel: string, |
62 | | - Handler: (...Arguments: any[]) => Promise<any>, |
63 | | - ) => IDisposable; |
64 | | -} |
65 | | - |
66 | | -export const Tag = Context.Tag<Interface>("IPC/Dispatcher"); |
| 13 | +export class Dispatcher extends Context.Tag("IPC/Dispatcher")< |
| 14 | + Dispatcher, |
| 15 | + { |
| 16 | + readonly DispatchRequest: ( |
| 17 | + Method: string, |
| 18 | + ParameterArray: any[], |
| 19 | + ) => Effect.Effect<any, Error>; |
| 20 | + readonly DispatchNotification: ( |
| 21 | + Method: string, |
| 22 | + ParameterArray: any[], |
| 23 | + ) => Effect.Effect<void, never>; |
| 24 | + readonly CancelOperation: ( |
| 25 | + RequestID: number, |
| 26 | + ) => Effect.Effect<void, never>; |
| 27 | + readonly ProcessIncomingData: ( |
| 28 | + Data: Uint8Array, |
| 29 | + ) => Effect.Effect<void, never>; |
| 30 | + readonly RegisterInvokeHandler: ( |
| 31 | + Channel: string, |
| 32 | + Handler: (...ArgumentArray: any[]) => Promise<any>, |
| 33 | + ) => Disposable; |
| 34 | + } |
| 35 | +>() {} |
0 commit comments