@eclipse-glsp/protocol
Advanced tools
Comparing version 0.9.0-next.9793bf31 to 0.9.0-next.9ac2fc1e
@@ -45,4 +45,4 @@ /******************************************************************************** | ||
/** | ||
* GLSP protocol version that the server is implementing. | ||
*/ | ||
* GLSP protocol version that the server is implementing. | ||
*/ | ||
protocolVersion: string; | ||
@@ -77,4 +77,4 @@ /** | ||
/** | ||
* Additional custom arguments. | ||
*/ | ||
* Additional custom arguments. | ||
*/ | ||
args?: Args; | ||
@@ -81,0 +81,0 @@ } |
"use strict"; | ||
/******************************************************************************** | ||
* Copyright (c) 2020-2021 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GLSPClient = exports.ClientState = exports.ApplicationIdProvider = void 0; | ||
var uuid = require("uuid"); | ||
var ApplicationIdProvider = /** @class */ (function () { | ||
function ApplicationIdProvider() { | ||
} | ||
ApplicationIdProvider.get = function () { | ||
const uuid = require("uuid"); | ||
class ApplicationIdProvider { | ||
static get() { | ||
if (!ApplicationIdProvider._applicationId) { | ||
@@ -13,6 +27,6 @@ ApplicationIdProvider._applicationId = uuid.v4(); | ||
return ApplicationIdProvider._applicationId; | ||
}; | ||
return ApplicationIdProvider; | ||
}()); | ||
} | ||
} | ||
exports.ApplicationIdProvider = ApplicationIdProvider; | ||
// eslint-disable-next-line no-shadow | ||
var ClientState; | ||
@@ -51,4 +65,5 @@ (function (ClientState) { | ||
(function (GLSPClient) { | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
function isOptions(object) { | ||
return object !== undefined && 'id' in object && typeof object['id'] === 'string'; | ||
return typeof object === 'object' && 'id' in object && typeof object['id'] === 'string'; | ||
} | ||
@@ -55,0 +70,0 @@ GLSPClient.isOptions = isOptions; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseJsonrpcGLSPClient = void 0; | ||
var glsp_client_1 = require("../glsp-client"); | ||
var glsp_jsonrpc_client_1 = require("./glsp-jsonrpc-client"); | ||
var BaseJsonrpcGLSPClient = /** @class */ (function () { | ||
function BaseJsonrpcGLSPClient(options) { | ||
const glsp_client_1 = require("../glsp-client"); | ||
const glsp_jsonrpc_client_1 = require("./glsp-jsonrpc-client"); | ||
class BaseJsonrpcGLSPClient { | ||
constructor(options) { | ||
Object.assign(this, options); | ||
this.state = glsp_client_1.ClientState.Initial; | ||
} | ||
BaseJsonrpcGLSPClient.prototype.shutdownServer = function () { | ||
shutdownServer() { | ||
if (this.checkConnectionState()) { | ||
this.resolvedConnection.sendNotification(glsp_jsonrpc_client_1.JsonrpcGLSPClient.ShutdownNotification); | ||
} | ||
}; | ||
BaseJsonrpcGLSPClient.prototype.initializeServer = function (params) { | ||
} | ||
initializeServer(params) { | ||
if (this.checkConnectionState()) { | ||
@@ -57,4 +21,4 @@ return this.resolvedConnection.sendRequest(glsp_jsonrpc_client_1.JsonrpcGLSPClient.InitializeRequest, params); | ||
return Promise.reject(glsp_jsonrpc_client_1.JsonrpcGLSPClient.ClientNotReadyMsg); | ||
}; | ||
BaseJsonrpcGLSPClient.prototype.initializeClientSession = function (params) { | ||
} | ||
initializeClientSession(params) { | ||
if (this.checkConnectionState()) { | ||
@@ -64,4 +28,4 @@ return this.resolvedConnection.sendRequest(glsp_jsonrpc_client_1.JsonrpcGLSPClient.InitializeClientSessionRequest, params); | ||
return Promise.reject(glsp_jsonrpc_client_1.JsonrpcGLSPClient.ClientNotReadyMsg); | ||
}; | ||
BaseJsonrpcGLSPClient.prototype.disposeClientSession = function (params) { | ||
} | ||
disposeClientSession(params) { | ||
if (this.checkConnectionState()) { | ||
@@ -71,14 +35,14 @@ return this.resolvedConnection.sendRequest(glsp_jsonrpc_client_1.JsonrpcGLSPClient.DisposeClientSessionRequest, params); | ||
return Promise.reject(glsp_jsonrpc_client_1.JsonrpcGLSPClient.ClientNotReadyMsg); | ||
}; | ||
BaseJsonrpcGLSPClient.prototype.onActionMessage = function (handler) { | ||
} | ||
onActionMessage(handler) { | ||
if (this.checkConnectionState()) { | ||
this.resolvedConnection.onNotification(glsp_jsonrpc_client_1.JsonrpcGLSPClient.ActionMessageNotification, handler); | ||
} | ||
}; | ||
BaseJsonrpcGLSPClient.prototype.sendActionMessage = function (message) { | ||
} | ||
sendActionMessage(message) { | ||
if (this.checkConnectionState()) { | ||
this.resolvedConnection.sendNotification(glsp_jsonrpc_client_1.JsonrpcGLSPClient.ActionMessageNotification, message); | ||
} | ||
}; | ||
BaseJsonrpcGLSPClient.prototype.checkConnectionState = function () { | ||
} | ||
checkConnectionState() { | ||
if (!this.isConnectionActive()) { | ||
@@ -88,30 +52,17 @@ throw new Error(glsp_jsonrpc_client_1.JsonrpcGLSPClient.ClientNotReadyMsg); | ||
return true; | ||
}; | ||
BaseJsonrpcGLSPClient.prototype.start = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var connection, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
this.state = glsp_client_1.ClientState.Starting; | ||
return [4 /*yield*/, this.resolveConnection()]; | ||
case 1: | ||
connection = _a.sent(); | ||
connection.listen(); | ||
this.resolvedConnection = connection; | ||
this.state = glsp_client_1.ClientState.Running; | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
error_1 = _a.sent(); | ||
glsp_jsonrpc_client_1.JsonrpcGLSPClient.error('Failed to start connection to server', error_1); | ||
this.state = glsp_client_1.ClientState.StartFailed; | ||
return [3 /*break*/, 3]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
BaseJsonrpcGLSPClient.prototype.stop = function () { | ||
var _this = this; | ||
} | ||
async start() { | ||
try { | ||
this.state = glsp_client_1.ClientState.Starting; | ||
const connection = await this.resolveConnection(); | ||
connection.listen(); | ||
this.resolvedConnection = connection; | ||
this.state = glsp_client_1.ClientState.Running; | ||
} | ||
catch (error) { | ||
glsp_jsonrpc_client_1.JsonrpcGLSPClient.error('Failed to start connection to server', error); | ||
this.state = glsp_client_1.ClientState.StartFailed; | ||
} | ||
} | ||
stop() { | ||
if (!this.connectionPromise) { | ||
@@ -125,11 +76,11 @@ this.state = glsp_client_1.ClientState.Stopped; | ||
this.state = glsp_client_1.ClientState.Stopping; | ||
return this.onStop = this.resolveConnection().then(function (connection) { | ||
return (this.onStop = this.resolveConnection().then(connection => { | ||
connection.dispose(); | ||
_this.state = glsp_client_1.ClientState.Stopped; | ||
_this.onStop = undefined; | ||
_this.connectionPromise = undefined; | ||
_this.resolvedConnection = undefined; | ||
}); | ||
}; | ||
BaseJsonrpcGLSPClient.prototype.resolveConnection = function () { | ||
this.state = glsp_client_1.ClientState.Stopped; | ||
this.onStop = undefined; | ||
this.connectionPromise = undefined; | ||
this.resolvedConnection = undefined; | ||
})); | ||
} | ||
resolveConnection() { | ||
if (!this.connectionPromise) { | ||
@@ -139,33 +90,15 @@ this.connectionPromise = this.doCreateConnection(); | ||
return this.connectionPromise; | ||
}; | ||
BaseJsonrpcGLSPClient.prototype.doCreateConnection = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var connection, _a; | ||
var _this = this; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!(typeof this.connectionProvider === 'function')) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.connectionProvider()]; | ||
case 1: | ||
_a = _b.sent(); | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
_a = this.connectionProvider; | ||
_b.label = 3; | ||
case 3: | ||
connection = _a; | ||
connection.onError(function (data) { return _this.handleConnectionError(data[0], data[1], data[2]); }); | ||
connection.onClose(function () { return _this.handleConnectionClosed(); }); | ||
return [2 /*return*/, connection]; | ||
} | ||
}); | ||
}); | ||
}; | ||
BaseJsonrpcGLSPClient.prototype.handleConnectionError = function (error, message, count) { | ||
} | ||
async doCreateConnection() { | ||
const connection = typeof this.connectionProvider === 'function' ? await this.connectionProvider() : this.connectionProvider; | ||
connection.onError((data) => this.handleConnectionError(data[0], data[1], data[2])); | ||
connection.onClose(() => this.handleConnectionClosed()); | ||
return connection; | ||
} | ||
handleConnectionError(error, message, count) { | ||
glsp_jsonrpc_client_1.JsonrpcGLSPClient.error('Connection to server is erroring. Shutting down server.', error); | ||
this.stop(); | ||
this.state = glsp_client_1.ClientState.ServerError; | ||
}; | ||
BaseJsonrpcGLSPClient.prototype.handleConnectionClosed = function () { | ||
} | ||
handleConnectionClosed() { | ||
if (this.state === glsp_client_1.ClientState.Stopping || this.state === glsp_client_1.ClientState.Stopped) { | ||
@@ -186,16 +119,11 @@ return; | ||
this.state = glsp_client_1.ClientState.ServerError; | ||
}; | ||
BaseJsonrpcGLSPClient.prototype.isConnectionActive = function () { | ||
} | ||
isConnectionActive() { | ||
return this.state === glsp_client_1.ClientState.Running && !!this.resolvedConnection; | ||
}; | ||
Object.defineProperty(BaseJsonrpcGLSPClient.prototype, "currentState", { | ||
get: function () { | ||
return this.state; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return BaseJsonrpcGLSPClient; | ||
}()); | ||
} | ||
get currentState() { | ||
return this.state; | ||
} | ||
} | ||
exports.BaseJsonrpcGLSPClient = BaseJsonrpcGLSPClient; | ||
//# sourceMappingURL=base-jsonrpc-glsp-client.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.JsonrpcGLSPClient = void 0; | ||
var vscode_jsonrpc_1 = require("vscode-jsonrpc"); | ||
var vscode_ws_jsonrpc_1 = require("vscode-ws-jsonrpc"); | ||
var glsp_client_1 = require("../glsp-client"); | ||
const vscode_jsonrpc_1 = require("vscode-jsonrpc"); | ||
const vscode_ws_jsonrpc_1 = require("vscode-ws-jsonrpc"); | ||
const glsp_client_1 = require("../glsp-client"); | ||
var JsonrpcGLSPClient; | ||
(function (JsonrpcGLSPClient) { | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
function isOptions(object) { | ||
@@ -20,14 +21,10 @@ return glsp_client_1.GLSPClient.isOptions(object) && 'connectionProvider' in object; | ||
function createWebsocketConnectionProvider(websocket, logger) { | ||
var socket = vscode_ws_jsonrpc_1.toSocket(websocket); | ||
var reader = new vscode_ws_jsonrpc_1.WebSocketMessageReader(socket); | ||
var writer = new vscode_ws_jsonrpc_1.WebSocketMessageWriter(socket); | ||
const socket = vscode_ws_jsonrpc_1.toSocket(websocket); | ||
const reader = new vscode_ws_jsonrpc_1.WebSocketMessageReader(socket); | ||
const writer = new vscode_ws_jsonrpc_1.WebSocketMessageWriter(socket); | ||
return vscode_ws_jsonrpc_1.createMessageConnection(reader, writer, logger); | ||
} | ||
JsonrpcGLSPClient.createWebsocketConnectionProvider = createWebsocketConnectionProvider; | ||
function error(message) { | ||
var optionalParams = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
optionalParams[_i - 1] = arguments[_i]; | ||
} | ||
console.error("[JsonrpcGLSPClient] " + message, optionalParams); | ||
function error(message, ...optionalParams) { | ||
console.error(`[JsonrpcGLSPClient] ${message}`, optionalParams); | ||
} | ||
@@ -34,0 +31,0 @@ JsonrpcGLSPClient.error = error; |
/******************************************************************************** | ||
* Copyright (c) 2020 EclipseSource and others. | ||
* Copyright (c) 2020-2021 EclipseSource and others. | ||
* | ||
@@ -4,0 +4,0 @@ * This program and the accompanying materials are made available under the |
"use strict"; | ||
/******************************************************************************** | ||
* Copyright (c) 2020 EclipseSource and others. | ||
* Copyright (c) 2020-2021 EclipseSource and others. | ||
* | ||
@@ -25,4 +25,4 @@ * This program and the accompanying materials are made available under the | ||
function getPort(argsKey, defaultPort) { | ||
argsKey = "--" + argsKey.replace('--', '').replace('=', '') + "="; | ||
var args = process.argv.filter(function (a) { return a.startsWith(argsKey); }); | ||
argsKey = `--${argsKey.replace('--', '').replace('=', '')}=`; | ||
const args = process.argv.filter(a => a.startsWith(argsKey)); | ||
if (args.length > 0) { | ||
@@ -29,0 +29,0 @@ return Number.parseInt(args[0].substring(argsKey.length), 10); |
{ | ||
"name": "@eclipse-glsp/protocol", | ||
"version": "0.9.0-next.9793bf31", | ||
"version": "0.9.0-next.9ac2fc1e", | ||
"description": "The protocol definition for client-server communication in GLSP", | ||
@@ -5,0 +5,0 @@ "license": "(EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0)", |
@@ -16,2 +16,4 @@ /******************************************************************************** | ||
********************************************************************************/ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
import { ActionMessage } from 'sprotty'; | ||
@@ -23,3 +25,5 @@ import * as uuid from 'uuid'; | ||
*/ | ||
export interface Args { [key: string]: string | number | boolean } | ||
export interface Args { | ||
[key: string]: string | number | boolean; | ||
} | ||
@@ -29,3 +33,5 @@ /** | ||
*/ | ||
export interface ServerActions { [key: string]: string[] } | ||
export interface ServerActions { | ||
[key: string]: string[]; | ||
} | ||
@@ -50,6 +56,5 @@ export interface InitializeParameters { | ||
export interface InitializeResult { | ||
/** | ||
* GLSP protocol version that the server is implementing. | ||
*/ | ||
* GLSP protocol version that the server is implementing. | ||
*/ | ||
protocolVersion: string; | ||
@@ -90,4 +95,4 @@ | ||
/** | ||
* Additional custom arguments. | ||
*/ | ||
* Additional custom arguments. | ||
*/ | ||
args?: Args; | ||
@@ -108,2 +113,3 @@ } | ||
// eslint-disable-next-line no-shadow | ||
export enum ClientState { | ||
@@ -219,4 +225,5 @@ /** | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
export function isOptions(object: any): object is Options { | ||
return object !== undefined && 'id' in object && typeof object['id'] === 'string'; | ||
return typeof object === 'object' && 'id' in object && typeof object['id'] === 'string'; | ||
} | ||
@@ -223,0 +230,0 @@ |
@@ -31,3 +31,2 @@ /******************************************************************************** | ||
export class BaseJsonrpcGLSPClient implements GLSPClient { | ||
readonly id: string; | ||
@@ -113,3 +112,3 @@ protected readonly connectionProvider: ConnectionProvider; | ||
this.state = ClientState.Stopping; | ||
return this.onStop = this.resolveConnection().then(connection => { | ||
return (this.onStop = this.resolveConnection().then(connection => { | ||
connection.dispose(); | ||
@@ -120,3 +119,3 @@ this.state = ClientState.Stopped; | ||
this.resolvedConnection = undefined; | ||
}); | ||
})); | ||
} | ||
@@ -123,0 +122,0 @@ |
@@ -26,3 +26,2 @@ /******************************************************************************** | ||
} from 'vscode-ws-jsonrpc'; | ||
import { | ||
@@ -44,2 +43,3 @@ DisposeClientSessionParameters, | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
export function isOptions(object: any): object is Options { | ||
@@ -51,3 +51,5 @@ return GLSPClient.isOptions(object) && 'connectionProvider' in object; | ||
export const InitializeRequest = new RequestType<InitializeParameters, InitializeResult, void, void>('initialize'); | ||
export const InitializeClientSessionRequest = new RequestType<InitializeClientSessionParameters, void, void, void>('initializeClientSession'); | ||
export const InitializeClientSessionRequest = new RequestType<InitializeClientSessionParameters, void, void, void>( | ||
'initializeClientSession' | ||
); | ||
export const DisposeClientSessionRequest = new RequestType<DisposeClientSessionParameters, void, void, void>('disposeClientSession'); | ||
@@ -54,0 +56,0 @@ |
/******************************************************************************** | ||
* Copyright (c) 2020 EclipseSource and others. | ||
* Copyright (c) 2020-2021 EclipseSource and others. | ||
* | ||
@@ -30,2 +30,1 @@ * This program and the accompanying materials are made available under the | ||
} | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
73647
1039