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 {
|
4 | /**
|
5 | * Sends a request and returns a promise resolving to the result of the request.
|
6 | *
|
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.
|
10 | */
|
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>;
|
13 | /**
|
14 | * Sends a request and returns a promise resolving to the result of the request.
|
15 | *
|
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.
|
20 | */
|
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>;
|
23 | /**
|
24 | * Sends a request and returns a promise resolving to the result of the request.
|
25 | *
|
26 | * @param method the method name.
|
27 | * @param token An optional cancellation token.
|
28 | * @returns A promise resolving to the request's result.
|
29 | */
|
30 | sendRequest<R>(method: string, token?: CancellationToken): Promise<R>;
|
31 | /**
|
32 | * Sends a request and returns a promise resolving to the result of the request.
|
33 | *
|
34 | * @param method the 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.
|
38 | */
|
39 | sendRequest<R>(method: string, param: any, token?: CancellationToken): Promise<R>;
|
40 | /**
|
41 | * Installs a request handler.
|
42 | *
|
43 | * @param type The request type to install the handler for.
|
44 | * @param handler The actual handler.
|
45 | * @returns A disposable to remove the handler.
|
46 | */
|
47 | onRequest<R, PR, E, RO>(type: ProtocolRequestType0<R, PR, E, RO>, handler: RequestHandler0<R, E>): Disposable;
|
48 | onRequest<R, E>(type: RequestType0<R, E>, handler: RequestHandler0<R, E>): Disposable;
|
49 | /**
|
50 | * Installs a request handler.
|
51 | *
|
52 | * @param type The request type to install the handler for.
|
53 | * @param handler The actual handler.
|
54 | * @returns A disposable to remove the handler.
|
55 | */
|
56 | onRequest<P, R, PR, E, RO>(type: ProtocolRequestType<P, R, PR, E, RO>, handler: RequestHandler<P, R, E>): Disposable;
|
57 | onRequest<P, R, E>(type: RequestType<P, R, E>, handler: RequestHandler<P, R, E>): Disposable;
|
58 | /**
|
59 | * Installs a request handler.
|
60 | *
|
61 | * @param methods the message method name to install a handler for.
|
62 | * @param handler The actual handler.
|
63 | * @returns A disposable to remove the handler.
|
64 | */
|
65 | onRequest<R, E>(method: string, handler: GenericRequestHandler<R, E>): Disposable;
|
66 | /**
|
67 | * Returns true if the connection has a pending response.
|
68 | * Otherwise false is returned.
|
69 | */
|
70 | hasPendingResponse(): boolean;
|
71 | /**
|
72 | * Sends a notification.
|
73 | *
|
74 | * @param type the notification's type to send.
|
75 | * @returns A promise that resolves when the notification is written to the
|
76 | * network layer.
|
77 | */
|
78 | sendNotification(type: NotificationType0): Promise<void>;
|
79 | sendNotification<RO>(type: ProtocolNotificationType0<RO>): Promise<void>;
|
80 | /**
|
81 | * Sends a notification.
|
82 | *
|
83 | * @param type the notification's type to send.
|
84 | * @param params the notification's parameters.
|
85 | * @returns A promise that resolves when the notification is written to the
|
86 | * network layer.
|
87 | */
|
88 | sendNotification<P, RO>(type: ProtocolNotificationType<P, RO>, params?: P): Promise<void>;
|
89 | sendNotification<P>(type: NotificationType<P>, params?: P): Promise<void>;
|
90 | /**
|
91 | * Sends a notification.
|
92 | *
|
93 | * @param method the notification's method name.
|
94 | * @returns A promise that resolves when the notification is written to the
|
95 | * network layer.
|
96 | */
|
97 | sendNotification(method: string): Promise<void>;
|
98 | /**
|
99 | * Sends a notification.
|
100 | *
|
101 | * @param method the notification's method name.
|
102 | * @param params the notification's parameters.
|
103 | * @returns A promise that resolves when the notification is written to the
|
104 | * network layer.
|
105 | */
|
106 | sendNotification(method: string, params: any): Promise<void>;
|
107 | /**
|
108 | * Installs a notification handler.
|
109 | *
|
110 | * @param type The notification type to install the handler for.
|
111 | * @param handler The actual handler.
|
112 | * @returns A disposable to remove the handler.
|
113 | */
|
114 | onNotification<RO>(type: ProtocolNotificationType0<RO>, handler: NotificationHandler0): Disposable;
|
115 | onNotification(type: NotificationType0, handler: NotificationHandler0): Disposable;
|
116 | /**
|
117 | * Installs a notification handler.
|
118 | *
|
119 | * @param type The notification type to install the handler for.
|
120 | * @param handler The actual handler.
|
121 | * @returns A disposable to remove the handler.
|
122 | */
|
123 | onNotification<P, RO>(type: ProtocolNotificationType<P, RO>, handler: NotificationHandler<P>): Disposable;
|
124 | onNotification<P>(type: NotificationType<P>, handler: NotificationHandler<P>): Disposable;
|
125 | /**
|
126 | * Installs a notification handler.
|
127 | *
|
128 | * @param methods The message method name to install the handler for.
|
129 | * @param handler The actual handler.
|
130 | * @returns A disposable to remove the handler.
|
131 | */
|
132 | onNotification(method: string, handler: GenericNotificationHandler): Disposable;
|
133 | /**
|
134 | * Installs a progress handler for a given token.
|
135 | * @param type the progress type
|
136 | * @param token the token
|
137 | * @param handler the handler
|
138 | * @returns A disposable to remove the handler.
|
139 | */
|
140 | onProgress<P>(type: ProgressType<P>, token: string | number, handler: NotificationHandler<P>): Disposable;
|
141 | /**
|
142 | * Sends progress.
|
143 | * @param type the progress type
|
144 | * @param token the token to use
|
145 | * @param value the progress value
|
146 | * @returns A promise that resolves when the progress is written to the
|
147 | * network layer.
|
148 | */
|
149 | sendProgress<P>(type: ProgressType<P>, token: string | number, value: P): Promise<void>;
|
150 | /**
|
151 | * Enables tracing mode for the connection.
|
152 | * @returns A promise that resolves when the trace value is written to the
|
153 | * network layer.
|
154 | */
|
155 | trace(value: Trace, tracer: Tracer, sendNotification?: boolean): Promise<void>;
|
156 | trace(value: Trace, tracer: Tracer, traceOptions?: TraceOptions): Promise<void>;
|
157 | /**
|
158 | * An event emitter firing when an error occurs on the connection.
|
159 | */
|
160 | onError: Event<[Error, Message | undefined, number | undefined]>;
|
161 | /**
|
162 | * An event emitter firing when the connection got closed.
|
163 | */
|
164 | onClose: Event<void>;
|
165 | /**
|
166 | * An event emitter firing when the connection receives a notification that is not
|
167 | * handled.
|
168 | */
|
169 | onUnhandledNotification: Event<NotificationMessage>;
|
170 | /**
|
171 | * An event emitter firing when the connection got disposed.
|
172 | */
|
173 | onDispose: Event<void>;
|
174 | /**
|
175 | * Ends the connection.
|
176 | */
|
177 | end(): void;
|
178 | /**
|
179 | * Actively disposes the connection.
|
180 | */
|
181 | dispose(): void;
|
182 | /**
|
183 | * Turns the connection into listening mode
|
184 | */
|
185 | listen(): void;
|
186 | }
|
187 | export declare function createProtocolConnection(input: MessageReader, output: MessageWriter, logger?: Logger, options?: ConnectionStrategy | ConnectionOptions): ProtocolConnection;
|