massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-json / node_modules / vscode-jsonrpc / lib / common / messages.js
1 "use strict";
2 /* --------------------------------------------------------------------------------------------
3  * Copyright (c) Microsoft Corporation. All rights reserved.
4  * Licensed under the MIT License. See License.txt in the project root for license information.
5  * ------------------------------------------------------------------------------------------ */
6 Object.defineProperty(exports, "__esModule", { value: true });
7 exports.isResponseMessage = exports.isNotificationMessage = exports.isRequestMessage = exports.NotificationType9 = exports.NotificationType8 = exports.NotificationType7 = exports.NotificationType6 = exports.NotificationType5 = exports.NotificationType4 = exports.NotificationType3 = exports.NotificationType2 = exports.NotificationType1 = exports.NotificationType0 = exports.NotificationType = exports.RequestType9 = exports.RequestType8 = exports.RequestType7 = exports.RequestType6 = exports.RequestType5 = exports.RequestType4 = exports.RequestType3 = exports.RequestType2 = exports.RequestType1 = exports.RequestType = exports.RequestType0 = exports.AbstractMessageSignature = exports.ParameterStructures = exports.ResponseError = exports.ErrorCodes = void 0;
8 const is = require("./is");
9 /**
10  * Predefined error codes.
11  */
12 var ErrorCodes;
13 (function (ErrorCodes) {
14     // Defined by JSON RPC
15     ErrorCodes.ParseError = -32700;
16     ErrorCodes.InvalidRequest = -32600;
17     ErrorCodes.MethodNotFound = -32601;
18     ErrorCodes.InvalidParams = -32602;
19     ErrorCodes.InternalError = -32603;
20     /**
21      * This is the start range of JSON RPC reserved error codes.
22      * It doesn't denote a real error code. No application error codes should
23      * be defined between the start and end range. For backwards
24      * compatibility the `ServerNotInitialized` and the `UnknownErrorCode`
25      * are left in the range.
26      *
27      * @since 3.16.0
28     */
29     ErrorCodes.jsonrpcReservedErrorRangeStart = -32099;
30     /** @deprecated use  jsonrpcReservedErrorRangeStart */
31     ErrorCodes.serverErrorStart = ErrorCodes.jsonrpcReservedErrorRangeStart;
32     ErrorCodes.MessageWriteError = -32099;
33     ErrorCodes.MessageReadError = -32098;
34     ErrorCodes.ServerNotInitialized = -32002;
35     ErrorCodes.UnknownErrorCode = -32001;
36     /**
37      * This is the end range of JSON RPC reserved error codes.
38      * It doesn't denote a real error code.
39      *
40      * @since 3.16.0
41     */
42     ErrorCodes.jsonrpcReservedErrorRangeEnd = -32000;
43     /** @deprecated use  jsonrpcReservedErrorRangeEnd */
44     ErrorCodes.serverErrorEnd = ErrorCodes.jsonrpcReservedErrorRangeEnd;
45 })(ErrorCodes = exports.ErrorCodes || (exports.ErrorCodes = {}));
46 /**
47  * An error object return in a response in case a request
48  * has failed.
49  */
50 class ResponseError extends Error {
51     constructor(code, message, data) {
52         super(message);
53         this.code = is.number(code) ? code : ErrorCodes.UnknownErrorCode;
54         this.data = data;
55         Object.setPrototypeOf(this, ResponseError.prototype);
56     }
57     toJson() {
58         return {
59             code: this.code,
60             message: this.message,
61             data: this.data,
62         };
63     }
64 }
65 exports.ResponseError = ResponseError;
66 class ParameterStructures {
67     constructor(kind) {
68         this.kind = kind;
69     }
70     static is(value) {
71         return value === ParameterStructures.auto || value === ParameterStructures.byName || value === ParameterStructures.byPosition;
72     }
73     toString() {
74         return this.kind;
75     }
76 }
77 exports.ParameterStructures = ParameterStructures;
78 /**
79  * The parameter structure is automatically inferred on the number of parameters
80  * and the parameter type in case of a single param.
81  */
82 ParameterStructures.auto = new ParameterStructures('auto');
83 /**
84  * Forces `byPosition` parameter structure. This is useful if you have a single
85  * parameter which has a literal type.
86  */
87 ParameterStructures.byPosition = new ParameterStructures('byPosition');
88 /**
89  * Forces `byName` parameter structure. This is only useful when having a single
90  * parameter. The library will report errors if used with a different number of
91  * parameters.
92  */
93 ParameterStructures.byName = new ParameterStructures('byName');
94 /**
95  * An abstract implementation of a MessageType.
96  */
97 class AbstractMessageSignature {
98     constructor(method, numberOfParams) {
99         this.method = method;
100         this.numberOfParams = numberOfParams;
101     }
102     get parameterStructures() {
103         return ParameterStructures.auto;
104     }
105 }
106 exports.AbstractMessageSignature = AbstractMessageSignature;
107 /**
108  * Classes to type request response pairs
109  */
110 class RequestType0 extends AbstractMessageSignature {
111     constructor(method) {
112         super(method, 0);
113     }
114 }
115 exports.RequestType0 = RequestType0;
116 class RequestType extends AbstractMessageSignature {
117     constructor(method, _parameterStructures = ParameterStructures.auto) {
118         super(method, 1);
119         this._parameterStructures = _parameterStructures;
120     }
121     get parameterStructures() {
122         return this._parameterStructures;
123     }
124 }
125 exports.RequestType = RequestType;
126 class RequestType1 extends AbstractMessageSignature {
127     constructor(method, _parameterStructures = ParameterStructures.auto) {
128         super(method, 1);
129         this._parameterStructures = _parameterStructures;
130     }
131     get parameterStructures() {
132         return this._parameterStructures;
133     }
134 }
135 exports.RequestType1 = RequestType1;
136 class RequestType2 extends AbstractMessageSignature {
137     constructor(method) {
138         super(method, 2);
139     }
140 }
141 exports.RequestType2 = RequestType2;
142 class RequestType3 extends AbstractMessageSignature {
143     constructor(method) {
144         super(method, 3);
145     }
146 }
147 exports.RequestType3 = RequestType3;
148 class RequestType4 extends AbstractMessageSignature {
149     constructor(method) {
150         super(method, 4);
151     }
152 }
153 exports.RequestType4 = RequestType4;
154 class RequestType5 extends AbstractMessageSignature {
155     constructor(method) {
156         super(method, 5);
157     }
158 }
159 exports.RequestType5 = RequestType5;
160 class RequestType6 extends AbstractMessageSignature {
161     constructor(method) {
162         super(method, 6);
163     }
164 }
165 exports.RequestType6 = RequestType6;
166 class RequestType7 extends AbstractMessageSignature {
167     constructor(method) {
168         super(method, 7);
169     }
170 }
171 exports.RequestType7 = RequestType7;
172 class RequestType8 extends AbstractMessageSignature {
173     constructor(method) {
174         super(method, 8);
175     }
176 }
177 exports.RequestType8 = RequestType8;
178 class RequestType9 extends AbstractMessageSignature {
179     constructor(method) {
180         super(method, 9);
181     }
182 }
183 exports.RequestType9 = RequestType9;
184 class NotificationType extends AbstractMessageSignature {
185     constructor(method, _parameterStructures = ParameterStructures.auto) {
186         super(method, 1);
187         this._parameterStructures = _parameterStructures;
188     }
189     get parameterStructures() {
190         return this._parameterStructures;
191     }
192 }
193 exports.NotificationType = NotificationType;
194 class NotificationType0 extends AbstractMessageSignature {
195     constructor(method) {
196         super(method, 0);
197     }
198 }
199 exports.NotificationType0 = NotificationType0;
200 class NotificationType1 extends AbstractMessageSignature {
201     constructor(method, _parameterStructures = ParameterStructures.auto) {
202         super(method, 1);
203         this._parameterStructures = _parameterStructures;
204     }
205     get parameterStructures() {
206         return this._parameterStructures;
207     }
208 }
209 exports.NotificationType1 = NotificationType1;
210 class NotificationType2 extends AbstractMessageSignature {
211     constructor(method) {
212         super(method, 2);
213     }
214 }
215 exports.NotificationType2 = NotificationType2;
216 class NotificationType3 extends AbstractMessageSignature {
217     constructor(method) {
218         super(method, 3);
219     }
220 }
221 exports.NotificationType3 = NotificationType3;
222 class NotificationType4 extends AbstractMessageSignature {
223     constructor(method) {
224         super(method, 4);
225     }
226 }
227 exports.NotificationType4 = NotificationType4;
228 class NotificationType5 extends AbstractMessageSignature {
229     constructor(method) {
230         super(method, 5);
231     }
232 }
233 exports.NotificationType5 = NotificationType5;
234 class NotificationType6 extends AbstractMessageSignature {
235     constructor(method) {
236         super(method, 6);
237     }
238 }
239 exports.NotificationType6 = NotificationType6;
240 class NotificationType7 extends AbstractMessageSignature {
241     constructor(method) {
242         super(method, 7);
243     }
244 }
245 exports.NotificationType7 = NotificationType7;
246 class NotificationType8 extends AbstractMessageSignature {
247     constructor(method) {
248         super(method, 8);
249     }
250 }
251 exports.NotificationType8 = NotificationType8;
252 class NotificationType9 extends AbstractMessageSignature {
253     constructor(method) {
254         super(method, 9);
255     }
256 }
257 exports.NotificationType9 = NotificationType9;
258 /**
259  * Tests if the given message is a request message
260  */
261 function isRequestMessage(message) {
262     const candidate = message;
263     return candidate && is.string(candidate.method) && (is.string(candidate.id) || is.number(candidate.id));
264 }
265 exports.isRequestMessage = isRequestMessage;
266 /**
267  * Tests if the given message is a notification message
268  */
269 function isNotificationMessage(message) {
270     const candidate = message;
271     return candidate && is.string(candidate.method) && message.id === void 0;
272 }
273 exports.isNotificationMessage = isNotificationMessage;
274 /**
275  * Tests if the given message is a response message
276  */
277 function isResponseMessage(message) {
278     const candidate = message;
279     return candidate && (candidate.result !== void 0 || !!candidate.error) && (is.string(candidate.id) || is.number(candidate.id) || candidate.id === null);
280 }
281 exports.isResponseMessage = isResponseMessage;
282 //# sourceMappingURL=messages.js.map