@eclipse-glsp/server 2.8.0-next.1 → 2.8.0-next.12
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.
- package/lib/browser/launch/worker-server-launcher.js +3 -5
- package/lib/browser/launch/worker-server-launcher.js.map +1 -1
- package/lib/common/actions/action-dispatcher.js +5 -8
- package/lib/common/actions/action-dispatcher.js.map +1 -1
- package/lib/common/actions/action-handler-registry.js +1 -1
- package/lib/common/actions/action-handler-registry.js.map +1 -1
- package/lib/common/actions/global-action-provider.js +1 -2
- package/lib/common/actions/global-action-provider.js.map +1 -1
- package/lib/common/command/command.js +1 -2
- package/lib/common/command/command.js.map +1 -1
- package/lib/common/command/recording-command.js +3 -6
- package/lib/common/command/recording-command.js.map +1 -1
- package/lib/common/di/diagram-module.js +5 -6
- package/lib/common/di/diagram-module.js.map +1 -1
- package/lib/common/di/glsp-module.js +1 -1
- package/lib/common/di/glsp-module.js.map +1 -1
- package/lib/common/di/server-module.js +1 -1
- package/lib/common/di/server-module.js.map +1 -1
- package/lib/common/features/directediting/context-edit-validator.js +3 -3
- package/lib/common/features/directediting/context-edit-validator.js.map +1 -1
- package/lib/common/features/directediting/label-edit-validator.js +1 -1
- package/lib/common/features/directediting/label-edit-validator.js.map +1 -1
- package/lib/common/features/layout/computed-bounds-action-handler.d.ts +16 -1
- package/lib/common/features/layout/computed-bounds-action-handler.d.ts.map +1 -1
- package/lib/common/features/layout/computed-bounds-action-handler.js +41 -4
- package/lib/common/features/layout/computed-bounds-action-handler.js.map +1 -1
- package/lib/common/features/layout/layout-operation-handler.js +1 -2
- package/lib/common/features/layout/layout-operation-handler.js.map +1 -1
- package/lib/common/features/model/gmodel-index.js +3 -5
- package/lib/common/features/model/gmodel-index.js.map +1 -1
- package/lib/common/features/model/gmodel-serializer.js +1 -2
- package/lib/common/features/model/gmodel-serializer.js.map +1 -1
- package/lib/common/features/model/model-submission-handler.d.ts +1 -2
- package/lib/common/features/model/model-submission-handler.d.ts.map +1 -1
- package/lib/common/features/model/model-submission-handler.js +3 -6
- package/lib/common/features/model/model-submission-handler.js.map +1 -1
- package/lib/common/features/model/request-model-action-handler.js +4 -6
- package/lib/common/features/model/request-model-action-handler.js.map +1 -1
- package/lib/common/features/navigation/navigation-target-resolution.js +1 -1
- package/lib/common/features/navigation/navigation-target-resolution.js.map +1 -1
- package/lib/common/features/progress/progress-service.d.ts.map +1 -1
- package/lib/common/features/progress/progress-service.js +1 -2
- package/lib/common/features/progress/progress-service.js.map +1 -1
- package/lib/common/features/validation/request-markers-handler.js +1 -2
- package/lib/common/features/validation/request-markers-handler.js.map +1 -1
- package/lib/common/gmodel/change-routing-points-operation-handler.js +1 -2
- package/lib/common/gmodel/change-routing-points-operation-handler.js.map +1 -1
- package/lib/common/gmodel/gmodel-create-node-operation-handler.js +3 -5
- package/lib/common/gmodel/gmodel-create-node-operation-handler.js.map +1 -1
- package/lib/common/gmodel/paste-operation-handler.d.ts +1 -1
- package/lib/common/gmodel/paste-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/paste-operation-handler.js +8 -11
- package/lib/common/gmodel/paste-operation-handler.js.map +1 -1
- package/lib/common/launch/glsp-server-launcher.d.ts +8 -1
- package/lib/common/launch/glsp-server-launcher.d.ts.map +1 -1
- package/lib/common/launch/glsp-server-launcher.js +11 -1
- package/lib/common/launch/glsp-server-launcher.js.map +1 -1
- package/lib/common/launch/jsonrpc-server-launcher.d.ts +51 -2
- package/lib/common/launch/jsonrpc-server-launcher.d.ts.map +1 -1
- package/lib/common/launch/jsonrpc-server-launcher.js +82 -3
- package/lib/common/launch/jsonrpc-server-launcher.js.map +1 -1
- package/lib/common/operations/compound-operation-handler.js +1 -1
- package/lib/common/operations/compound-operation-handler.js.map +1 -1
- package/lib/common/operations/json-operation-handler.js +2 -3
- package/lib/common/operations/json-operation-handler.js.map +1 -1
- package/lib/common/protocol/glsp-server.js +6 -7
- package/lib/common/protocol/glsp-server.js.map +1 -1
- package/lib/common/session/client-session-manager.js +3 -5
- package/lib/common/session/client-session-manager.js.map +1 -1
- package/lib/common/utils/action-queue.js +2 -4
- package/lib/common/utils/action-queue.js.map +1 -1
- package/lib/common/utils/client-options-util.js +2 -2
- package/lib/common/utils/client-options-util.js.map +1 -1
- package/lib/common/utils/glsp-server-error.d.ts +2 -3
- package/lib/common/utils/glsp-server-error.d.ts.map +1 -1
- package/lib/common/utils/glsp-server-error.js +1 -1
- package/lib/common/utils/glsp-server-error.js.map +1 -1
- package/lib/common/utils/layout-util.d.ts +5 -5
- package/lib/common/utils/layout-util.d.ts.map +1 -1
- package/lib/common/utils/layout-util.js +17 -19
- package/lib/common/utils/layout-util.js.map +1 -1
- package/lib/common/utils/logger.js +1 -2
- package/lib/common/utils/logger.js.map +1 -1
- package/lib/node/abstract-json-model-storage.js +2 -4
- package/lib/node/abstract-json-model-storage.js.map +1 -1
- package/lib/node/launch/socket-server-launcher.d.ts +39 -2
- package/lib/node/launch/socket-server-launcher.d.ts.map +1 -1
- package/lib/node/launch/socket-server-launcher.js +50 -31
- package/lib/node/launch/socket-server-launcher.js.map +1 -1
- package/lib/node/launch/websocket-server-launcher.d.ts +36 -5
- package/lib/node/launch/websocket-server-launcher.d.ts.map +1 -1
- package/lib/node/launch/websocket-server-launcher.js +54 -13
- package/lib/node/launch/websocket-server-launcher.js.map +1 -1
- package/package.json +17 -21
- package/src/common/features/directediting/context-edit-validator.ts +2 -2
- package/src/common/features/layout/computed-bounds-action-handler.ts +52 -4
- package/src/common/features/model/model-submission-handler.ts +3 -2
- package/src/common/features/progress/progress-service.ts +2 -3
- package/src/common/gmodel/paste-operation-handler.ts +6 -6
- package/src/common/launch/glsp-server-launcher.ts +12 -1
- package/src/common/launch/jsonrpc-server-launcher.ts +89 -2
- package/src/common/utils/glsp-server-error.ts +3 -5
- package/src/common/utils/layout-util.ts +13 -12
- package/src/node/launch/socket-server-launcher.ts +54 -31
- package/src/node/launch/websocket-server-launcher.ts +72 -14
- package/src/browser/di/browser-action-dispatch-scope.spec.ts +0 -75
- package/src/common/actions/action-handler-registry.spec.ts +0 -52
- package/src/common/actions/global-action-provider.spec.ts +0 -68
- package/src/common/command/command-stack.spec.ts +0 -239
- package/src/common/command/command.spec.ts +0 -92
- package/src/common/command/recording-command.spec.ts +0 -86
- package/src/common/di/binding-target.spec.ts +0 -147
- package/src/common/di/multi-bindings.spec.ts +0 -133
- package/src/common/features/contextactions/context-actions-provider-registry.spec.ts +0 -69
- package/src/common/features/contextactions/request-context-actions-handler.spec.ts +0 -75
- package/src/common/features/contextactions/tool-palette-item-provider.spec.ts +0 -46
- package/src/common/features/directediting/context-edit-validator-registry.spec.ts +0 -54
- package/src/common/features/directediting/request-edit-validation-handler.spec.ts +0 -131
- package/src/common/features/model/gmodel-serializer.spec.ts +0 -141
- package/src/common/features/type-hints/request-type-hints-action-handler.spec.ts +0 -59
- package/src/common/operations/operation-handler-registry.spec.ts +0 -50
- package/src/common/protocol/glsp-server.spec.ts +0 -154
- package/src/common/session/client-session-factory.spec.ts +0 -60
- package/src/common/session/client-session-manager.spec.ts +0 -83
- package/src/common/test/mock-util.ts +0 -281
- package/src/common/utils/action-queue.spec.ts +0 -133
- package/src/common/utils/promise-queue.spec.ts +0 -142
- package/src/common/utils/registry.spec.ts +0 -225
- package/src/node/actions/action-dispatcher.spec.ts +0 -678
- package/src/node/launch/cli-parser.spec.ts +0 -61
- package/src/node/launch/socket-cli-parser.spec.ts +0 -73
- package/src/node/launch/socket-server-launcher.spec.ts +0 -74
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-
|
|
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
|
-
|
|
47
|
-
|
|
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));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-
|
|
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
|
|
@@ -14,11 +14,9 @@
|
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
16
|
export class GLSPServerError extends Error {
|
|
17
|
-
constructor(
|
|
18
|
-
message: string,
|
|
19
|
-
readonly cause?: unknown
|
|
20
|
-
) {
|
|
17
|
+
constructor(message: string, cause?: unknown) {
|
|
21
18
|
super(message);
|
|
19
|
+
this.cause = cause;
|
|
22
20
|
}
|
|
23
21
|
}
|
|
24
22
|
|
|
@@ -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 =
|
|
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 =
|
|
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
|
|
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
|
-
|
|
68
|
-
|
|
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
|
-
|
|
72
|
+
edge.routingPoints = routingPoints;
|
|
72
73
|
const edgeRoutingPoints = edge.routingPoints;
|
|
73
74
|
|
|
74
75
|
const args = edge.args ?? {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-
|
|
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
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
|
-
import { Disposable } from '@eclipse-glsp/protocol';
|
|
16
|
+
import { Disposable, Emitter } from '@eclipse-glsp/protocol';
|
|
17
17
|
import { inject, injectable } from 'inversify';
|
|
18
18
|
import * as net from 'net';
|
|
19
19
|
import * as jsonrpc from 'vscode-jsonrpc/node';
|
|
@@ -24,48 +24,71 @@ import { Logger } from '../../common/utils/logger';
|
|
|
24
24
|
export class SocketServerLauncher extends JsonRpcGLSPServerLauncher<net.TcpSocketConnectOpts> {
|
|
25
25
|
@inject(Logger) protected override logger: Logger;
|
|
26
26
|
|
|
27
|
-
protected netServer
|
|
27
|
+
protected netServer?: net.Server;
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
protected onConnectionEmitter = new Emitter<net.Socket>();
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Fires for every socket the server accepts, before the JSON-RPC connection is built on it.
|
|
33
|
+
*
|
|
34
|
+
* A listener must not consume the socket. Subscribe before {@link start} to observe the first connection; the
|
|
35
|
+
* subscription outlives an individual launch and is disposed by the caller.
|
|
36
|
+
*/
|
|
37
|
+
readonly onConnection = this.onConnectionEmitter.event;
|
|
38
|
+
|
|
39
|
+
protected override getServerSocket(): net.Server | undefined {
|
|
40
|
+
return this.netServer;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
protected override registerDisposables(): void {
|
|
44
|
+
super.registerDisposables();
|
|
31
45
|
this.toDispose.push(
|
|
32
46
|
Disposable.create(() => {
|
|
33
|
-
this.netServer
|
|
47
|
+
this.netServer?.close();
|
|
34
48
|
})
|
|
35
49
|
);
|
|
36
50
|
}
|
|
37
51
|
|
|
38
52
|
protected run(opts: net.TcpSocketConnectOpts): Promise<void> {
|
|
39
|
-
this.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
53
|
+
this.resetListening();
|
|
54
|
+
const netServer = net.createServer(socket => this.acceptConnection(socket));
|
|
55
|
+
this.netServer = netServer;
|
|
43
56
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (!addressInfo) {
|
|
48
|
-
this.logger.error('Could not resolve GLSP Server address info. Shutting down.');
|
|
49
|
-
this.shutdown();
|
|
50
|
-
return;
|
|
51
|
-
} else if (typeof addressInfo === 'string') {
|
|
52
|
-
this.logger.error(`GLSP Server is unexpectedly listening to pipe or domain socket "${addressInfo}". Shutting down.`);
|
|
53
|
-
this.shutdown();
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const currentPort = addressInfo.port;
|
|
57
|
-
this.logger.info(`The GLSP server is ready to accept new client requests on port: ${currentPort}`);
|
|
58
|
-
// Print a message to the output stream that indicates that the start is completed.
|
|
59
|
-
// This indicates to the client that the server process is ready (in an embedded scenario).
|
|
60
|
-
console.log(this.startupCompleteMessage.concat(currentPort.toString()));
|
|
61
|
-
});
|
|
62
|
-
this.netServer.on('error', () => this.shutdown());
|
|
57
|
+
netServer.listen(opts.port, opts.host);
|
|
58
|
+
netServer.on('listening', () => this.handleListening(netServer));
|
|
59
|
+
netServer.on('error', error => this.handleError(error));
|
|
63
60
|
return new Promise((resolve, reject) => {
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
netServer.on('close', () => resolve(undefined));
|
|
62
|
+
netServer.on('error', error => reject(error));
|
|
66
63
|
});
|
|
67
64
|
}
|
|
68
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Takes up a socket the server accepted. Observers are notified before the socket is read from.
|
|
68
|
+
*
|
|
69
|
+
* @param socket The accepted socket.
|
|
70
|
+
*/
|
|
71
|
+
protected acceptConnection(socket: net.Socket): void {
|
|
72
|
+
this.onConnectionEmitter.fire(socket);
|
|
73
|
+
this.createServerInstance(this.createConnection(socket));
|
|
74
|
+
}
|
|
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
|
+
protected handleListening(server: net.Server): void {
|
|
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
|
+
}
|
|
91
|
+
|
|
69
92
|
protected createConnection(socket: net.Socket): jsonrpc.MessageConnection {
|
|
70
93
|
return jsonrpc.createMessageConnection(new jsonrpc.SocketMessageReader(socket), new jsonrpc.SocketMessageWriter(socket), console);
|
|
71
94
|
}
|
|
@@ -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
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
16
|
|
|
17
|
-
import { createWebSocketConnection, Disposable, MaybePromise, WebSocketWrapper } from '@eclipse-glsp/protocol';
|
|
17
|
+
import { createWebSocketConnection, Disposable, Emitter, MaybePromise, WebSocketWrapper } from '@eclipse-glsp/protocol';
|
|
18
18
|
import * as http from 'http';
|
|
19
19
|
import { inject, injectable } from 'inversify';
|
|
20
20
|
import * as net from 'net';
|
|
21
21
|
import * as jsonrpc from 'vscode-jsonrpc';
|
|
22
|
-
import {
|
|
22
|
+
import { WebSocket, WebSocketServer } from 'ws';
|
|
23
23
|
import { JsonRpcGLSPServerLauncher } from '../../common/launch/jsonrpc-server-launcher';
|
|
24
24
|
import { Logger } from '../../common/utils/logger';
|
|
25
25
|
|
|
@@ -41,6 +41,13 @@ export interface WebsocketConnectionData {
|
|
|
41
41
|
connection: jsonrpc.MessageConnection;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/** An accepted web socket together with the upgrade request it was negotiated with. */
|
|
45
|
+
export interface AcceptedWebSocket {
|
|
46
|
+
socket: WebSocket;
|
|
47
|
+
/** The handshake request, the only place where its headers and query are still available. */
|
|
48
|
+
request: http.IncomingMessage;
|
|
49
|
+
}
|
|
50
|
+
|
|
44
51
|
const STATUS_UPGRADE_REQUIRED = 426;
|
|
45
52
|
|
|
46
53
|
@injectable()
|
|
@@ -48,35 +55,86 @@ export class WebSocketServerLauncher extends JsonRpcGLSPServerLauncher<WebSocket
|
|
|
48
55
|
@inject(Logger)
|
|
49
56
|
protected override logger: Logger;
|
|
50
57
|
|
|
51
|
-
protected server
|
|
58
|
+
protected server?: WebSocketServer;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The HTTP server the web socket server is mounted on.
|
|
62
|
+
*
|
|
63
|
+
* Held separately because `ws` only closes an HTTP server it created itself, so releasing the socket is up to us.
|
|
64
|
+
*/
|
|
65
|
+
protected httpServer?: http.Server;
|
|
52
66
|
|
|
53
|
-
|
|
54
|
-
|
|
67
|
+
protected onConnectionEmitter = new Emitter<AcceptedWebSocket>();
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Fires for every web socket the server accepts, before the JSON-RPC connection is built on it.
|
|
71
|
+
*
|
|
72
|
+
* A listener must not consume the socket. Subscribe before {@link start} to observe the first connection; the
|
|
73
|
+
* subscription outlives an individual launch and is disposed by the caller.
|
|
74
|
+
*/
|
|
75
|
+
readonly onConnection = this.onConnectionEmitter.event;
|
|
76
|
+
|
|
77
|
+
protected override getServerSocket(): net.Server | undefined {
|
|
78
|
+
return this.httpServer;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
protected override registerDisposables(): void {
|
|
82
|
+
super.registerDisposables();
|
|
55
83
|
this.toDispose.push(
|
|
56
84
|
Disposable.create(() => {
|
|
57
|
-
this.server
|
|
85
|
+
this.server?.close();
|
|
86
|
+
// `ws` leaves an HTTP server it did not create itself listening, so close ours explicitly.
|
|
87
|
+
this.httpServer?.close();
|
|
88
|
+
this.httpServer = undefined;
|
|
58
89
|
})
|
|
59
90
|
);
|
|
60
91
|
}
|
|
61
92
|
|
|
62
93
|
protected async run(options: WebSocketServerOptions): Promise<void> {
|
|
94
|
+
this.resetListening();
|
|
63
95
|
const resolvedOptions = await this.resolveOptions(options);
|
|
64
|
-
this.
|
|
96
|
+
if (!this.running) {
|
|
97
|
+
// Shut down while the options were being resolved, so release the socket they already bound.
|
|
98
|
+
resolvedOptions.server.close();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.httpServer = resolvedOptions.server;
|
|
102
|
+
this.server = new WebSocketServer({ server: resolvedOptions.server, path: resolvedOptions.path });
|
|
65
103
|
const endpoint = `ws://${resolvedOptions.host}:${resolvedOptions.port}:${resolvedOptions.path}`;
|
|
66
104
|
this.logger.info(`The GLSP Websocket launcher is ready to accept new client requests on endpoint '${endpoint}'`);
|
|
67
105
|
console.log(this.startupCompleteMessage.concat(resolvedOptions.port.toString()));
|
|
68
106
|
|
|
69
|
-
this.server
|
|
70
|
-
|
|
71
|
-
this.createServerInstance(connection);
|
|
72
|
-
});
|
|
107
|
+
this.observeListening(resolvedOptions.server);
|
|
108
|
+
this.server.on('connection', (ws, request) => this.acceptConnection(ws, request));
|
|
73
109
|
|
|
110
|
+
const server = this.server;
|
|
74
111
|
return new Promise((resolve, reject) => {
|
|
75
|
-
|
|
76
|
-
|
|
112
|
+
server.on('close', () => resolve(undefined));
|
|
113
|
+
server.on('error', error => reject(error));
|
|
77
114
|
});
|
|
78
115
|
}
|
|
79
116
|
|
|
117
|
+
/** Settles {@link listening} from the HTTP server, which may already be bound by the time we get here. */
|
|
118
|
+
protected observeListening(server: http.Server): void {
|
|
119
|
+
if (server.listening) {
|
|
120
|
+
this.settleListening(server);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
server.on('listening', () => this.settleListening(server));
|
|
124
|
+
server.on('error', error => this.handleError(error));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Takes up a web socket the server accepted. Observers are notified before the socket is read from.
|
|
129
|
+
*
|
|
130
|
+
* @param socket The accepted web socket.
|
|
131
|
+
* @param request The upgrade request the socket was negotiated with.
|
|
132
|
+
*/
|
|
133
|
+
protected acceptConnection(socket: WebSocket, request: http.IncomingMessage): void {
|
|
134
|
+
this.onConnectionEmitter.fire({ socket, request });
|
|
135
|
+
this.createServerInstance(this.createConnection(socket));
|
|
136
|
+
}
|
|
137
|
+
|
|
80
138
|
protected createConnection(socket: WebSocket): jsonrpc.MessageConnection {
|
|
81
139
|
return createWebSocketConnection(wrapWebSocket(socket));
|
|
82
140
|
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2026 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
|
-
import { Action } from '@eclipse-glsp/protocol';
|
|
17
|
-
import { expect } from 'chai';
|
|
18
|
-
import { ClientAction } from '../../common/protocol/client-action';
|
|
19
|
-
import * as mock from '../../common/test/mock-util';
|
|
20
|
-
import { BrowserActionDispatchScope } from './browser-action-dispatch-scope';
|
|
21
|
-
|
|
22
|
-
describe('BrowserActionDispatchScope', () => {
|
|
23
|
-
const action: Action = { kind: 'foo' };
|
|
24
|
-
const markedClientAction = ((): Action => {
|
|
25
|
-
const a: Action = { kind: 'bar' };
|
|
26
|
-
ClientAction.mark(a);
|
|
27
|
-
return a;
|
|
28
|
-
})();
|
|
29
|
-
|
|
30
|
-
let scope: BrowserActionDispatchScope;
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
scope = new BrowserActionDispatchScope();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('isReentrant is false outside enter()', () => {
|
|
36
|
-
expect(scope.isReentrant(action)).to.be.false;
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('isReentrant is true during a synchronous enter()', () => {
|
|
40
|
-
scope.enter(() => {
|
|
41
|
-
expect(scope.isReentrant(action)).to.be.true;
|
|
42
|
-
});
|
|
43
|
-
expect(scope.isReentrant(action)).to.be.false;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('isReentrant is true during an async enter() and false after settle', async () => {
|
|
47
|
-
const probe: Promise<boolean> = scope.enter(async () => {
|
|
48
|
-
await Promise.resolve();
|
|
49
|
-
return scope.isReentrant(action);
|
|
50
|
-
});
|
|
51
|
-
expect(await probe).to.be.true;
|
|
52
|
-
expect(scope.isReentrant(action)).to.be.false;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('resets active flag when callback throws synchronously', () => {
|
|
56
|
-
expect(() =>
|
|
57
|
-
scope.enter(() => {
|
|
58
|
-
throw new Error('boom');
|
|
59
|
-
})
|
|
60
|
-
).to.throw('boom');
|
|
61
|
-
expect(scope.isReentrant(action)).to.be.false;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('resets active flag when async callback rejects', async () => {
|
|
65
|
-
await mock.expectToThrowAsync(() => scope.enter(() => Promise.reject(new Error('boom'))), 'boom');
|
|
66
|
-
expect(scope.isReentrant(action)).to.be.false;
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('isReentrant is false for client-originated actions even when scope is active', () => {
|
|
70
|
-
scope.enter(() => {
|
|
71
|
-
expect(scope.isReentrant(markedClientAction)).to.be.false;
|
|
72
|
-
expect(scope.isReentrant(action)).to.be.true;
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2023 STMicroelectronics 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
|
-
import * as mock from '../test/mock-util';
|
|
17
|
-
import { ActionHandlerRegistry } from './action-handler-registry';
|
|
18
|
-
import { expect } from 'chai';
|
|
19
|
-
|
|
20
|
-
describe('Test ActionHandlerRegistry (only functionality that is not covered by "registry.spec.ts"', () => {
|
|
21
|
-
const singleAction = 'singleHandledAction';
|
|
22
|
-
const multiAction = 'multiHandledAction';
|
|
23
|
-
|
|
24
|
-
const h1 = new mock.StubActionHandler([singleAction]);
|
|
25
|
-
const h2 = new mock.StubActionHandler([multiAction]);
|
|
26
|
-
const h3 = new mock.StubActionHandler([multiAction]);
|
|
27
|
-
const h4 = new mock.StubActionHandler([multiAction]);
|
|
28
|
-
const registry: ActionHandlerRegistry = new ActionHandlerRegistry();
|
|
29
|
-
|
|
30
|
-
it('registerHandler - should register given handlers', () => {
|
|
31
|
-
// setup
|
|
32
|
-
registry.registerHandler(h1);
|
|
33
|
-
registry.registerHandler(h2);
|
|
34
|
-
registry.registerHandler(h3);
|
|
35
|
-
registry.registerHandler(h4);
|
|
36
|
-
|
|
37
|
-
const result = registry.getAll();
|
|
38
|
-
expect(result).to.have.length(4);
|
|
39
|
-
expect(result.includes(h1)).true;
|
|
40
|
-
expect(result.includes(h2)).true;
|
|
41
|
-
expect(result.includes(h3)).true;
|
|
42
|
-
expect(result.includes(h4)).true;
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('get - should return three handlers sorted by priority', () => {
|
|
46
|
-
const result = registry.get(multiAction);
|
|
47
|
-
expect(result.length).to.be.equal(3);
|
|
48
|
-
expect(result[0]).to.be.deep.equal(h4);
|
|
49
|
-
expect(result[1]).to.be.deep.equal(h2);
|
|
50
|
-
expect(result[2]).to.be.deep.equal(h3);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2023 STMicroelectronics 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
|
-
import { expect } from 'chai';
|
|
17
|
-
import { Container, ContainerModule } from 'inversify';
|
|
18
|
-
import * as sinon from 'sinon';
|
|
19
|
-
import { DiagramModules, InjectionContainer } from '../di/service-identifiers';
|
|
20
|
-
import { ClientSessionInitializer } from '../session/client-session-initializer';
|
|
21
|
-
import * as mock from '../test/mock-util';
|
|
22
|
-
import { Logger } from '../utils/logger';
|
|
23
|
-
import { ActionHandler } from './action-handler';
|
|
24
|
-
import { ActionHandlerRegistry } from './action-handler-registry';
|
|
25
|
-
import { DefaultGlobalActionProvider } from './global-action-provider';
|
|
26
|
-
|
|
27
|
-
describe('test DefaultGlobalActionProvider', () => {
|
|
28
|
-
const container = new Container();
|
|
29
|
-
const serverActions = ['A1', 'A2', 'A3'];
|
|
30
|
-
const diagramType = 'myDiagramType';
|
|
31
|
-
|
|
32
|
-
const handler1Actions = ['A1', 'A2'];
|
|
33
|
-
const handler2Actions = ['A2', 'A3'];
|
|
34
|
-
|
|
35
|
-
const h1 = new mock.StubActionHandler(handler1Actions);
|
|
36
|
-
const h2 = new mock.StubActionHandler(handler2Actions);
|
|
37
|
-
|
|
38
|
-
const handlerRegistry = new ActionHandlerRegistry();
|
|
39
|
-
sinon.stub(handlerRegistry, 'getAll').returns([h1, h2]);
|
|
40
|
-
|
|
41
|
-
const diagramModule1 = new ContainerModule(bind => {
|
|
42
|
-
bind(ClientSessionInitializer).toConstantValue(new mock.StubClientSessionInitializer());
|
|
43
|
-
bind(ActionHandler).toConstantValue(new mock.StubActionHandler(handler1Actions));
|
|
44
|
-
bind(ActionHandler).toConstantValue(new mock.StubActionHandler(handler2Actions));
|
|
45
|
-
bind(ActionHandlerRegistry).toConstantValue(handlerRegistry);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const diagramModules = new Map<string, ContainerModule[]>();
|
|
49
|
-
diagramModules.set(diagramType, [diagramModule1]);
|
|
50
|
-
|
|
51
|
-
container.load(
|
|
52
|
-
new ContainerModule(bind => {
|
|
53
|
-
bind(Logger).toConstantValue(new mock.StubLogger());
|
|
54
|
-
bind(InjectionContainer).toConstantValue(container);
|
|
55
|
-
bind(DiagramModules).toConstantValue(diagramModules);
|
|
56
|
-
})
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const actionProvider = container.resolve(DefaultGlobalActionProvider);
|
|
60
|
-
|
|
61
|
-
it('serverActionsKinds', () => {
|
|
62
|
-
const result = actionProvider.actionKinds;
|
|
63
|
-
expect(result.size).to.be.equal(1);
|
|
64
|
-
const resultServerActions = result.get(diagramType);
|
|
65
|
-
expect(resultServerActions).to.not.be.undefined;
|
|
66
|
-
expect(serverActions.every(action => resultServerActions!.includes(action))).true;
|
|
67
|
-
});
|
|
68
|
-
});
|