1 import { Message, NotificationMessage, CancellationToken, RequestHandler0, RequestHandler, GenericRequestHandler, NotificationHandler0, NotificationHandler, GenericNotificationHandler, ProgressType, Trace, Tracer, TraceOptions, Disposable, Event, MessageReader, MessageWriter, Logger, ConnectionStrategy, ConnectionOptions, RequestType0, RequestType, NotificationType0, NotificationType } from 'vscode-jsonrpc';
2 import { ProtocolRequestType, ProtocolRequestType0, ProtocolNotificationType, ProtocolNotificationType0 } from './messages';
3 export interface ProtocolConnection {
5 * Sends a request and returns a promise resolving to the result of the request.
7 * @param type The type of request to sent.
8 * @param token An optional cancellation token.
9 * @returns A promise resolving to the request's result.
11 sendRequest<R, PR, E, RO>(type: ProtocolRequestType0<R, PR, E, RO>, token?: CancellationToken): Promise<R>;
12 sendRequest<R, E>(type: RequestType0<R, E>, token?: CancellationToken): Promise<R>;
14 * Sends a request and returns a promise resolving to the result of the request.
16 * @param type The type of request to sent.
17 * @param params The request's parameter.
18 * @param token An optional cancellation token.
19 * @returns A promise resolving to the request's result.
21 sendRequest<P, R, PR, E, RO>(type: ProtocolRequestType<P, R, PR, E, RO>, params: P, token?: CancellationToken): Promise<R>;
22 sendRequest<P, R, E>(type: RequestType<P, R, E>, params: P, token?: CancellationToken): Promise<R>;
24 * Sends a request and returns a promise resolving to the result of the request.
26 * @param method the request's method name.
27 * @param token An optional cancellation token.
28 * @returns A promise resolving to the request's result.
30 sendRequest<R>(method: string, token?: CancellationToken): Promise<R>;
32 * Sends a request and returns a promise resolving to the result of the request.
34 * @param method the request's method name.
35 * @param params The request's parameter.
36 * @param token An optional cancellation token.
37 * @returns A promise resolving to the request's result.
39 sendRequest<R>(method: string, param: any, token?: CancellationToken): Promise<R>;
41 * Installs a request handler.
43 * @param type The request type to install the handler for.
44 * @param handler The actual handler.
46 onRequest<R, PR, E, RO>(type: ProtocolRequestType0<R, PR, E, RO>, handler: RequestHandler0<R, E>): Disposable;
47 onRequest<R, E>(type: RequestType0<R, E>, handler: RequestHandler0<R, E>): Disposable;
49 * Installs a request handler.
51 * @param type The request type to install the handler for.
52 * @param handler The actual handler.
54 onRequest<P, R, PR, E, RO>(type: ProtocolRequestType<P, R, PR, E, RO>, handler: RequestHandler<P, R, E>): Disposable;
55 onRequest<P, R, E>(type: RequestType<P, R, E>, handler: RequestHandler<P, R, E>): Disposable;
57 * Installs a request handler.
59 * @param methods The method name to install the handler for.
60 * @param handler The actual handler.
62 onRequest<R, E>(method: string, handler: GenericRequestHandler<R, E>): Disposable;
64 * Sends a notification.
66 * @param type the notification's type to send.
68 sendNotification(type: NotificationType0): void;
69 sendNotification<RO>(type: ProtocolNotificationType0<RO>): void;
71 * Sends a notification.
73 * @param type the notification's type to send.
74 * @param params the notification's parameters.
76 sendNotification<P, RO>(type: ProtocolNotificationType<P, RO>, params?: P): void;
77 sendNotification<P>(type: NotificationType<P>, params?: P): void;
79 * Sends a notification.
81 * @param method the notification's method name.
83 sendNotification(method: string): void;
85 * Sends a notification.
87 * @param method the notification's method name.
88 * @param params the notification's parameters.
90 sendNotification(method: string, params: any): void;
92 * Installs a notification handler.
94 * @param type The notification type to install the handler for.
95 * @param handler The actual handler.
97 onNotification<RO>(type: ProtocolNotificationType0<RO>, handler: NotificationHandler0): Disposable;
98 onNotification(type: NotificationType0, handler: NotificationHandler0): Disposable;
100 * Installs a notification handler.
102 * @param type The notification type to install the handler for.
103 * @param handler The actual handler.
105 onNotification<P, RO>(type: ProtocolNotificationType<P, RO>, handler: NotificationHandler<P>): Disposable;
106 onNotification<P>(type: NotificationType<P>, handler: NotificationHandler<P>): Disposable;
108 * Installs a notification handler.
110 * @param methods The method name to install the handler for.
111 * @param handler The actual handler.
113 onNotification(method: string, handler: GenericNotificationHandler): Disposable;
115 * Installs a progress handler for a given token.
116 * @param type the progress type
117 * @param token the token
118 * @param handler the handler
120 onProgress<P>(type: ProgressType<P>, token: string | number, handler: NotificationHandler<P>): Disposable;
123 * @param type the progress type
124 * @param token the token to use
125 * @param value the progress value
127 sendProgress<P>(type: ProgressType<P>, token: string | number, value: P): void;
129 * Enables tracing mode for the connection.
131 trace(value: Trace, tracer: Tracer, sendNotification?: boolean): void;
132 trace(value: Trace, tracer: Tracer, traceOptions?: TraceOptions): void;
134 * An event emitter firing when an error occurs on the connection.
136 onError: Event<[Error, Message | undefined, number | undefined]>;
138 * An event emitter firing when the connection got closed.
140 onClose: Event<void>;
142 * An event emiiter firing when the connection receives a notification that is not
145 onUnhandledNotification: Event<NotificationMessage>;
147 * An event emitter firing when the connection got disposed.
149 onDispose: Event<void>;
151 * Ends the connection.
155 * Actively disposes the connection.
159 * Turns the connection into listening mode
163 export declare function createProtocolConnection(input: MessageReader, output: MessageWriter, logger?: Logger, options?: ConnectionStrategy | ConnectionOptions): ProtocolConnection;