@eclipse-glsp/server 1.1.0-next.44aae0c.44 → 1.1.0-next.5c40594.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/lib/browser/launch/worker-server-launcher.d.ts +8 -5
  2. package/lib/browser/launch/worker-server-launcher.d.ts.map +1 -1
  3. package/lib/browser/launch/worker-server-launcher.js +9 -11
  4. package/lib/browser/launch/worker-server-launcher.js.map +1 -1
  5. package/lib/common/command/recording-command.d.ts +7 -7
  6. package/lib/common/command/recording-command.d.ts.map +1 -1
  7. package/lib/common/command/recording-command.js +6 -6
  8. package/lib/common/command/recording-command.js.map +1 -1
  9. package/lib/common/features/layout/computed-bounds-action-handler.js +1 -1
  10. package/lib/common/features/layout/computed-bounds-action-handler.js.map +1 -1
  11. package/lib/common/index.d.ts +3 -1
  12. package/lib/common/index.d.ts.map +1 -1
  13. package/lib/common/index.js +3 -1
  14. package/lib/common/index.js.map +1 -1
  15. package/lib/common/launch/glsp-server-launcher.d.ts +7 -6
  16. package/lib/common/launch/glsp-server-launcher.d.ts.map +1 -1
  17. package/lib/common/launch/glsp-server-launcher.js +25 -2
  18. package/lib/common/launch/glsp-server-launcher.js.map +1 -1
  19. package/lib/common/utils/layout-util.d.ts +1 -1
  20. package/lib/common/utils/layout-util.d.ts.map +1 -1
  21. package/lib/common/utils/layout-util.js +3 -3
  22. package/lib/common/utils/layout-util.js.map +1 -1
  23. package/lib/node/index.d.ts +1 -0
  24. package/lib/node/index.d.ts.map +1 -1
  25. package/lib/node/index.js +1 -0
  26. package/lib/node/index.js.map +1 -1
  27. package/lib/node/launch/socket-server-launcher.d.ts +2 -1
  28. package/lib/node/launch/socket-server-launcher.d.ts.map +1 -1
  29. package/lib/node/launch/socket-server-launcher.js +11 -10
  30. package/lib/node/launch/socket-server-launcher.js.map +1 -1
  31. package/lib/node/launch/websocket-server-launcher.d.ts +59 -0
  32. package/lib/node/launch/websocket-server-launcher.d.ts.map +1 -0
  33. package/lib/node/launch/websocket-server-launcher.js +145 -0
  34. package/lib/node/launch/websocket-server-launcher.js.map +1 -0
  35. package/package.json +7 -5
  36. package/src/browser/launch/worker-server-launcher.ts +16 -12
  37. package/src/common/command/recording-command.ts +11 -11
  38. package/src/common/features/layout/computed-bounds-action-handler.ts +2 -2
  39. package/src/common/index.ts +3 -1
  40. package/src/common/launch/glsp-server-launcher.ts +13 -7
  41. package/src/common/utils/layout-util.ts +1 -1
  42. package/src/node/index.ts +1 -0
  43. package/src/node/launch/socket-server-launcher.ts +13 -7
  44. package/src/node/launch/websocket-server-launcher.ts +164 -0
@@ -0,0 +1,59 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2023 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+ /// <reference types="node" />
17
+ import { MaybePromise, WebSocketWrapper } from '@eclipse-glsp/protocol';
18
+ import * as http from 'http';
19
+ import { Container } from 'inversify';
20
+ import * as jsonrpc from 'vscode-jsonrpc';
21
+ import { Server, WebSocket } from 'ws';
22
+ import { GLSPServerLauncher } from '../../common/launch/glsp-server-launcher';
23
+ import { GLSPServer } from '../../common/protocol/glsp-server';
24
+ import { Logger } from '../../common/utils/logger';
25
+ export interface WebSocketServerOptions {
26
+ host?: string;
27
+ port?: number;
28
+ path: string;
29
+ }
30
+ export interface ResolvedWebSocketServerOptions {
31
+ host?: string;
32
+ port: number;
33
+ path: string;
34
+ server: http.Server;
35
+ }
36
+ export interface WebsocketConnectionData {
37
+ socket: WebSocket;
38
+ connection: jsonrpc.MessageConnection;
39
+ }
40
+ export declare class WebSocketServerLauncher extends GLSPServerLauncher<WebSocketServerOptions> {
41
+ protected logger: Logger;
42
+ protected server: Server;
43
+ protected startupCompleteMessage: string;
44
+ protected currentConnections: jsonrpc.MessageConnection[];
45
+ constructor();
46
+ protected run(options: WebSocketServerOptions): Promise<void>;
47
+ protected createClientConnection(socket: WebSocket): Promise<void>;
48
+ protected disposeClientConnection(container: Container, glspServer: GLSPServer): void;
49
+ protected createConnection(socket: WebSocket): jsonrpc.MessageConnection;
50
+ protected resolveOptions(options: WebSocketServerOptions): Promise<ResolvedWebSocketServerOptions>;
51
+ protected createHttpServer(port: number, host?: string): http.Server;
52
+ start(options: WebSocketServerOptions): MaybePromise<void>;
53
+ }
54
+ /**
55
+ * Creates a {@link WebSocketWrapper} for the given plain WebSocket
56
+ * @param socket The socket to wrap
57
+ */
58
+ export declare function wrapWebSocket(socket: WebSocket): WebSocketWrapper;
59
+ //# sourceMappingURL=websocket-server-launcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-server-launcher.d.ts","sourceRoot":"","sources":["../../../src/node/launch/websocket-server-launcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;;AAElF,OAAO,EAAyC,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/G,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAsB,MAAM,WAAW,CAAC;AAE1D,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAqB,MAAM,mCAAmC,CAAC;AAClF,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2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wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,gBAAgB,CAQjE"}
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ /********************************************************************************
3
+ * Copyright (c) 2023 EclipseSource and others.
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the Eclipse Public License v. 2.0 which is available at
7
+ * http://www.eclipse.org/legal/epl-2.0.
8
+ *
9
+ * This Source Code may also be made available under the following Secondary
10
+ * Licenses when the conditions for such availability set forth in the Eclipse
11
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ * with the GNU Classpath Exception which is available at
13
+ * https://www.gnu.org/software/classpath/license.html.
14
+ *
15
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
+ ********************************************************************************/
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __metadata = (this && this.__metadata) || function (k, v) {
24
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.wrapWebSocket = exports.WebSocketServerLauncher = void 0;
28
+ const protocol_1 = require("@eclipse-glsp/protocol");
29
+ const http = require("http");
30
+ const inversify_1 = require("inversify");
31
+ const net = require("net");
32
+ const ws_1 = require("ws");
33
+ const glsp_server_launcher_1 = require("../../common/launch/glsp-server-launcher");
34
+ const glsp_server_1 = require("../../common/protocol/glsp-server");
35
+ const logger_1 = require("../../common/utils/logger");
36
+ const socket_server_launcher_1 = require("./socket-server-launcher");
37
+ const STATUS_UPGRADE_REQUIRED = 426;
38
+ let WebSocketServerLauncher = class WebSocketServerLauncher extends glsp_server_launcher_1.GLSPServerLauncher {
39
+ constructor() {
40
+ super();
41
+ this.startupCompleteMessage = socket_server_launcher_1.START_UP_COMPLETE_MSG;
42
+ this.currentConnections = [];
43
+ this.toDispose.push(protocol_1.Disposable.create(() => {
44
+ this.currentConnections.forEach(connection => connection.dispose());
45
+ this.server.close();
46
+ }));
47
+ }
48
+ async run(options) {
49
+ const resolvedOptions = await this.resolveOptions(options);
50
+ this.server = new ws_1.Server({ server: resolvedOptions.server, path: resolvedOptions.path });
51
+ const endpoint = `ws://${resolvedOptions.host}:${resolvedOptions.port}:${resolvedOptions.path}`;
52
+ this.logger.info(`The GLSP Websocket launcher is ready to accept new client requests on endpoint '${endpoint}'`);
53
+ console.log(this.startupCompleteMessage.concat(resolvedOptions.port.toString()));
54
+ this.server.on('connection', (ws, req) => {
55
+ this.createClientConnection(ws);
56
+ });
57
+ return new Promise((resolve, reject) => {
58
+ this.server.on('close', () => resolve(undefined));
59
+ this.server.on('error', error => reject(error));
60
+ });
61
+ }
62
+ async createClientConnection(socket) {
63
+ const container = this.createContainer();
64
+ const connection = this.createConnection(socket);
65
+ this.currentConnections.push(connection);
66
+ const glspServer = container.get(glsp_server_1.JsonRpcGLSPServer);
67
+ glspServer.connect(connection);
68
+ this.logger.info('Starting GLSP server connection');
69
+ connection.listen();
70
+ connection.onDispose(() => this.disposeClientConnection(container, glspServer));
71
+ socket.on('close', () => this.disposeClientConnection(container, glspServer));
72
+ connection.onClose(() => console.log('GOD dam'));
73
+ return new Promise((resolve, rejects) => {
74
+ connection.onClose(() => resolve(undefined));
75
+ connection.onError(error => rejects(error));
76
+ });
77
+ }
78
+ disposeClientConnection(container, glspServer) {
79
+ glspServer.shutdown();
80
+ container.unbindAll();
81
+ }
82
+ createConnection(socket) {
83
+ return (0, protocol_1.createWebSocketConnection)(wrapWebSocket(socket));
84
+ }
85
+ async resolveOptions(options) {
86
+ const port = !options.port || options.port === 0 ? await getFreePort() : options.port;
87
+ const path = options.path.startsWith('/') ? options.path : `/${options.path}`;
88
+ const server = this.createHttpServer(port, options.host);
89
+ return Object.assign(Object.assign({}, options), { port, path, server });
90
+ }
91
+ createHttpServer(port, host) {
92
+ const server = http.createServer((req, res) => {
93
+ const body = http.STATUS_CODES[STATUS_UPGRADE_REQUIRED];
94
+ res.writeHead(426, {
95
+ 'Content-Length': body === null || body === void 0 ? void 0 : body.length,
96
+ 'Content-Type': 'text/plain'
97
+ });
98
+ res.end(body);
99
+ });
100
+ server.listen(port, host);
101
+ // Set server timeout to infinite
102
+ server.setTimeout(0);
103
+ return server;
104
+ }
105
+ start(options) {
106
+ super.start(options);
107
+ }
108
+ };
109
+ __decorate([
110
+ (0, inversify_1.inject)(logger_1.Logger),
111
+ __metadata("design:type", logger_1.Logger)
112
+ ], WebSocketServerLauncher.prototype, "logger", void 0);
113
+ WebSocketServerLauncher = __decorate([
114
+ (0, inversify_1.injectable)(),
115
+ __metadata("design:paramtypes", [])
116
+ ], WebSocketServerLauncher);
117
+ exports.WebSocketServerLauncher = WebSocketServerLauncher;
118
+ async function getFreePort() {
119
+ return new Promise((resolve, reject) => {
120
+ const srv = net.createServer();
121
+ srv.listen(0, () => {
122
+ const address = srv.address();
123
+ if (!address || typeof address === 'string') {
124
+ reject(new Error('Could not address to compute a free port'));
125
+ return;
126
+ }
127
+ srv.close(() => resolve(address.port));
128
+ });
129
+ });
130
+ }
131
+ /**
132
+ * Creates a {@link WebSocketWrapper} for the given plain WebSocket
133
+ * @param socket The socket to wrap
134
+ */
135
+ function wrapWebSocket(socket) {
136
+ return {
137
+ send: content => socket.send(content),
138
+ onMessage: cb => socket.on('message', cb),
139
+ onClose: cb => socket.on('close', cb),
140
+ onError: cb => socket.on('error', cb),
141
+ dispose: () => socket.close()
142
+ };
143
+ }
144
+ exports.wrapWebSocket = wrapWebSocket;
145
+ //# sourceMappingURL=websocket-server-launcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-server-launcher.js","sourceRoot":"","sources":["../../../src/node/launch/websocket-server-launcher.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;;;;;;;;;;AAElF,qDAA+G;AAC/G,6BAA6B;AAC7B,yCAA0D;AAC1D,2BAA2B;AAE3B,2BAAuC;AACvC,mFAA8E;AAC9E,mEAAkF;AAClF,sDAAmD;AACnD,qEAAiE;AAoBjE,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAG7B,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ,yCAA0C;IAQnF;QACI,KAAK,EAAE,CAAC;QAJF,2BAAsB,GAAG,8CAAqB,CAAC;QAC/C,uBAAkB,GAAgC,EAAE,CAAC;QAI3D,IAAI,CAAC,SAAS,CAAC,IAAI,CACf,qBAAU,CAAC,MAAM,CAAC,GAAG,EAAE;YACnB,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;YACpE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC,CAAC,CACL,CAAC;IACN,CAAC;IAES,KAAK,CAAC,GAAG,CAAC,OAA+B;QAC/C,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAC3D,IAAI,CAAC,MAAM,GAAG,IAAI,WAAM,CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,IAAI,EAAE,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC;QACzF,MAAM,QAAQ,GAAG,QAAQ,eAAe,CAAC,IAAI,IAAI,eAAe,CAAC,IAAI,IAAI,eAAe,CAAC,IAAI,EAAE,CAAC;QAChG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mFAAmF,QAAQ,GAAG,CAAC,CAAC;QACjH,OAAO,CAAC,GAAG,CA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AI,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AACD;;;GAGG;AACH,SAAgB,aAAa,CAAC,MAAiB;IAC3C,OAAO;QACH,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QACrC,SAAS,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC;QACzC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC;QACrC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC;QACrC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE;KAChC,CAAC;AACN,CAAC;AARD,sCAQC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eclipse-glsp/server",
3
- "version": "1.1.0-next.44aae0c.44+44aae0c",
3
+ "version": "1.1.0-next.5c40594.46+5c40594",
4
4
  "description": "A js server framework for Eclipse GLSP",
5
5
  "keywords": [
6
6
  "eclipse",
@@ -59,19 +59,21 @@
59
59
  "watch": "tsc -w"
60
60
  },
61
61
  "dependencies": {
62
- "@eclipse-glsp/graph": "1.1.0-next.44aae0c.44+44aae0c",
62
+ "@eclipse-glsp/graph": "1.1.0-next.5c40594.46+5c40594",
63
63
  "@eclipse-glsp/protocol": "next",
64
64
  "@types/uuid": "8.3.1",
65
65
  "commander": "^8.3.0",
66
66
  "fast-json-patch": "^3.1.0",
67
67
  "inversify": "^5.1.1",
68
- "winston": "^3.3.3"
68
+ "winston": "^3.3.3",
69
+ "ws": "^8.12.1"
69
70
  },
70
71
  "devDependencies": {
71
- "@types/fs-extra": "^9.0.13"
72
+ "@types/fs-extra": "^9.0.13",
73
+ "@types/ws": "^8.5.4"
72
74
  },
73
75
  "publishConfig": {
74
76
  "access": "public"
75
77
  },
76
- "gitHead": "44aae0ca2380fe42eb95aac54d2d4e45e187d14f"
78
+ "gitHead": "5c40594962e16e16e56ec82d8100f45b849de315"
77
79
  }
@@ -16,24 +16,30 @@
16
16
 
17
17
  import { Container, injectable } from 'inversify';
18
18
  import * as jsonrpc from 'vscode-jsonrpc/browser';
19
- import { GLSPServer, GLSPServerLauncher, JsonRpcGLSPServer, MaybePromise, START_UP_COMPLETE_MSG } from '../../common/index';
19
+ import { GLSPServer, GLSPServerLauncher, JsonRpcGLSPServer, MaybePromise } from '../../common/index';
20
+ export interface WorkerLaunchOptions {
21
+ context?: Worker;
22
+ }
23
+
24
+ export const START_UP_COMPLETE_MSG = '[GLSP-Server]:Startup completed.';
20
25
 
21
26
  @injectable()
22
- export class WorkerServerLauncher extends GLSPServerLauncher {
23
- private connection?: jsonrpc.MessageConnection;
27
+ export class WorkerServerLauncher extends GLSPServerLauncher<WorkerLaunchOptions> {
28
+ protected connection?: jsonrpc.MessageConnection;
24
29
 
25
- protected run(): MaybePromise<void> {
30
+ protected run(options: WorkerLaunchOptions): MaybePromise<void> {
26
31
  if (this.connection) {
27
32
  throw new Error('Error during launch. Server already has an active client connection');
28
33
  }
29
34
  const container = this.createContainer();
30
- this.connection = this.createConnection();
35
+ this.connection = this.createConnection(options);
31
36
  const glspServer = container.get<JsonRpcGLSPServer>(JsonRpcGLSPServer);
32
37
  glspServer.connect(this.connection);
33
38
  this.connection.onDispose(() => this.disposeClientConnection(container, glspServer));
34
39
 
35
40
  this.logger.info('GLSP server worker connection established');
36
41
  this.connection.listen();
42
+ this.toDispose.push(this.connection);
37
43
  postMessage(START_UP_COMPLETE_MSG);
38
44
  return new Promise((resolve, rejects) => {
39
45
  this.connection?.onClose(() => resolve(undefined));
@@ -47,12 +53,10 @@ export class WorkerServerLauncher extends GLSPServerLauncher {
47
53
  this.connection = undefined;
48
54
  }
49
55
 
50
- protected stop(): MaybePromise<void> {
51
- this.logger.info('Shutdown WorkerServerLauncher');
52
- this.connection?.dispose();
53
- }
54
-
55
- protected createConnection(): jsonrpc.MessageConnection {
56
- return jsonrpc.createMessageConnection(new jsonrpc.BrowserMessageReader(self), new jsonrpc.BrowserMessageWriter(self));
56
+ protected createConnection(options: WorkerLaunchOptions): jsonrpc.MessageConnection {
57
+ return jsonrpc.createMessageConnection(
58
+ new jsonrpc.BrowserMessageReader(options.context ?? self),
59
+ new jsonrpc.BrowserMessageWriter(options.context ?? self)
60
+ );
57
61
  }
58
62
  }
@@ -29,9 +29,9 @@ export abstract class AbstractRecordingCommand<JsonObject extends AnyObject> imp
29
29
  protected redoPatch?: jsonPatch.Operation[];
30
30
 
31
31
  async execute(): Promise<void> {
32
- const beforeState = this.deepClone(this.getJsonObject());
32
+ const beforeState = this.deepClone(await this.getJsonObject());
33
33
  await this.doExecute();
34
- const afterState = this.getJsonObject();
34
+ const afterState = await this.getJsonObject();
35
35
  this.undoPatch = jsonPatch.compare(afterState, beforeState);
36
36
  this.redoPatch = jsonPatch.compare(beforeState, afterState);
37
37
  }
@@ -41,14 +41,14 @@ export abstract class AbstractRecordingCommand<JsonObject extends AnyObject> imp
41
41
  * right after {@link AbstractRecordingCommand.doExecute} to derive the undo & redo patches.
42
42
  * @returns The current state of the JSON object
43
43
  */
44
- protected abstract getJsonObject(): JsonObject;
44
+ protected abstract getJsonObject(): MaybePromise<JsonObject>;
45
45
 
46
46
  /**
47
47
  * The actual execution i.e. series of changes applied to the JSOn object that should be captured.
48
48
  */
49
49
  protected abstract doExecute(): MaybePromise<void>;
50
50
 
51
- protected applyPatch(object: JsonObject, patch: jsonPatch.Operation[]): void {
51
+ protected applyPatch(object: JsonObject, patch: jsonPatch.Operation[]): MaybePromise<void> {
52
52
  jsonPatch.applyPatch(object, patch, false, true);
53
53
  }
54
54
 
@@ -62,15 +62,15 @@ export abstract class AbstractRecordingCommand<JsonObject extends AnyObject> imp
62
62
  return jsonPatch.deepClone(object);
63
63
  }
64
64
 
65
- undo(): void {
65
+ async undo(): Promise<void> {
66
66
  if (this.undoPatch) {
67
- this.applyPatch(this.getJsonObject(), this.undoPatch);
67
+ return this.applyPatch(await this.getJsonObject(), this.undoPatch);
68
68
  }
69
69
  }
70
70
 
71
- redo(): void {
71
+ async redo(): Promise<void> {
72
72
  if (this.redoPatch) {
73
- this.applyPatch(this.getJsonObject(), this.redoPatch);
73
+ return this.applyPatch(await this.getJsonObject(), this.redoPatch);
74
74
  }
75
75
  }
76
76
 
@@ -88,7 +88,7 @@ export class RecordingCommand<JsonObject extends AnyObject = AnyObject> extends
88
88
  super();
89
89
  }
90
90
 
91
- protected getJsonObject(): JsonObject {
91
+ protected getJsonObject(): MaybePromise<JsonObject> {
92
92
  return this.jsonObject;
93
93
  }
94
94
  }
@@ -107,11 +107,11 @@ export class GModelRecordingCommand extends AbstractRecordingCommand<GModelRootS
107
107
  this.modelState.index.indexRoot(this.modelState.root);
108
108
  }
109
109
 
110
- protected getJsonObject(): GModelRootSchema {
110
+ protected getJsonObject(): MaybePromise<GModelRootSchema> {
111
111
  return this.serializer.createSchema(this.modelState.root);
112
112
  }
113
113
 
114
- protected override applyPatch(rootSchema: GModelRootSchema, patch: jsonPatch.Operation[]): void {
114
+ protected override applyPatch(rootSchema: GModelRootSchema, patch: jsonPatch.Operation[]): MaybePromise<void> {
115
115
  super.applyPatch(rootSchema, patch);
116
116
  const newRoot = this.serializer.createRoot(rootSchema);
117
117
  this.modelState.updateRoot(newRoot);
@@ -17,7 +17,7 @@ import { GModelRoot } from '@eclipse-glsp/graph';
17
17
  import { Action, ComputedBoundsAction, MaybePromise } from '@eclipse-glsp/protocol';
18
18
  import { inject, injectable } from 'inversify';
19
19
  import { ActionHandler } from '../../actions/action-handler';
20
- import { applyAlignment, applyBounds, applyRoute } from '../../utils/layout-util';
20
+ import { applyAlignment, applyElementAndBounds, applyRoute } from '../../utils/layout-util';
21
21
  import { ModelState } from '../model/model-state';
22
22
  import { ModelSubmissionHandler } from '../model/model-submission-handler';
23
23
 
@@ -47,7 +47,7 @@ export class ComputedBoundsActionHandler implements ActionHandler {
47
47
 
48
48
  protected applyBounds(root: GModelRoot, action: ComputedBoundsAction): void {
49
49
  const index = this.modelState.index;
50
- action.bounds.forEach(bounds => applyBounds(bounds, index));
50
+ action.bounds.forEach(bounds => applyElementAndBounds(bounds, index));
51
51
  (action.alignments ?? []).forEach(alignment => applyAlignment(alignment, index));
52
52
  (action.routes ?? []).forEach(route => applyRoute(route, index));
53
53
  }
@@ -23,6 +23,8 @@ export * from './actions/client-action-handler';
23
23
  export * from './actions/global-action-provider';
24
24
  export * from './command/command';
25
25
  export * from './command/command-stack';
26
+ export * from './command/recording-command';
27
+ export * from './command/undo-redo-action-handler';
26
28
  export * from './di/binding-target';
27
29
  export * from './di/client-session-module';
28
30
  export * from './di/diagram-module';
@@ -65,7 +67,6 @@ export * from './features/popup/popup-model-factory';
65
67
  export * from './features/popup/request-popup-model-action-handler';
66
68
  export * from './features/validation/model-validator';
67
69
  export * from './features/validation/request-markers-handler';
68
- export * from './gmodel/cut-operation-handler';
69
70
  export * from './gmodel/index';
70
71
  export * from './launch/glsp-server-launcher';
71
72
  export * from './operations/compound-operation-handler';
@@ -84,6 +85,7 @@ export * from './session/client-session-manager';
84
85
  export * from './utils/args-util';
85
86
  export * from './utils/client-options-util';
86
87
  export * from './utils/glsp-server-error';
88
+ export * from './utils/layout-util';
87
89
  export * from './utils/logger';
88
90
  export * from './utils/promise-queue';
89
91
  export * from './utils/registry';
@@ -13,20 +13,19 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
- import { MaybePromise } from '@eclipse-glsp/protocol';
16
+ import { Disposable, DisposableCollection, MaybePromise } from '@eclipse-glsp/protocol';
17
17
  import { Container, ContainerModule, inject, injectable, optional } from 'inversify';
18
18
  import { ServerModule } from '../di/server-module';
19
19
  import { InjectionContainer } from '../di/service-identifiers';
20
20
  import { Logger } from '../utils/logger';
21
21
 
22
- export const START_UP_COMPLETE_MSG = '[GLSP-Server]:Startup completed';
23
-
24
22
  @injectable()
25
- export abstract class GLSPServerLauncher<T = undefined> {
23
+ export abstract class GLSPServerLauncher<T> implements Disposable {
26
24
  @inject(Logger) protected logger: Logger;
27
25
 
28
26
  protected _modules: ContainerModule[] = [];
29
27
  protected running: boolean;
28
+ protected toDispose = new DisposableCollection();
30
29
 
31
30
  @inject(InjectionContainer) @optional() protected parentContainer?: Container;
32
31
 
@@ -40,7 +39,7 @@ export abstract class GLSPServerLauncher<T = undefined> {
40
39
  return container;
41
40
  }
42
41
 
43
- start(startParams?: T): MaybePromise<void> {
42
+ start(startParams: T): MaybePromise<void> {
44
43
  if (!this.running) {
45
44
  this.running = true;
46
45
  return this.run(startParams);
@@ -48,10 +47,11 @@ export abstract class GLSPServerLauncher<T = undefined> {
48
47
  this.logger.warn('Could not start launcher. Launcher is already running!');
49
48
  }
50
49
 
51
- protected abstract run(startParams?: T): MaybePromise<void>;
50
+ protected abstract run(startParams: T): MaybePromise<void>;
52
51
 
53
52
  shutdown(): MaybePromise<void> {
54
53
  if (this.running) {
54
+ this.logger.info('Shutdown GLSPServerLauncher');
55
55
  const result = this.stop();
56
56
  this.running = false;
57
57
  return result;
@@ -59,7 +59,13 @@ export abstract class GLSPServerLauncher<T = undefined> {
59
59
  this.logger.warn('Could not stop launcher. Launcher is not running!');
60
60
  }
61
61
 
62
- protected abstract stop(): MaybePromise<void>;
62
+ protected stop(): MaybePromise<void> {
63
+ this.dispose();
64
+ }
65
+
66
+ dispose(): void {
67
+ this.toDispose.dispose();
68
+ }
63
69
 
64
70
  get modules(): ContainerModule[] {
65
71
  if (!this._modules) {
@@ -27,7 +27,7 @@ import { getOrThrow, GLSPServerError } from './glsp-server-error';
27
27
  * @param index The model index.
28
28
  * @returns The changed element.
29
29
  */
30
- export function applyBounds(bounds: ElementAndBounds, index: GModelIndex): GBoundsAware | undefined {
30
+ export function applyElementAndBounds(bounds: ElementAndBounds, index: GModelIndex): GBoundsAware | undefined {
31
31
  const element = getOrThrow(index.get(bounds.elementId), 'Model element not found! ID: ' + bounds.elementId);
32
32
  if (isGBoundsAware(element)) {
33
33
  if (bounds.newPosition !== undefined) {
package/src/node/index.ts CHANGED
@@ -21,3 +21,4 @@ export * from './gmodel/gmodel-storage';
21
21
  export * from './launch/cli-parser';
22
22
  export * from './launch/socket-cli-parser';
23
23
  export * from './launch/socket-server-launcher';
24
+ export * from './launch/websocket-server-launcher';
@@ -16,11 +16,13 @@
16
16
  import { Container, inject, injectable } from 'inversify';
17
17
  import * as net from 'net';
18
18
  import * as jsonrpc from 'vscode-jsonrpc/node';
19
+ import { Disposable } from '..';
19
20
  import { GLSPServerLauncher } from '../../common/launch/glsp-server-launcher';
20
21
  import { GLSPServer, JsonRpcGLSPServer } from '../../common/protocol/glsp-server';
21
22
  import { Logger } from '../../common/utils/logger';
22
23
 
23
- const START_UP_COMPLETE_MSG = '[GLSP-Server]:Startup completed. Accepting requests on port:';
24
+ export const START_UP_COMPLETE_MSG = '[GLSP-Server]:Startup completed. Accepting requests on port:';
25
+
24
26
  @injectable()
25
27
  export class SocketServerLauncher extends GLSPServerLauncher<net.TcpSocketConnectOpts> {
26
28
  @inject(Logger) protected override logger: Logger;
@@ -29,6 +31,16 @@ export class SocketServerLauncher extends GLSPServerLauncher<net.TcpSocketConnec
29
31
  protected startupCompleteMessage = START_UP_COMPLETE_MSG;
30
32
  protected netServer: net.Server;
31
33
 
34
+ constructor() {
35
+ super();
36
+ this.toDispose.push(
37
+ Disposable.create(() => {
38
+ this.currentConnections.forEach(connection => connection.dispose());
39
+ this.netServer.close();
40
+ })
41
+ );
42
+ }
43
+
32
44
  protected run(opts: net.TcpSocketConnectOpts): Promise<void> {
33
45
  this.netServer = net.createServer(socket => this.createClientConnection(socket));
34
46
 
@@ -81,10 +93,4 @@ export class SocketServerLauncher extends GLSPServerLauncher<net.TcpSocketConnec
81
93
  protected createConnection(socket: net.Socket): jsonrpc.MessageConnection {
82
94
  return jsonrpc.createMessageConnection(new jsonrpc.SocketMessageReader(socket), new jsonrpc.SocketMessageWriter(socket), console);
83
95
  }
84
-
85
- protected stop(): void {
86
- this.logger.info('Shutdown SocketServerLauncher');
87
- this.currentConnections.forEach(connection => connection.dispose());
88
- this.netServer.close();
89
- }
90
96
  }