@eclipse-glsp/server 2.8.0-next.7 → 2.8.0

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 (31) hide show
  1. package/lib/common/features/layout/computed-bounds-action-handler.d.ts +16 -1
  2. package/lib/common/features/layout/computed-bounds-action-handler.d.ts.map +1 -1
  3. package/lib/common/features/layout/computed-bounds-action-handler.js +41 -3
  4. package/lib/common/features/layout/computed-bounds-action-handler.js.map +1 -1
  5. package/lib/common/launch/glsp-server-launcher.d.ts +8 -1
  6. package/lib/common/launch/glsp-server-launcher.d.ts.map +1 -1
  7. package/lib/common/launch/glsp-server-launcher.js +11 -1
  8. package/lib/common/launch/glsp-server-launcher.js.map +1 -1
  9. package/lib/common/launch/jsonrpc-server-launcher.d.ts +51 -2
  10. package/lib/common/launch/jsonrpc-server-launcher.d.ts.map +1 -1
  11. package/lib/common/launch/jsonrpc-server-launcher.js +82 -3
  12. package/lib/common/launch/jsonrpc-server-launcher.js.map +1 -1
  13. package/lib/common/utils/layout-util.d.ts +5 -5
  14. package/lib/common/utils/layout-util.d.ts.map +1 -1
  15. package/lib/common/utils/layout-util.js +12 -11
  16. package/lib/common/utils/layout-util.js.map +1 -1
  17. package/lib/node/launch/socket-server-launcher.d.ts +39 -2
  18. package/lib/node/launch/socket-server-launcher.d.ts.map +1 -1
  19. package/lib/node/launch/socket-server-launcher.js +50 -31
  20. package/lib/node/launch/socket-server-launcher.js.map +1 -1
  21. package/lib/node/launch/websocket-server-launcher.d.ts +36 -5
  22. package/lib/node/launch/websocket-server-launcher.d.ts.map +1 -1
  23. package/lib/node/launch/websocket-server-launcher.js +53 -12
  24. package/lib/node/launch/websocket-server-launcher.js.map +1 -1
  25. package/package.json +3 -3
  26. package/src/common/features/layout/computed-bounds-action-handler.ts +52 -4
  27. package/src/common/launch/glsp-server-launcher.ts +12 -1
  28. package/src/common/launch/jsonrpc-server-launcher.ts +89 -2
  29. package/src/common/utils/layout-util.ts +13 -12
  30. package/src/node/launch/socket-server-launcher.ts +54 -31
  31. package/src/node/launch/websocket-server-launcher.ts +72 -14
@@ -11,7 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.SocketServerLauncher = void 0;
13
13
  /********************************************************************************
14
- * Copyright (c) 2022-2024 STMicroelectronics and others.
14
+ * Copyright (c) 2022-2026 STMicroelectronics and others.
15
15
  *
16
16
  * This program and the accompanying materials are made available under the
17
17
  * terms of the Eclipse Public License v. 2.0 which is available at
@@ -33,41 +33,61 @@ const jsonrpc_server_launcher_1 = require("../../common/launch/jsonrpc-server-la
33
33
  const logger_1 = require("../../common/utils/logger");
34
34
  let SocketServerLauncher = class SocketServerLauncher extends jsonrpc_server_launcher_1.JsonRpcGLSPServerLauncher {
35
35
  constructor() {
36
- super();
36
+ super(...arguments);
37
+ this.onConnectionEmitter = new protocol_1.Emitter();
38
+ /**
39
+ * Fires for every socket the server accepts, before the JSON-RPC connection is built on it.
40
+ *
41
+ * A listener must not consume the socket. Subscribe before {@link start} to observe the first connection; the
42
+ * subscription outlives an individual launch and is disposed by the caller.
43
+ */
44
+ this.onConnection = this.onConnectionEmitter.event;
45
+ }
46
+ getServerSocket() {
47
+ return this.netServer;
48
+ }
49
+ registerDisposables() {
50
+ super.registerDisposables();
37
51
  this.toDispose.push(protocol_1.Disposable.create(() => {
38
- this.netServer.close();
52
+ this.netServer?.close();
39
53
  }));
40
54
  }
41
55
  run(opts) {
42
- this.netServer = net.createServer(socket => {
43
- const connection = this.createConnection(socket);
44
- this.createServerInstance(connection);
45
- });
46
- this.netServer.listen(opts.port, opts.host);
47
- this.netServer.on('listening', () => {
48
- const addressInfo = this.netServer.address();
49
- if (!addressInfo) {
50
- this.logger.error('Could not resolve GLSP Server address info. Shutting down.');
51
- this.shutdown();
52
- return;
53
- }
54
- else if (typeof addressInfo === 'string') {
55
- this.logger.error(`GLSP Server is unexpectedly listening to pipe or domain socket "${addressInfo}". Shutting down.`);
56
- this.shutdown();
57
- return;
58
- }
59
- const currentPort = addressInfo.port;
60
- this.logger.info(`The GLSP server is ready to accept new client requests on port: ${currentPort}`);
61
- // Print a message to the output stream that indicates that the start is completed.
62
- // This indicates to the client that the server process is ready (in an embedded scenario).
63
- console.log(this.startupCompleteMessage.concat(currentPort.toString()));
64
- });
65
- this.netServer.on('error', () => this.shutdown());
56
+ this.resetListening();
57
+ const netServer = net.createServer(socket => this.acceptConnection(socket));
58
+ this.netServer = netServer;
59
+ netServer.listen(opts.port, opts.host);
60
+ netServer.on('listening', () => this.handleListening(netServer));
61
+ netServer.on('error', error => this.handleError(error));
66
62
  return new Promise((resolve, reject) => {
67
- this.netServer.on('close', () => resolve(undefined));
68
- this.netServer.on('error', error => reject(error));
63
+ netServer.on('close', () => resolve(undefined));
64
+ netServer.on('error', error => reject(error));
69
65
  });
70
66
  }
67
+ /**
68
+ * Takes up a socket the server accepted. Observers are notified before the socket is read from.
69
+ *
70
+ * @param socket The accepted socket.
71
+ */
72
+ acceptConnection(socket) {
73
+ this.onConnectionEmitter.fire(socket);
74
+ this.createServerInstance(this.createConnection(socket));
75
+ }
76
+ /**
77
+ * Reports the server as ready and resolves {@link listening}.
78
+ *
79
+ * @param server The server that reported itself as listening.
80
+ */
81
+ handleListening(server) {
82
+ const addressInfo = this.settleListening(server);
83
+ if (!addressInfo) {
84
+ return;
85
+ }
86
+ this.logger.info(`The GLSP server is ready to accept new client requests on port: ${addressInfo.port}`);
87
+ // Print a message to the output stream that indicates that the start is completed.
88
+ // This indicates to the client that the server process is ready (in an embedded scenario).
89
+ console.log(this.startupCompleteMessage.concat(addressInfo.port.toString()));
90
+ }
71
91
  createConnection(socket) {
72
92
  return jsonrpc.createMessageConnection(new jsonrpc.SocketMessageReader(socket), new jsonrpc.SocketMessageWriter(socket), console);
73
93
  }
@@ -78,7 +98,6 @@ __decorate([
78
98
  __metadata("design:type", logger_1.Logger)
79
99
  ], SocketServerLauncher.prototype, "logger", void 0);
80
100
  exports.SocketServerLauncher = SocketServerLauncher = __decorate([
81
- (0, inversify_1.injectable)(),
82
- __metadata("design:paramtypes", [])
101
+ (0, inversify_1.injectable)()
83
102
  ], SocketServerLauncher);
84
103
  //# sourceMappingURL=socket-server-launcher.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"socket-server-launcher.js","sourceRoot":"","sources":["../../../src/node/launch/socket-server-launcher.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;kFAckF;AAClF,qDAAoD;AACpD,yCAA+C;AAC/C,2BAA2B;AAC3B,+CAA+C;AAC/C,yFAAwF;AACxF,sDAAmD;AAG5C,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,mDAAmD;IAKzF;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,CAAC,IAAI,CACf,qBAAU,CAAC,MAAM,CAAC,GAAG,EAAE;YACnB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QAC3B,CAAC,CAAC,CACL,CAAC;IACN,CAAC;IAES,GAAG,CAAC,IAA8B;QACxC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE;YACvC,MAAM,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;YACjD,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE;YAChC,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;YAC7C,IAAI,CAAC,WAAW,EAAE,CAAC;gBACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4DAA4D,CAAC,C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AA;AAvEY,oDAAoB;AACM;IAAlC,IAAA,kBAAM,EAAC,eAAM,CAAC;8BAA4B,eAAM;oDAAC;+BADzC,oBAAoB;IADhC,IAAA,sBAAU,GAAE;GACA,oBAAoB,CAuEhC"}
@@ -1,5 +1,5 @@
1
1
  /********************************************************************************
2
- * Copyright (c) 2023 EclipseSource and others.
2
+ * Copyright (c) 2023-2026 EclipseSource and others.
3
3
  *
4
4
  * This program and the accompanying materials are made available under the
5
5
  * terms of the Eclipse Public License v. 2.0 which is available at
@@ -13,10 +13,11 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
- import { MaybePromise, WebSocketWrapper } from '@eclipse-glsp/protocol';
16
+ import { Emitter, MaybePromise, WebSocketWrapper } from '@eclipse-glsp/protocol';
17
17
  import * as http from 'http';
18
+ import * as net from 'net';
18
19
  import * as jsonrpc from 'vscode-jsonrpc';
19
- import { Server, WebSocket } from 'ws';
20
+ import { WebSocket, WebSocketServer } from 'ws';
20
21
  import { JsonRpcGLSPServerLauncher } from '../../common/launch/jsonrpc-server-launcher';
21
22
  import { Logger } from '../../common/utils/logger';
22
23
  export interface WebSocketServerOptions {
@@ -34,11 +35,41 @@ export interface WebsocketConnectionData {
34
35
  socket: WebSocket;
35
36
  connection: jsonrpc.MessageConnection;
36
37
  }
38
+ /** An accepted web socket together with the upgrade request it was negotiated with. */
39
+ export interface AcceptedWebSocket {
40
+ socket: WebSocket;
41
+ /** The handshake request, the only place where its headers and query are still available. */
42
+ request: http.IncomingMessage;
43
+ }
37
44
  export declare class WebSocketServerLauncher extends JsonRpcGLSPServerLauncher<WebSocketServerOptions> {
38
45
  protected logger: Logger;
39
- protected server: Server;
40
- constructor();
46
+ protected server?: WebSocketServer;
47
+ /**
48
+ * The HTTP server the web socket server is mounted on.
49
+ *
50
+ * Held separately because `ws` only closes an HTTP server it created itself, so releasing the socket is up to us.
51
+ */
52
+ protected httpServer?: http.Server;
53
+ protected onConnectionEmitter: Emitter<AcceptedWebSocket>;
54
+ /**
55
+ * Fires for every web socket the server accepts, before the JSON-RPC connection is built on it.
56
+ *
57
+ * A listener must not consume the socket. Subscribe before {@link start} to observe the first connection; the
58
+ * subscription outlives an individual launch and is disposed by the caller.
59
+ */
60
+ readonly onConnection: import("@eclipse-glsp/protocol").Event<AcceptedWebSocket>;
61
+ protected getServerSocket(): net.Server | undefined;
62
+ protected registerDisposables(): void;
41
63
  protected run(options: WebSocketServerOptions): Promise<void>;
64
+ /** Settles {@link listening} from the HTTP server, which may already be bound by the time we get here. */
65
+ protected observeListening(server: http.Server): void;
66
+ /**
67
+ * Takes up a web socket the server accepted. Observers are notified before the socket is read from.
68
+ *
69
+ * @param socket The accepted web socket.
70
+ * @param request The upgrade request the socket was negotiated with.
71
+ */
72
+ protected acceptConnection(socket: WebSocket, request: http.IncomingMessage): void;
42
73
  protected createConnection(socket: WebSocket): jsonrpc.MessageConnection;
43
74
  protected resolveOptions(options: WebSocketServerOptions): Promise<ResolvedWebSocketServerOptions>;
44
75
  protected createHttpServer(port: number, host?: string): http.Server;
@@ -1 +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;AAG7B,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AACxF,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAEnD,MAAM,WAAW,sBAAsB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,8BAA8B;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,uBAAuB;IACpC,MAAM,EAAE,SAAS,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC,iBAAiB,CAAC;CACzC;AAID,qBACa,uBAAwB,SAAQ,yBAAyB,CAAC,sBAAsB,CAAC;IAC1F,UACmB,MAAM,EAAE,MAAM,CAAC;IAElC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;;cAWT,GAAG,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBnE,SAAS,CAAC,gBAAgB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,iBAAiB;cAIxD,cAAc,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,8BAA8B,CAAC;IAQxG,SAAS,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM;IAgB3D,KAAK,CAAC,OAAO,EAAE,sBAAsB,GAAG,YAAY,CAAC,IAAI,CAAC;CAGtE;AAeD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,gBAAgB,CAQjE"}
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,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACxH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,KAAK,GAAG,MAAM,KAAK,C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AAS,CAAC,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,GAAG,IAAI;IASrD;;;;;OAKG;IACH,SAAS,CAAC,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,eAAe,GAAG,IAAI;IAKlF,SAAS,CAAC,gBAAgB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,iBAAiB;cAIxD,cAAc,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,8BAA8B,CAAC;IAQxG,SAAS,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM;IAgB3D,KAAK,CAAC,OAAO,EAAE,sBAAsB,GAAG,YAAY,CAAC,IAAI,CAAC;CAGtE;AAeD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,gBAAgB,CAQjE"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /********************************************************************************
3
- * Copyright (c) 2023 EclipseSource and others.
3
+ * Copyright (c) 2023-2026 EclipseSource and others.
4
4
  *
5
5
  * This program and the accompanying materials are made available under the
6
6
  * terms of the Eclipse Public License v. 2.0 which is available at
@@ -36,26 +36,68 @@ const logger_1 = require("../../common/utils/logger");
36
36
  const STATUS_UPGRADE_REQUIRED = 426;
37
37
  let WebSocketServerLauncher = class WebSocketServerLauncher extends jsonrpc_server_launcher_1.JsonRpcGLSPServerLauncher {
38
38
  constructor() {
39
- super();
39
+ super(...arguments);
40
+ this.onConnectionEmitter = new protocol_1.Emitter();
41
+ /**
42
+ * Fires for every web socket the server accepts, before the JSON-RPC connection is built on it.
43
+ *
44
+ * A listener must not consume the socket. Subscribe before {@link start} to observe the first connection; the
45
+ * subscription outlives an individual launch and is disposed by the caller.
46
+ */
47
+ this.onConnection = this.onConnectionEmitter.event;
48
+ }
49
+ getServerSocket() {
50
+ return this.httpServer;
51
+ }
52
+ registerDisposables() {
53
+ super.registerDisposables();
40
54
  this.toDispose.push(protocol_1.Disposable.create(() => {
41
- this.server.close();
55
+ this.server?.close();
56
+ // `ws` leaves an HTTP server it did not create itself listening, so close ours explicitly.
57
+ this.httpServer?.close();
58
+ this.httpServer = undefined;
42
59
  }));
43
60
  }
44
61
  async run(options) {
62
+ this.resetListening();
45
63
  const resolvedOptions = await this.resolveOptions(options);
46
- this.server = new ws_1.Server({ server: resolvedOptions.server, path: resolvedOptions.path });
64
+ if (!this.running) {
65
+ // Shut down while the options were being resolved, so release the socket they already bound.
66
+ resolvedOptions.server.close();
67
+ return;
68
+ }
69
+ this.httpServer = resolvedOptions.server;
70
+ this.server = new ws_1.WebSocketServer({ server: resolvedOptions.server, path: resolvedOptions.path });
47
71
  const endpoint = `ws://${resolvedOptions.host}:${resolvedOptions.port}:${resolvedOptions.path}`;
48
72
  this.logger.info(`The GLSP Websocket launcher is ready to accept new client requests on endpoint '${endpoint}'`);
49
73
  console.log(this.startupCompleteMessage.concat(resolvedOptions.port.toString()));
50
- this.server.on('connection', (ws, req) => {
51
- const connection = this.createConnection(ws);
52
- this.createServerInstance(connection);
53
- });
74
+ this.observeListening(resolvedOptions.server);
75
+ this.server.on('connection', (ws, request) => this.acceptConnection(ws, request));
76
+ const server = this.server;
54
77
  return new Promise((resolve, reject) => {
55
- this.server.on('close', () => resolve(undefined));
56
- this.server.on('error', error => reject(error));
78
+ server.on('close', () => resolve(undefined));
79
+ server.on('error', error => reject(error));
57
80
  });
58
81
  }
82
+ /** Settles {@link listening} from the HTTP server, which may already be bound by the time we get here. */
83
+ observeListening(server) {
84
+ if (server.listening) {
85
+ this.settleListening(server);
86
+ return;
87
+ }
88
+ server.on('listening', () => this.settleListening(server));
89
+ server.on('error', error => this.handleError(error));
90
+ }
91
+ /**
92
+ * Takes up a web socket the server accepted. Observers are notified before the socket is read from.
93
+ *
94
+ * @param socket The accepted web socket.
95
+ * @param request The upgrade request the socket was negotiated with.
96
+ */
97
+ acceptConnection(socket, request) {
98
+ this.onConnectionEmitter.fire({ socket, request });
99
+ this.createServerInstance(this.createConnection(socket));
100
+ }
59
101
  createConnection(socket) {
60
102
  return (0, protocol_1.createWebSocketConnection)(wrapWebSocket(socket));
61
103
  }
@@ -89,8 +131,7 @@ __decorate([
89
131
  __metadata("design:type", logger_1.Logger)
90
132
  ], WebSocketServerLauncher.prototype, "logger", void 0);
91
133
  exports.WebSocketServerLauncher = WebSocketServerLauncher = __decorate([
92
- (0, inversify_1.injectable)(),
93
- __metadata("design:paramtypes", [])
134
+ (0, inversify_1.injectable)()
94
135
  ], WebSocketServerLauncher);
95
136
  async function getFreePort() {
96
137
  return new Promise((resolve, reject) => {
@@ -1 +1 @@
1
- {"version":3,"file":"websocket-server-launcher.js","sourceRoot":"","sources":["../../../src/node/launch/websocket-server-launcher.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;;;;;;;;;;AAmHlF,sCAQC;AAzHD,qDAA+G;AAC/G,6BAA6B;AAC7B,yCAA+C;AAC/C,2BAA2B;AAE3B,2BAAuC;AACvC,yFAAwF;AACxF,sDAAmD;AAoBnD,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAG7B,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ,mDAAiD;IAM1F;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,CAAC,IAAI,CACf,qBAAU,CAAC,MAAM,CAAC,GAAG,EAAE;YACnB,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,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AE,CAAC;QAC/B,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE;YACf,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;YAC9B,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;gBAC1C,MAAM,CAAC,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC,CAAC;gBAC9D,OAAO;YACX,CAAC;YACD,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,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"}
1
+ {"version":3,"file":"websocket-server-launcher.js","sourceRoot":"","sources":["../../../src/node/launch/websocket-server-launcher.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;;;;;;;;;;AA6KlF,sCAQC;AAnLD,qDAAwH;AACxH,6BAA6B;AAC7B,yCAA+C;AAC/C,2BAA2B;AAE3B,2BAAgD;AAChD,yFAAwF;AACxF,sDAAmD;AA2BnD,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAG7B,IAAM,uBA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E,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC;QACrC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE;KAChC,CAAC;AACN,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eclipse-glsp/server",
3
- "version": "2.8.0-next.7",
3
+ "version": "2.8.0",
4
4
  "description": "A js server framework for Eclipse GLSP",
5
5
  "keywords": [
6
6
  "eclipse",
@@ -51,13 +51,13 @@
51
51
  "!**/test/**"
52
52
  ],
53
53
  "dependencies": {
54
- "@eclipse-glsp/protocol": "next",
54
+ "@eclipse-glsp/protocol": "2.8.0",
55
55
  "commander": "^14.0.0",
56
56
  "fast-json-patch": "^3.1.0",
57
57
  "vscode-jsonrpc": "8.2.0",
58
58
  "winston": "^3.3.3",
59
59
  "ws": "^8.12.1",
60
- "@eclipse-glsp/graph": "2.8.0-next.7"
60
+ "@eclipse-glsp/graph": "2.8.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/ws": "^8.5.4"
@@ -14,10 +14,19 @@
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
16
  import { GModelRoot } from '@eclipse-glsp/graph';
17
- import { Action, ComputedBoundsAction, LayoutOperation, MaybePromise } from '@eclipse-glsp/protocol';
17
+ import {
18
+ Action,
19
+ ComputedBoundsAction,
20
+ ElementAndAlignment,
21
+ ElementAndBounds,
22
+ ElementAndRoutingPoints,
23
+ LayoutOperation,
24
+ MaybePromise
25
+ } from '@eclipse-glsp/protocol';
18
26
  import { inject, injectable } from 'inversify';
19
27
  import { ActionHandler } from '../../actions/action-handler';
20
28
  import { applyAlignment, applyElementAndBounds, applyRoute } from '../../utils/layout-util';
29
+ import { Logger } from '../../utils/logger';
21
30
  import { ModelState } from '../model/model-state';
22
31
  import { ModelSubmissionHandler } from '../model/model-submission-handler';
23
32
 
@@ -34,6 +43,9 @@ export class ComputedBoundsActionHandler implements ActionHandler {
34
43
  @inject(ModelState)
35
44
  protected modelState: ModelState;
36
45
 
46
+ @inject(Logger)
47
+ protected logger: Logger;
48
+
37
49
  actionKinds = [ComputedBoundsAction.KIND];
38
50
  execute(action: ComputedBoundsAction): MaybePromise<Action[]> {
39
51
  const model = this.modelState.root;
@@ -48,11 +60,47 @@ export class ComputedBoundsActionHandler implements ActionHandler {
48
60
  return [];
49
61
  }
50
62
 
63
+ /**
64
+ * Applies everything the client computed for the given model.
65
+ *
66
+ * An entry that cannot be applied is skipped and logged rather than treated as an error.
67
+ */
51
68
  protected applyBounds(root: GModelRoot, action: ComputedBoundsAction): void {
69
+ this.applyElementBounds(action.bounds);
70
+ this.applyAlignments(action.alignments ?? []);
71
+ this.applyRoutes(action.routes ?? []);
72
+ }
73
+
74
+ protected applyElementBounds(allBounds: ElementAndBounds[]): void {
75
+ const index = this.modelState.index;
76
+ allBounds.forEach(bounds => {
77
+ if (!applyElementAndBounds(bounds, index)) {
78
+ this.logger.warn(`Skipped computed bounds of element '${bounds.elementId}'`);
79
+ }
80
+ });
81
+ }
82
+
83
+ protected applyAlignments(alignments: ElementAndAlignment[]): void {
84
+ const index = this.modelState.index;
85
+ alignments.forEach(alignment => {
86
+ if (!applyAlignment(alignment, index)) {
87
+ this.logger.warn(`Skipped computed alignment of element '${alignment.elementId}'`);
88
+ }
89
+ });
90
+ }
91
+
92
+ /**
93
+ * Applies the computed routes.
94
+ *
95
+ * A skipped route is logged at debug level, an edge the client has not finished routing yet is expected.
96
+ */
97
+ protected applyRoutes(routes: ElementAndRoutingPoints[]): void {
52
98
  const index = this.modelState.index;
53
- action.bounds.forEach(bounds => applyElementAndBounds(bounds, index));
54
- (action.alignments ?? []).forEach(alignment => applyAlignment(alignment, index));
55
- (action.routes ?? []).forEach(route => applyRoute(route, index));
99
+ routes.forEach(route => {
100
+ if (!applyRoute(route, index)) {
101
+ this.logger.debug(`Skipped computed route of element '${route.elementId}'`);
102
+ }
103
+ });
56
104
  }
57
105
 
58
106
  priority?: number | undefined;
@@ -1,5 +1,5 @@
1
1
  /********************************************************************************
2
- * Copyright (c) 2022-2023 STMicroelectronics and others.
2
+ * Copyright (c) 2022-2026 STMicroelectronics and others.
3
3
  *
4
4
  * This program and the accompanying materials are made available under the
5
5
  * terms of the Eclipse Public License v. 2.0 which is available at
@@ -42,11 +42,22 @@ export abstract class GLSPServerLauncher<T> implements Disposable {
42
42
  start(startParams: T): MaybePromise<void> {
43
43
  if (!this.running) {
44
44
  this.running = true;
45
+ this.registerDisposables();
45
46
  return this.run(startParams);
46
47
  }
47
48
  this.logger.warn('Could not start launcher. Launcher is already running!');
48
49
  }
49
50
 
51
+ /**
52
+ * Registers what {@link shutdown} has to release for the launch that is about to start.
53
+ *
54
+ * Called once per launch, because {@link dispose} empties the collection it registers into. A subclass that holds
55
+ * resources for the duration of a launch overrides this instead of registering them in its constructor.
56
+ */
57
+ protected registerDisposables(): void {
58
+ // nothing to release by default
59
+ }
60
+
50
61
  protected abstract run(startParams: T): MaybePromise<void>;
51
62
 
52
63
  shutdown(): MaybePromise<void> {
@@ -15,6 +15,7 @@
15
15
  ********************************************************************************/
16
16
 
17
17
  import {
18
+ Deferred,
18
19
  Disposable,
19
20
  GLSPClientProxy,
20
21
  GLSPServer,
@@ -23,6 +24,7 @@ import {
23
24
  configureClientConnection
24
25
  } from '@eclipse-glsp/protocol';
25
26
  import { Container, ContainerModule, inject, injectable } from 'inversify';
27
+ import * as net from 'net';
26
28
  import * as jsonrpc from 'vscode-jsonrpc';
27
29
  import { Logger } from '../utils/logger';
28
30
  import { GLSPServerLauncher } from './glsp-server-launcher';
@@ -43,8 +45,93 @@ export abstract class JsonRpcGLSPServerLauncher<T> extends GLSPServerLauncher<T>
43
45
  protected serverInstances = new Map<jsonrpc.MessageConnection, JsonRpcServerInstance>();
44
46
  protected startupCompleteMessage = START_UP_COMPLETE_MSG;
45
47
 
46
- constructor() {
47
- super();
48
+ protected listeningAddress = new Deferred<net.AddressInfo>();
49
+
50
+ /**
51
+ * Resolves with the address the server bound to once it is listening, and rejects if it never gets there.
52
+ *
53
+ * Launching with port `0` lets the operating system pick a free port, so the bound address is not necessarily the
54
+ * requested one. Settles once per launch and keeps that value, so use {@link port} for the current state. Reading
55
+ * this before {@link start} is fine, the promise handed out is the one that launch settles.
56
+ */
57
+ get listening(): Promise<net.AddressInfo> {
58
+ return this.listeningAddress.promise;
59
+ }
60
+
61
+ /**
62
+ * The port the server is currently listening on, or `undefined` if it is not.
63
+ *
64
+ * Await {@link listening} rather than polling this while the server is still starting up.
65
+ */
66
+ get port(): number | undefined {
67
+ const address = this.getServerSocket()?.address();
68
+ return address && typeof address !== 'string' ? address.port : undefined;
69
+ }
70
+
71
+ /**
72
+ * The socket that {@link port} reports on, or `undefined` before the first launch.
73
+ *
74
+ * A launcher that binds a socket overrides this, the default reports no address at all.
75
+ */
76
+ protected getServerSocket(): net.Server | undefined {
77
+ return undefined;
78
+ }
79
+
80
+ /**
81
+ * Arms {@link listening} for a launch.
82
+ *
83
+ * An unresolved promise is kept, so a caller that grabbed {@link listening} before {@link start} gets the one this
84
+ * launch settles. A settled one is replaced, so a restart is not handed the previous result.
85
+ */
86
+ protected resetListening(): void {
87
+ if (this.listeningAddress.state !== 'unresolved') {
88
+ this.listeningAddress = new Deferred<net.AddressInfo>();
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Resolves {@link listening} with the address the given server bound to.
94
+ *
95
+ * @param server The server that reported itself as listening.
96
+ * @returns The bound address, or `undefined` if it cannot be used, in which case the launcher is shut down.
97
+ */
98
+ protected settleListening(server: net.Server): net.AddressInfo | undefined {
99
+ const addressInfo = server.address();
100
+ if (!addressInfo) {
101
+ this.failToListen('Could not resolve GLSP Server address info.');
102
+ return undefined;
103
+ }
104
+ if (typeof addressInfo === 'string') {
105
+ this.failToListen(`GLSP Server is unexpectedly listening to pipe or domain socket "${addressInfo}".`);
106
+ return undefined;
107
+ }
108
+ this.listeningAddress.resolve(addressInfo);
109
+ return addressInfo;
110
+ }
111
+
112
+ /**
113
+ * Invoked when the server socket fails, e.g. because the requested port is already in use.
114
+ *
115
+ * @param error The reason the socket failed.
116
+ */
117
+ protected handleError(error: Error): void {
118
+ this.failToListen(`GLSP server socket error. ${error.message}`, error);
119
+ }
120
+
121
+ /**
122
+ * Reports that the server will not accept requests, rejects {@link listening} and shuts the launcher down.
123
+ *
124
+ * @param message The reason the server is not usable.
125
+ * @param cause The underlying error, if the reason was one.
126
+ */
127
+ protected failToListen(message: string, cause?: Error): void {
128
+ this.logger.error(`${message} Shutting down.`);
129
+ this.listeningAddress.reject(cause ?? new Error(message));
130
+ this.shutdown();
131
+ }
132
+
133
+ protected override registerDisposables(): void {
134
+ super.registerDisposables();
48
135
  this.toDispose.push(
49
136
  Disposable.create(() => {
50
137
  this.serverInstances.forEach(instance => this.disposeServerInstance(instance));
@@ -25,11 +25,11 @@ import { GLSPServerError, getOrThrow } from './glsp-server-error';
25
25
  *
26
26
  * @param bounds The new bounds.
27
27
  * @param index The model index.
28
- * @returns The changed element.
28
+ * @returns The changed element, or `undefined` if the bounds could not be applied to any element.
29
29
  */
30
30
  export function applyElementAndBounds(bounds: ElementAndBounds, index: GModelIndex): GBoundsAware | undefined {
31
- const element = getOrThrow(index.get(bounds.elementId), 'Model element not found! ID: ' + bounds.elementId);
32
- if (isGBoundsAware(element)) {
31
+ const element = index.find(bounds.elementId);
32
+ if (element && isGBoundsAware(element)) {
33
33
  if (bounds.newPosition !== undefined) {
34
34
  element.position = bounds.newPosition;
35
35
  }
@@ -44,11 +44,11 @@ export function applyElementAndBounds(bounds: ElementAndBounds, index: GModelInd
44
44
  *
45
45
  * @param alignment The new alignment.
46
46
  * @param index The model index.
47
- * @returns The changed element.
47
+ * @returns The changed element, or `undefined` if the alignment could not be applied to any element.
48
48
  */
49
49
  export function applyAlignment(alignment: ElementAndAlignment, index: GModelIndex): GAlignable | undefined {
50
- const element = getOrThrow(index.get(alignment.elementId), 'Model element not found! ID: ' + alignment.elementId);
51
- if (isGAlignable(element)) {
50
+ const element = index.find(alignment.elementId);
51
+ if (element && isGAlignable(element)) {
52
52
  element.alignment = alignment.newAlignment;
53
53
  return element;
54
54
  }
@@ -56,19 +56,20 @@ export function applyAlignment(alignment: ElementAndAlignment, index: GModelInde
56
56
  }
57
57
 
58
58
  /**
59
- * Applies the new route to the model.
59
+ * Applies the new route to the model. A route needs at least a source and a target point to describe an edge.
60
60
  *
61
61
  * @param route The new route.
62
62
  * @param index The model index.
63
- * @returns The changed element.
63
+ * @returns The changed edge, or `undefined` if the route could not be applied to any edge.
64
64
  */
65
- export function applyRoute(route: ElementAndRoutingPoints, index: GModelIndex): GEdge {
65
+ export function applyRoute(route: ElementAndRoutingPoints, index: GModelIndex): GEdge | undefined {
66
66
  const routingPoints = route.newRoutingPoints ?? [];
67
- if (routingPoints.length < 2) {
68
- throw new GLSPServerError('Invalid Route!');
67
+ const edge = index.findByClass(route.elementId, GEdge);
68
+ if (!edge || routingPoints.length < 2) {
69
+ return undefined;
69
70
  }
70
71
  // first and last point mark the source and target point
71
- const edge = applyRoutingPoints(route, index);
72
+ edge.routingPoints = routingPoints;
72
73
  const edgeRoutingPoints = edge.routingPoints;
73
74
 
74
75
  const args = edge.args ?? {};