UNPKG

12.6 kBTypeScriptView Raw
1/**
2 * A language server message
3 */
4export interface Message {
5 jsonrpc: string;
6}
7/**
8 * Request message
9 */
10export interface RequestMessage extends Message {
11 /**
12 * The request id.
13 */
14 id: number | string | null;
15 /**
16 * The method to be invoked.
17 */
18 method: string;
19 /**
20 * The method's params.
21 */
22 params?: any[] | object;
23}
24/**
25 * Predefined error codes.
26 */
27export declare namespace ErrorCodes {
28 const ParseError: -32700;
29 const InvalidRequest: -32600;
30 const MethodNotFound: -32601;
31 const InvalidParams: -32602;
32 const InternalError: -32603;
33 /**
34 * This is the start range of JSON RPC reserved error codes.
35 * It doesn't denote a real error code. No application error codes should
36 * be defined between the start and end range. For backwards
37 * compatibility the `ServerNotInitialized` and the `UnknownErrorCode`
38 * are left in the range.
39 *
40 * @since 3.16.0
41 */
42 const jsonrpcReservedErrorRangeStart: -32099;
43 /** @deprecated use jsonrpcReservedErrorRangeStart */
44 const serverErrorStart: -32099;
45 /**
46 * An error occurred when write a message to the transport layer.
47 */
48 const MessageWriteError: -32099;
49 /**
50 * An error occurred when reading a message from the transport layer.
51 */
52 const MessageReadError: -32098;
53 /**
54 * The connection got disposed or lost and all pending responses got
55 * rejected.
56 */
57 const PendingResponseRejected: -32097;
58 /**
59 * The connection is inactive and a use of it failed.
60 */
61 const ConnectionInactive: -32096;
62 /**
63 * Error code indicating that a server received a notification or
64 * request before the server has received the `initialize` request.
65 */
66 const ServerNotInitialized: -32002;
67 const UnknownErrorCode: -32001;
68 /**
69 * This is the end range of JSON RPC reserved error codes.
70 * It doesn't denote a real error code.
71 *
72 * @since 3.16.0
73 */
74 const jsonrpcReservedErrorRangeEnd: -32000;
75 /** @deprecated use jsonrpcReservedErrorRangeEnd */
76 const serverErrorEnd: -32000;
77}
78type integer = number;
79export type ErrorCodes = integer;
80export interface ResponseErrorLiteral<D = void> {
81 /**
82 * A number indicating the error type that occurred.
83 */
84 code: number;
85 /**
86 * A string providing a short description of the error.
87 */
88 message: string;
89 /**
90 * A Primitive or Structured value that contains additional
91 * information about the error. Can be omitted.
92 */
93 data?: D;
94}
95/**
96 * An error object return in a response in case a request
97 * has failed.
98 */
99export declare class ResponseError<D = void> extends Error {
100 readonly code: number;
101 readonly data: D | undefined;
102 constructor(code: number, message: string, data?: D);
103 toJson(): ResponseErrorLiteral<D>;
104}
105/**
106 * A response message.
107 */
108export interface ResponseMessage extends Message {
109 /**
110 * The request id.
111 */
112 id: number | string | null;
113 /**
114 * The result of a request. This member is REQUIRED on success.
115 * This member MUST NOT exist if there was an error invoking the method.
116 */
117 result?: string | number | boolean | object | any[] | null;
118 /**
119 * The error object in case a request fails.
120 */
121 error?: ResponseErrorLiteral<any>;
122}
123/**
124 * A LSP Log Entry.
125 */
126export type LSPMessageType = 'send-request' | 'receive-request' | 'send-response' | 'receive-response' | 'send-notification' | 'receive-notification';
127export interface LSPLogMessage {
128 type: LSPMessageType;
129 message: RequestMessage | ResponseMessage | NotificationMessage;
130 timestamp: number;
131}
132export declare class ParameterStructures {
133 private readonly kind;
134 /**
135 * The parameter structure is automatically inferred on the number of parameters
136 * and the parameter type in case of a single param.
137 */
138 static readonly auto: ParameterStructures;
139 /**
140 * Forces `byPosition` parameter structure. This is useful if you have a single
141 * parameter which has a literal type.
142 */
143 static readonly byPosition: ParameterStructures;
144 /**
145 * Forces `byName` parameter structure. This is only useful when having a single
146 * parameter. The library will report errors if used with a different number of
147 * parameters.
148 */
149 static readonly byName: ParameterStructures;
150 private constructor();
151 static is(value: any): value is ParameterStructures;
152 toString(): string;
153}
154/**
155 * An interface to type messages.
156 */
157export interface MessageSignature {
158 readonly method: string;
159 readonly numberOfParams: number;
160 readonly parameterStructures: ParameterStructures;
161}
162/**
163 * An abstract implementation of a MessageType.
164 */
165export declare abstract class AbstractMessageSignature implements MessageSignature {
166 readonly method: string;
167 readonly numberOfParams: number;
168 constructor(method: string, numberOfParams: number);
169 get parameterStructures(): ParameterStructures;
170}
171/**
172 * End marker interface for request and notification types.
173 */
174export interface _EM {
175 _$endMarker$_: number;
176}
177/**
178 * Classes to type request response pairs
179 */
180export declare class RequestType0<R, E> extends AbstractMessageSignature {
181 /**
182 * Clients must not use this property. It is here to ensure correct typing.
183 */
184 readonly _: [R, E, _EM] | undefined;
185 constructor(method: string);
186}
187export declare class RequestType<P, R, E> extends AbstractMessageSignature {
188 private _parameterStructures;
189 /**
190 * Clients must not use this property. It is here to ensure correct typing.
191 */
192 readonly _: [P, R, E, _EM] | undefined;
193 constructor(method: string, _parameterStructures?: ParameterStructures);
194 get parameterStructures(): ParameterStructures;
195}
196export declare class RequestType1<P1, R, E> extends AbstractMessageSignature {
197 private _parameterStructures;
198 /**
199 * Clients must not use this property. It is here to ensure correct typing.
200 */
201 readonly _: [P1, R, E, _EM] | undefined;
202 constructor(method: string, _parameterStructures?: ParameterStructures);
203 get parameterStructures(): ParameterStructures;
204}
205export declare class RequestType2<P1, P2, R, E> extends AbstractMessageSignature {
206 /**
207 * Clients must not use this property. It is here to ensure correct typing.
208 */
209 readonly _: [P1, P2, R, E, _EM] | undefined;
210 constructor(method: string);
211}
212export declare class RequestType3<P1, P2, P3, R, E> extends AbstractMessageSignature {
213 /**
214 * Clients must not use this property. It is here to ensure correct typing.
215 */
216 readonly _: [P1, P2, P3, R, E, _EM] | undefined;
217 constructor(method: string);
218}
219export declare class RequestType4<P1, P2, P3, P4, R, E> extends AbstractMessageSignature {
220 /**
221 * Clients must not use this property. It is here to ensure correct typing.
222 */
223 readonly _: [P1, P2, P3, P4, R, E, _EM] | undefined;
224 constructor(method: string);
225}
226export declare class RequestType5<P1, P2, P3, P4, P5, R, E> extends AbstractMessageSignature {
227 /**
228 * Clients must not use this property. It is here to ensure correct typing.
229 */
230 readonly _: [P1, P2, P3, P4, P5, R, E, _EM] | undefined;
231 constructor(method: string);
232}
233export declare class RequestType6<P1, P2, P3, P4, P5, P6, R, E> extends AbstractMessageSignature {
234 /**
235 * Clients must not use this property. It is here to ensure correct typing.
236 */
237 readonly _: [P1, P2, P3, P4, P5, P6, R, E, _EM] | undefined;
238 constructor(method: string);
239}
240export declare class RequestType7<P1, P2, P3, P4, P5, P6, P7, R, E> extends AbstractMessageSignature {
241 /**
242 * Clients must not use this property. It is here to ensure correct typing.
243 */
244 readonly _: [P1, P2, P3, P4, P5, P6, P7, R, E, _EM] | undefined;
245 constructor(method: string);
246}
247export declare class RequestType8<P1, P2, P3, P4, P5, P6, P7, P8, R, E> extends AbstractMessageSignature {
248 /**
249 * Clients must not use this property. It is here to ensure correct typing.
250 */
251 readonly _: [P1, P2, P3, P4, P5, P6, P7, P8, R, E, _EM] | undefined;
252 constructor(method: string);
253}
254export declare class RequestType9<P1, P2, P3, P4, P5, P6, P7, P8, P9, R, E> extends AbstractMessageSignature {
255 /**
256 * Clients must not use this property. It is here to ensure correct typing.
257 */
258 readonly _: [P1, P2, P3, P4, P5, P6, P7, P8, P9, R, E, _EM] | undefined;
259 constructor(method: string);
260}
261/**
262 * Notification Message
263 */
264export interface NotificationMessage extends Message {
265 /**
266 * The method to be invoked.
267 */
268 method: string;
269 /**
270 * The notification's params.
271 */
272 params?: any[] | object;
273}
274export declare class NotificationType<P> extends AbstractMessageSignature {
275 private _parameterStructures;
276 /**
277 * Clients must not use this property. It is here to ensure correct typing.
278 */
279 readonly _: [P, _EM] | undefined;
280 constructor(method: string, _parameterStructures?: ParameterStructures);
281 get parameterStructures(): ParameterStructures;
282}
283export declare class NotificationType0 extends AbstractMessageSignature {
284 /**
285 * Clients must not use this property. It is here to ensure correct typing.
286 */
287 readonly _: [_EM] | undefined;
288 constructor(method: string);
289}
290export declare class NotificationType1<P1> extends AbstractMessageSignature {
291 private _parameterStructures;
292 /**
293 * Clients must not use this property. It is here to ensure correct typing.
294 */
295 readonly _: [P1, _EM] | undefined;
296 constructor(method: string, _parameterStructures?: ParameterStructures);
297 get parameterStructures(): ParameterStructures;
298}
299export declare class NotificationType2<P1, P2> extends AbstractMessageSignature {
300 /**
301 * Clients must not use this property. It is here to ensure correct typing.
302 */
303 readonly _: [P1, P2, _EM] | undefined;
304 constructor(method: string);
305}
306export declare class NotificationType3<P1, P2, P3> extends AbstractMessageSignature {
307 /**
308 * Clients must not use this property. It is here to ensure correct typing.
309 */
310 readonly _: [P1, P2, P3, _EM] | undefined;
311 constructor(method: string);
312}
313export declare class NotificationType4<P1, P2, P3, P4> extends AbstractMessageSignature {
314 /**
315 * Clients must not use this property. It is here to ensure correct typing.
316 */
317 readonly _: [P1, P2, P3, P4, _EM] | undefined;
318 constructor(method: string);
319}
320export declare class NotificationType5<P1, P2, P3, P4, P5> extends AbstractMessageSignature {
321 /**
322 * Clients must not use this property. It is here to ensure correct typing.
323 */
324 readonly _: [P1, P2, P3, P4, P5, _EM] | undefined;
325 constructor(method: string);
326}
327export declare class NotificationType6<P1, P2, P3, P4, P5, P6> extends AbstractMessageSignature {
328 /**
329 * Clients must not use this property. It is here to ensure correct typing.
330 */
331 readonly _: [P1, P2, P3, P4, P5, P6, _EM] | undefined;
332 constructor(method: string);
333}
334export declare class NotificationType7<P1, P2, P3, P4, P5, P6, P7> extends AbstractMessageSignature {
335 /**
336 * Clients must not use this property. It is here to ensure correct typing.
337 */
338 readonly _: [P1, P2, P3, P4, P5, P6, P7, _EM] | undefined;
339 constructor(method: string);
340}
341export declare class NotificationType8<P1, P2, P3, P4, P5, P6, P7, P8> extends AbstractMessageSignature {
342 /**
343 * Clients must not use this property. It is here to ensure correct typing.
344 */
345 readonly _: [P1, P2, P3, P4, P5, P6, P7, P8, _EM] | undefined;
346 constructor(method: string);
347}
348export declare class NotificationType9<P1, P2, P3, P4, P5, P6, P7, P8, P9> extends AbstractMessageSignature {
349 /**
350 * Clients must not use this property. It is here to ensure correct typing.
351 */
352 readonly _: [P1, P2, P3, P4, P5, P6, P7, P8, P9, _EM] | undefined;
353 constructor(method: string);
354}
355export declare namespace Message {
356 /**
357 * Tests if the given message is a request message
358 */
359 function isRequest(message: Message | undefined): message is RequestMessage;
360 /**
361 * Tests if the given message is a notification message
362 */
363 function isNotification(message: Message | undefined): message is NotificationMessage;
364 /**
365 * Tests if the given message is a response message
366 */
367 function isResponse(message: Message | undefined): message is ResponseMessage;
368}
369export {};