UNPKG

vscode-jsonrpc

Version:
81 lines 2.91 kB
/* -------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. * ------------------------------------------------------------------------------------------ */ 'use strict'; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var is = require('./is'); /** * Predefined error codes. */ var ErrorCodes; (function (ErrorCodes) { // Defined by JSON RPC ErrorCodes.ParseError = -32700; ErrorCodes.InvalidRequest = -32600; ErrorCodes.MethodNotFound = -32601; ErrorCodes.InvalidParams = -32602; ErrorCodes.InternalError = -32603; ErrorCodes.serverErrorStart = -32099; ErrorCodes.serverErrorEnd = -32000; // Defined by VSCode. ErrorCodes.MessageWriteError = 1; ErrorCodes.MessageReadError = 2; })(ErrorCodes = exports.ErrorCodes || (exports.ErrorCodes = {})); /** * A error object return in a response in case a request * has failed. */ var ResponseError = (function (_super) { __extends(ResponseError, _super); function ResponseError(code, message, data) { _super.call(this, message); this.code = code; this.message = message; if (is.defined(data)) { this.data = data; } } ResponseError.prototype.toJson = function () { var result = { code: this.code, message: this.message }; if (is.defined(this.data)) { result.data = this.data; } ; return result; }; return ResponseError; }(Error)); exports.ResponseError = ResponseError; /** * Tests if the given message is a request message */ function isRequestMessage(message) { var candidate = message; return candidate && is.string(candidate.method) && (is.string(candidate.id) || is.number(candidate.id)); } exports.isRequestMessage = isRequestMessage; /** * Tests if the given message is a notification message */ function isNotificationMessage(message) { var candidate = message; return candidate && is.string(candidate.method) && is.undefined(message.id); } exports.isNotificationMessage = isNotificationMessage; /** * Tests if the given message is a response message */ function isReponseMessage(message) { var candidate = message; return candidate && (is.defined(candidate.result) || is.defined(candidate.error)) && (is.string(candidate.id) || is.number(candidate.id)); } exports.isReponseMessage = isReponseMessage; //# sourceMappingURL=messages.js.map