@eclipse-glsp/server 1.1.0-RC10 → 1.1.0-next.342c713.66
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 +26 -2
- package/lib/browser/launch/worker-server-launcher.js.map +1 -1
- package/lib/common/actions/action-dispatcher.d.ts +2 -1
- package/lib/common/actions/action-dispatcher.d.ts.map +1 -1
- package/lib/common/actions/action-dispatcher.js +9 -6
- package/lib/common/actions/action-dispatcher.js.map +1 -1
- package/lib/common/actions/action-handler-registry.js +4 -2
- package/lib/common/actions/action-handler-registry.js.map +1 -1
- package/lib/common/actions/client-action-handler.d.ts +17 -8
- package/lib/common/actions/client-action-handler.d.ts.map +1 -1
- package/lib/common/actions/client-action-handler.js +32 -21
- package/lib/common/actions/client-action-handler.js.map +1 -1
- package/lib/common/actions/global-action-provider.d.ts +6 -21
- package/lib/common/actions/global-action-provider.d.ts.map +1 -1
- package/lib/common/actions/global-action-provider.js +17 -21
- package/lib/common/actions/global-action-provider.js.map +1 -1
- package/lib/common/command/command-stack.js +2 -1
- package/lib/common/command/command-stack.js.map +1 -1
- package/lib/common/command/recording-command.d.ts +9 -14
- package/lib/common/command/recording-command.d.ts.map +1 -1
- package/lib/common/command/recording-command.js +36 -27
- package/lib/common/command/recording-command.js.map +1 -1
- package/lib/common/command/undo-redo-action-handler.js +2 -1
- package/lib/common/command/undo-redo-action-handler.js.map +1 -1
- package/lib/common/di/client-session-module.d.ts +9 -1
- package/lib/common/di/client-session-module.d.ts.map +1 -1
- package/lib/common/di/client-session-module.js +9 -9
- package/lib/common/di/client-session-module.js.map +1 -1
- package/lib/common/di/diagram-module.d.ts +20 -1
- package/lib/common/di/diagram-module.d.ts.map +1 -1
- package/lib/common/di/diagram-module.js +10 -48
- package/lib/common/di/diagram-module.js.map +1 -1
- package/lib/common/di/glsp-module.js +2 -1
- package/lib/common/di/glsp-module.js.map +1 -1
- package/lib/common/di/server-module.d.ts +0 -1
- package/lib/common/di/server-module.d.ts.map +1 -1
- package/lib/common/di/server-module.js +0 -1
- package/lib/common/di/server-module.js.map +1 -1
- package/lib/common/diagram/request-type-hints-action-handler.js +2 -1
- package/lib/common/diagram/request-type-hints-action-handler.js.map +1 -1
- package/lib/common/features/clipboard/request-clipboard-data-action-handler.js +2 -1
- package/lib/common/features/clipboard/request-clipboard-data-action-handler.js.map +1 -1
- package/lib/common/features/contextactions/command-palette-action-provider.js +2 -1
- package/lib/common/features/contextactions/command-palette-action-provider.js.map +1 -1
- package/lib/common/features/contextactions/context-actions-provider-registry.js +2 -1
- package/lib/common/features/contextactions/context-actions-provider-registry.js.map +1 -1
- package/lib/common/features/contextactions/context-menu-item-provider.js +2 -1
- package/lib/common/features/contextactions/context-menu-item-provider.js.map +1 -1
- package/lib/common/features/contextactions/request-context-actions-handler.js +2 -1
- package/lib/common/features/contextactions/request-context-actions-handler.js.map +1 -1
- package/lib/common/features/contextactions/tool-palette-item-provider.js +4 -2
- package/lib/common/features/contextactions/tool-palette-item-provider.js.map +1 -1
- package/lib/common/features/directediting/context-edit-validator-registry.js +2 -1
- package/lib/common/features/directediting/context-edit-validator-registry.js.map +1 -1
- package/lib/common/features/directediting/label-edit-validator.js +2 -1
- package/lib/common/features/directediting/label-edit-validator.js.map +1 -1
- package/lib/common/features/directediting/request-edit-validation-handler.js +2 -1
- package/lib/common/features/directediting/request-edit-validation-handler.js.map +1 -1
- package/lib/common/features/layout/computed-bounds-action-handler.js +2 -1
- package/lib/common/features/layout/computed-bounds-action-handler.js.map +1 -1
- package/lib/common/features/layout/layout-operation-handler.js +2 -1
- package/lib/common/features/layout/layout-operation-handler.js.map +1 -1
- package/lib/common/features/model/gmodel-factory.js +2 -1
- package/lib/common/features/model/gmodel-factory.js.map +1 -1
- package/lib/common/features/model/gmodel-index.js +2 -1
- package/lib/common/features/model/gmodel-index.js.map +1 -1
- package/lib/common/features/model/gmodel-serializer.js +2 -1
- package/lib/common/features/model/gmodel-serializer.js.map +1 -1
- package/lib/common/features/model/model-state.d.ts.map +1 -1
- package/lib/common/features/model/model-state.js +5 -1
- package/lib/common/features/model/model-state.js.map +1 -1
- package/lib/common/features/model/model-submission-handler.d.ts +30 -2
- package/lib/common/features/model/model-submission-handler.d.ts.map +1 -1
- package/lib/common/features/model/model-submission-handler.js +58 -8
- package/lib/common/features/model/model-submission-handler.js.map +1 -1
- package/lib/common/features/model/request-model-action-handler.d.ts +5 -6
- package/lib/common/features/model/request-model-action-handler.d.ts.map +1 -1
- package/lib/common/features/model/request-model-action-handler.js +37 -14
- package/lib/common/features/model/request-model-action-handler.js.map +1 -1
- package/lib/common/features/model/save-model-action-handler.js +2 -1
- package/lib/common/features/model/save-model-action-handler.js.map +1 -1
- package/lib/common/features/navigation/navigation-target-provider-registry.js +2 -1
- package/lib/common/features/navigation/navigation-target-provider-registry.js.map +1 -1
- package/lib/common/features/navigation/navigation-target-resolver.js +2 -1
- package/lib/common/features/navigation/navigation-target-resolver.js.map +1 -1
- package/lib/common/features/navigation/request-navigation-targets-action-handler.js +2 -1
- package/lib/common/features/navigation/request-navigation-targets-action-handler.js.map +1 -1
- package/lib/common/features/navigation/resolve-navigation-targets-action-handler.js +2 -1
- package/lib/common/features/navigation/resolve-navigation-targets-action-handler.js.map +1 -1
- package/lib/common/features/popup/request-popup-model-action-handler.js +2 -1
- package/lib/common/features/popup/request-popup-model-action-handler.js.map +1 -1
- package/lib/common/features/progress/progress-service.d.ts +44 -0
- package/lib/common/features/progress/progress-service.d.ts.map +1 -0
- package/lib/common/features/progress/progress-service.js +74 -0
- package/lib/common/features/progress/progress-service.js.map +1 -0
- package/lib/common/features/validation/model-validator.d.ts +47 -2
- package/lib/common/features/validation/model-validator.d.ts.map +1 -1
- package/lib/common/features/validation/model-validator.js +80 -1
- package/lib/common/features/validation/model-validator.js.map +1 -1
- package/lib/common/features/validation/request-markers-handler.d.ts +15 -0
- package/lib/common/features/validation/request-markers-handler.d.ts.map +1 -1
- package/lib/common/features/validation/request-markers-handler.js +5 -10
- package/lib/common/features/validation/request-markers-handler.js.map +1 -1
- package/lib/common/gmodel/apply-label-edit-operation-handler.js +2 -1
- package/lib/common/gmodel/apply-label-edit-operation-handler.js.map +1 -1
- package/lib/common/gmodel/change-bounds-operation-handler.js +2 -1
- package/lib/common/gmodel/change-bounds-operation-handler.js.map +1 -1
- package/lib/common/gmodel/change-routing-points-operation-handler.js +2 -1
- package/lib/common/gmodel/change-routing-points-operation-handler.js.map +1 -1
- package/lib/common/gmodel/cut-operation-handler.js +2 -1
- package/lib/common/gmodel/cut-operation-handler.js.map +1 -1
- package/lib/common/gmodel/delete-operation-handler.js +2 -1
- package/lib/common/gmodel/delete-operation-handler.js.map +1 -1
- package/lib/common/gmodel/gmodel-create-edge-operation-handler.d.ts +3 -3
- package/lib/common/gmodel/gmodel-create-edge-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/gmodel-create-edge-operation-handler.js +2 -1
- package/lib/common/gmodel/gmodel-create-edge-operation-handler.js.map +1 -1
- package/lib/common/gmodel/gmodel-create-node-operation-handler.d.ts +3 -3
- package/lib/common/gmodel/gmodel-create-node-operation-handler.d.ts.map +1 -1
- package/lib/common/gmodel/gmodel-create-node-operation-handler.js +2 -1
- package/lib/common/gmodel/gmodel-create-node-operation-handler.js.map +1 -1
- package/lib/common/gmodel/gmodel-diagram-module.js +2 -1
- package/lib/common/gmodel/gmodel-diagram-module.js.map +1 -1
- package/lib/common/gmodel/paste-operation-handler.js +26 -2
- package/lib/common/gmodel/paste-operation-handler.js.map +1 -1
- package/lib/common/gmodel/reconnect-edge-operation-handler.js +2 -1
- package/lib/common/gmodel/reconnect-edge-operation-handler.js.map +1 -1
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +1 -0
- package/lib/common/index.js.map +1 -1
- package/lib/common/launch/glsp-server-launcher.js +2 -1
- package/lib/common/launch/glsp-server-launcher.js.map +1 -1
- package/lib/common/launch/jsonrpc-server-launcher.js +2 -1
- package/lib/common/launch/jsonrpc-server-launcher.js.map +1 -1
- package/lib/common/operations/compound-operation-handler.d.ts +5 -0
- package/lib/common/operations/compound-operation-handler.d.ts.map +1 -1
- package/lib/common/operations/compound-operation-handler.js +8 -2
- package/lib/common/operations/compound-operation-handler.js.map +1 -1
- package/lib/common/operations/create-operation-handler.d.ts +19 -5
- package/lib/common/operations/create-operation-handler.d.ts.map +1 -1
- package/lib/common/operations/create-operation-handler.js +2 -1
- package/lib/common/operations/create-operation-handler.js.map +1 -1
- package/lib/common/operations/json-operation-handler.d.ts +94 -0
- package/lib/common/operations/json-operation-handler.d.ts.map +1 -0
- package/lib/common/operations/json-operation-handler.js +120 -0
- package/lib/common/operations/json-operation-handler.js.map +1 -0
- package/lib/common/operations/operation-action-handler.d.ts.map +1 -1
- package/lib/common/operations/operation-action-handler.js +3 -2
- package/lib/common/operations/operation-action-handler.js.map +1 -1
- package/lib/common/operations/operation-handler-registry.d.ts +1 -9
- package/lib/common/operations/operation-handler-registry.d.ts.map +1 -1
- package/lib/common/operations/operation-handler-registry.js +4 -12
- package/lib/common/operations/operation-handler-registry.js.map +1 -1
- package/lib/common/operations/operation-handler.d.ts +2 -2
- package/lib/common/operations/operation-handler.d.ts.map +1 -1
- package/lib/common/operations/operation-handler.js +2 -1
- package/lib/common/operations/operation-handler.js.map +1 -1
- package/lib/common/protocol/client-action.d.ts +31 -0
- package/lib/common/protocol/client-action.d.ts.map +1 -0
- package/lib/common/protocol/client-action.js +35 -0
- package/lib/common/protocol/client-action.js.map +1 -0
- package/lib/common/protocol/glsp-server.d.ts +1 -1
- package/lib/common/protocol/glsp-server.d.ts.map +1 -1
- package/lib/common/protocol/glsp-server.js +9 -10
- package/lib/common/protocol/glsp-server.js.map +1 -1
- package/lib/common/session/client-session-factory.js +5 -4
- package/lib/common/session/client-session-factory.js.map +1 -1
- package/lib/common/session/client-session-manager.js +2 -1
- package/lib/common/session/client-session-manager.js.map +1 -1
- package/lib/common/utils/client-options-util.d.ts +3 -0
- package/lib/common/utils/client-options-util.d.ts.map +1 -1
- package/lib/common/utils/client-options-util.js +5 -15
- package/lib/common/utils/client-options-util.js.map +1 -1
- package/lib/common/utils/console-logger.js +2 -1
- package/lib/common/utils/console-logger.js.map +1 -1
- package/lib/common/utils/logger.js +2 -1
- package/lib/common/utils/logger.js.map +1 -1
- package/lib/common/utils/promise-queue.d.ts.map +1 -1
- package/lib/common/utils/promise-queue.js +3 -6
- package/lib/common/utils/promise-queue.js.map +1 -1
- package/lib/common/utils/registry.d.ts +3 -1
- package/lib/common/utils/registry.d.ts.map +1 -1
- package/lib/common/utils/registry.js +15 -4
- package/lib/common/utils/registry.js.map +1 -1
- package/lib/node/abstract-json-model-storage.d.ts.map +1 -1
- package/lib/node/abstract-json-model-storage.js +33 -3
- package/lib/node/abstract-json-model-storage.js.map +1 -1
- package/lib/node/di/app-module.js +24 -1
- package/lib/node/di/app-module.js.map +1 -1
- package/lib/node/gmodel/gmodel-storage.js +2 -1
- package/lib/node/gmodel/gmodel-storage.js.map +1 -1
- package/lib/node/launch/cli-parser.js +26 -3
- package/lib/node/launch/cli-parser.js.map +1 -1
- package/lib/node/launch/socket-cli-parser.js +24 -1
- package/lib/node/launch/socket-cli-parser.js.map +1 -1
- package/lib/node/launch/socket-server-launcher.js +27 -3
- package/lib/node/launch/socket-server-launcher.js.map +1 -1
- package/lib/node/launch/websocket-server-launcher.js +27 -3
- package/lib/node/launch/websocket-server-launcher.js.map +1 -1
- package/package.json +4 -5
- package/src/common/actions/action-dispatcher.spec.ts +3 -2
- package/src/common/actions/action-dispatcher.ts +8 -5
- package/src/common/actions/client-action-handler.ts +28 -18
- package/src/common/actions/global-action-provider.spec.ts +4 -15
- package/src/common/actions/global-action-provider.ts +21 -25
- package/src/common/command/recording-command.spec.ts +15 -5
- package/src/common/command/recording-command.ts +16 -26
- package/src/common/di/client-session-module.ts +17 -10
- package/src/common/di/diagram-module.ts +14 -66
- package/src/common/di/server-module.ts +0 -1
- package/src/common/features/model/model-state.ts +3 -0
- package/src/common/features/model/model-submission-handler.ts +63 -6
- package/src/common/features/model/request-model-action-handler.ts +37 -17
- package/src/common/features/progress/progress-service.ts +74 -0
- package/src/common/features/validation/model-validator.ts +75 -3
- package/src/common/features/validation/request-markers-handler.ts +4 -10
- package/src/common/gmodel/gmodel-create-edge-operation-handler.ts +3 -3
- package/src/common/gmodel/gmodel-create-node-operation-handler.ts +3 -3
- package/src/common/index.ts +1 -0
- package/src/common/operations/compound-operation-handler.ts +6 -1
- package/src/common/operations/create-operation-handler.ts +22 -5
- package/src/common/operations/json-operation-handler.ts +147 -0
- package/src/common/operations/operation-action-handler.ts +2 -2
- package/src/common/operations/operation-handler-registry.ts +1 -12
- package/src/common/operations/operation-handler.ts +2 -2
- package/src/common/protocol/client-action.ts +38 -0
- package/src/common/protocol/glsp-server.spec.ts +11 -10
- package/src/common/protocol/glsp-server.ts +11 -14
- package/src/common/session/client-session-factory.spec.ts +2 -2
- package/src/common/session/client-session-factory.ts +3 -3
- package/src/common/session/client-session-manager.spec.ts +4 -3
- package/src/common/utils/client-options-util.ts +8 -0
- package/src/common/utils/promise-queue.ts +4 -5
- package/src/common/utils/registry.spec.ts +3 -1
- package/src/common/utils/registry.ts +8 -3
- package/src/node/abstract-json-model-storage.ts +8 -2
- package/src/node/launch/cli-parser.ts +1 -1
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
16
|
import { GModelElement } from '@eclipse-glsp/graph';
|
|
17
|
-
import { Marker, MaybePromise } from '@eclipse-glsp/protocol';
|
|
17
|
+
import { Marker, MarkersReason, MaybePromise } from '@eclipse-glsp/protocol';
|
|
18
|
+
import { injectable } from 'inversify';
|
|
18
19
|
|
|
19
20
|
export const ModelValidator = Symbol('ModelValidator');
|
|
20
21
|
|
|
@@ -28,7 +29,78 @@ export interface ModelValidator {
|
|
|
28
29
|
* Validates the given list of {@link GModelElement}s and returns a list of {@link Marker}s.
|
|
29
30
|
*
|
|
30
31
|
* @param elements The list of {@link GModelElement} to validate.
|
|
31
|
-
* @
|
|
32
|
+
* @param reason The reason for a validation request, such as "batch" or "live" validation.
|
|
33
|
+
* @return A list of {@link Marker}s for the validated {@link GModelElement}s.
|
|
32
34
|
*/
|
|
33
|
-
validate(elements: GModelElement[]): MaybePromise<Marker[]>;
|
|
35
|
+
validate(elements: GModelElement[], reason?: string): MaybePromise<Marker[]>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@injectable()
|
|
39
|
+
export abstract class AbstractModelValidator implements ModelValidator {
|
|
40
|
+
validate(elements: GModelElement[], reason: string): Marker[] {
|
|
41
|
+
const markers: Marker[] = [];
|
|
42
|
+
for (const element of elements) {
|
|
43
|
+
if (MarkersReason.LIVE === reason) {
|
|
44
|
+
markers.push(...this.doLiveValidation(element));
|
|
45
|
+
} else if (MarkersReason.BATCH === reason) {
|
|
46
|
+
markers.push(...this.doBatchValidation(element));
|
|
47
|
+
} else {
|
|
48
|
+
markers.push(...this.doValidationForCustomReason(element));
|
|
49
|
+
}
|
|
50
|
+
if (element.children) {
|
|
51
|
+
markers.push(...this.validate(element.children, reason));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return markers;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Perform the live validation rules for the given <code>element</code>.
|
|
59
|
+
*
|
|
60
|
+
* This will be invoked on start and after each operation for all elements.
|
|
61
|
+
* Thus, the validation should be rather inexpensive.
|
|
62
|
+
* There is no need to traverse through the children in this method as {@link #validate(List, String)} will invoke
|
|
63
|
+
* this method for all children anyway.
|
|
64
|
+
*
|
|
65
|
+
* @param element The element to validate.
|
|
66
|
+
* @return A list of {@link Marker}s for the validated {@link GModelElement}.
|
|
67
|
+
*/
|
|
68
|
+
doLiveValidation(element: GModelElement): Marker[] {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Perform the batch validation rules for the given <code>element</code>.
|
|
74
|
+
*
|
|
75
|
+
* <p>
|
|
76
|
+
* This will be invoked on demand by the client.
|
|
77
|
+
* Thus, the validation can include more expensive validation rules.
|
|
78
|
+
* There is no need to traverse through the children in this method as {@link #validate(List, String)} will invoke
|
|
79
|
+
* this method for all children anyway.
|
|
80
|
+
* </p>
|
|
81
|
+
*
|
|
82
|
+
* @param element The element to validate.
|
|
83
|
+
* @return A list of {@link Marker}s for the validated {@link GModelElement}.
|
|
84
|
+
*/
|
|
85
|
+
doBatchValidation(element: GModelElement): Marker[] {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Perform a validation for a custom <code>reason</code> with the given <code>element</code>.
|
|
91
|
+
*
|
|
92
|
+
* <p>
|
|
93
|
+
* GLSP editors may add custom reasons for triggering a validation, other than <code>live</code> and
|
|
94
|
+
* <code>batch</code>.
|
|
95
|
+
* Validation requests that are not live or batch validations will be handled by this method.
|
|
96
|
+
* There is no need to traverse through the children in this method as {@link #validate(List, String)} will invoke
|
|
97
|
+
* this method for all children anyway.
|
|
98
|
+
* </p>
|
|
99
|
+
*
|
|
100
|
+
* @param element The element to validate.
|
|
101
|
+
* @return A list of {@link Marker}s for the validated {@link GModelElement}.
|
|
102
|
+
*/
|
|
103
|
+
doValidationForCustomReason(element: GModelElement): Marker[] {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
34
106
|
}
|
|
@@ -13,8 +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 {
|
|
17
|
-
import { Action, Marker, RequestMarkersAction, SetMarkersAction } from '@eclipse-glsp/protocol';
|
|
16
|
+
import { Action, MarkersReason, RequestMarkersAction, SetMarkersAction } from '@eclipse-glsp/protocol';
|
|
18
17
|
import { inject, injectable, optional } from 'inversify';
|
|
19
18
|
import { ActionHandler } from '../../actions/action-handler';
|
|
20
19
|
import { GLSPServerError } from '../../utils/glsp-server-error';
|
|
@@ -38,14 +37,9 @@ export class RequestMarkersHandler implements ActionHandler {
|
|
|
38
37
|
elementIDs = [this.modelState.root.id];
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
const modelElement = currentModelIndex.findByClass(elementID, GGraph);
|
|
45
|
-
if (modelElement) {
|
|
46
|
-
markers = markers.concat(await this.validator.validate([modelElement]));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
40
|
+
const modelElements = this.modelState.index.getAll(elementIDs);
|
|
41
|
+
const markers = await this.validator.validate(modelElements, action.reason ?? MarkersReason.BATCH);
|
|
42
|
+
|
|
49
43
|
return [SetMarkersAction.create(markers)];
|
|
50
44
|
}
|
|
51
45
|
}
|
|
@@ -19,7 +19,7 @@ import { GNode } from '@eclipse-glsp/graph/lib/gnode';
|
|
|
19
19
|
import { CreateEdgeOperation, MaybePromise, TriggerEdgeCreationAction } from '@eclipse-glsp/protocol';
|
|
20
20
|
import { injectable } from 'inversify';
|
|
21
21
|
import { Command } from '../command/command';
|
|
22
|
-
import {
|
|
22
|
+
import { CreateEdgeOperationHandler } from '../operations/create-operation-handler';
|
|
23
23
|
import { GModelOperationHandler } from './gmodel-operation-handler';
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -28,8 +28,8 @@ import { GModelOperationHandler } from './gmodel-operation-handler';
|
|
|
28
28
|
* (i.e. all operation handlers directly modify the graphical model).
|
|
29
29
|
*/
|
|
30
30
|
@injectable()
|
|
31
|
-
export abstract class GModelCreateEdgeOperationHandler extends GModelOperationHandler implements
|
|
32
|
-
override readonly operationType
|
|
31
|
+
export abstract class GModelCreateEdgeOperationHandler extends GModelOperationHandler implements CreateEdgeOperationHandler {
|
|
32
|
+
override readonly operationType = CreateEdgeOperation.KIND;
|
|
33
33
|
abstract override label: string;
|
|
34
34
|
abstract elementTypeIds: string[];
|
|
35
35
|
|
|
@@ -19,7 +19,7 @@ import { CreateNodeOperation, MaybePromise, Point, SelectAction, TriggerNodeCrea
|
|
|
19
19
|
import { inject, injectable } from 'inversify';
|
|
20
20
|
import { ActionDispatcher } from '../actions/action-dispatcher';
|
|
21
21
|
import { Command } from '../command/command';
|
|
22
|
-
import {
|
|
22
|
+
import { CreateNodeOperationHandler } from '../operations/create-operation-handler';
|
|
23
23
|
import { getRelativeLocation } from '../utils/layout-util';
|
|
24
24
|
import { GModelOperationHandler } from './gmodel-operation-handler';
|
|
25
25
|
|
|
@@ -29,7 +29,7 @@ import { GModelOperationHandler } from './gmodel-operation-handler';
|
|
|
29
29
|
* (i.e. all operation handlers directly modify the graphical model).
|
|
30
30
|
*/
|
|
31
31
|
@injectable()
|
|
32
|
-
export abstract class GModelCreateNodeOperationHandler extends GModelOperationHandler implements
|
|
32
|
+
export abstract class GModelCreateNodeOperationHandler extends GModelOperationHandler implements CreateNodeOperationHandler {
|
|
33
33
|
@inject(ActionDispatcher)
|
|
34
34
|
protected actionDispatcher: ActionDispatcher;
|
|
35
35
|
|
|
@@ -37,7 +37,7 @@ export abstract class GModelCreateNodeOperationHandler extends GModelOperationHa
|
|
|
37
37
|
|
|
38
38
|
abstract override label: string;
|
|
39
39
|
|
|
40
|
-
override operationType
|
|
40
|
+
override readonly operationType = CreateNodeOperation.KIND;
|
|
41
41
|
|
|
42
42
|
override createCommand(operation: CreateNodeOperation): MaybePromise<Command | undefined> {
|
|
43
43
|
return this.commandOf(() => this.executeCreation(operation));
|
package/src/common/index.ts
CHANGED
|
@@ -71,6 +71,7 @@ export * from './gmodel/index';
|
|
|
71
71
|
export * from './launch/glsp-server-launcher';
|
|
72
72
|
export * from './operations/compound-operation-handler';
|
|
73
73
|
export * from './operations/create-operation-handler';
|
|
74
|
+
export * from './operations/json-operation-handler';
|
|
74
75
|
export * from './operations/operation-action-handler';
|
|
75
76
|
export * from './operations/operation-handler';
|
|
76
77
|
export * from './operations/operation-handler-registry';
|
|
@@ -19,6 +19,11 @@ import { Command, CompoundCommand } from '../command/command';
|
|
|
19
19
|
import { OperationHandler } from './operation-handler';
|
|
20
20
|
import { OperationHandlerRegistry } from './operation-handler-registry';
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Generic {@link OperationHandler} from {@link CompoundOperations}.
|
|
24
|
+
* Retrieves the corresponding execution commands for the list of (sub) operations
|
|
25
|
+
* and constructs a {@link CompoundCommand} for them.
|
|
26
|
+
*/
|
|
22
27
|
@injectable()
|
|
23
28
|
export class CompoundOperationHandler extends OperationHandler {
|
|
24
29
|
@inject(OperationHandlerRegistry)
|
|
@@ -27,7 +32,7 @@ export class CompoundOperationHandler extends OperationHandler {
|
|
|
27
32
|
operationType = CompoundOperation.KIND;
|
|
28
33
|
|
|
29
34
|
async createCommand(operation: CompoundOperation): Promise<Command | undefined> {
|
|
30
|
-
const maybeCommands = operation.operationList.map(op => this.operationHandlerRegistry.
|
|
35
|
+
const maybeCommands = operation.operationList.map(op => this.operationHandlerRegistry.getOperationHandler(op)?.execute(op));
|
|
31
36
|
const commands: Command[] = [];
|
|
32
37
|
|
|
33
38
|
for await (const command of maybeCommands) {
|
|
@@ -19,21 +19,37 @@ import {
|
|
|
19
19
|
hasArrayProp,
|
|
20
20
|
hasFunctionProp,
|
|
21
21
|
hasStringProp,
|
|
22
|
+
MaybePromise,
|
|
22
23
|
TriggerEdgeCreationAction,
|
|
23
24
|
TriggerNodeCreationAction
|
|
24
25
|
} from '@eclipse-glsp/protocol';
|
|
26
|
+
import { Command } from '../command/command';
|
|
25
27
|
import { OperationHandler } from './operation-handler';
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
|
-
* A special {@link OperationHandler} that is responsible for the handling of {@link
|
|
30
|
+
* A special {@link OperationHandler} that is responsible for the handling of (a subset of) {@link CreateEdgeOperation}s. Depending on its
|
|
29
31
|
* operation type the triggered actions are {@link TriggerNodeCreationAction} or {@link TriggerEdgeCreationAction}s.
|
|
30
32
|
*/
|
|
31
|
-
export interface
|
|
33
|
+
export interface CreateEdgeOperationHandler extends OperationHandler {
|
|
34
|
+
label: string;
|
|
35
|
+
elementTypeIds: string[];
|
|
36
|
+
operationType: typeof CreateEdgeOperation.KIND;
|
|
37
|
+
getTriggerActions(): TriggerEdgeCreationAction[];
|
|
38
|
+
createCommand(operation: CreateEdgeOperation): MaybePromise<Command | undefined>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface CreateNodeOperationHandler extends OperationHandler {
|
|
32
42
|
readonly label: string;
|
|
33
43
|
elementTypeIds: string[];
|
|
34
|
-
operationType:
|
|
35
|
-
getTriggerActions():
|
|
44
|
+
operationType: typeof CreateNodeOperation.KIND;
|
|
45
|
+
getTriggerActions(): TriggerNodeCreationAction[];
|
|
46
|
+
createCommand(operation: CreateNodeOperation): MaybePromise<Command | undefined>;
|
|
36
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* A special {@link OperationHandler} that is responsible for the handling of a node or edge creation operation. Depending on its
|
|
50
|
+
* operation type the triggered actions are {@link TriggerNodeCreationAction} or {@link TriggerEdgeCreationAction}s.
|
|
51
|
+
*/
|
|
52
|
+
export type CreateOperationHandler = CreateNodeOperationHandler | CreateEdgeOperationHandler;
|
|
37
53
|
|
|
38
54
|
export type CreateOperationKind = typeof CreateNodeOperation.KIND | typeof CreateEdgeOperation.KIND;
|
|
39
55
|
|
|
@@ -41,9 +57,10 @@ export namespace CreateOperationHandler {
|
|
|
41
57
|
export function is(object: unknown): object is CreateOperationHandler {
|
|
42
58
|
return (
|
|
43
59
|
object instanceof OperationHandler &&
|
|
60
|
+
hasStringProp(object, 'operationType') &&
|
|
44
61
|
hasStringProp(object, 'label') &&
|
|
45
62
|
hasArrayProp(object, 'elementTypeIds') &&
|
|
46
|
-
hasFunctionProp(object, 'getTriggerActions')
|
|
63
|
+
hasFunctionProp(object, 'getTriggerActions', true)
|
|
47
64
|
);
|
|
48
65
|
}
|
|
49
66
|
}
|
|
@@ -0,0 +1,147 @@
|
|
|
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
|
+
import { GModelElement } from '@eclipse-glsp/graph';
|
|
17
|
+
import {
|
|
18
|
+
AnyObject,
|
|
19
|
+
CreateEdgeOperation,
|
|
20
|
+
CreateNodeOperation,
|
|
21
|
+
MaybePromise,
|
|
22
|
+
Point,
|
|
23
|
+
TriggerEdgeCreationAction,
|
|
24
|
+
TriggerNodeCreationAction,
|
|
25
|
+
hasFunctionProp,
|
|
26
|
+
hasObjectProp
|
|
27
|
+
} from '@eclipse-glsp/protocol';
|
|
28
|
+
import { injectable } from 'inversify';
|
|
29
|
+
import { Command } from '../command/command';
|
|
30
|
+
import { AbstractRecordingCommand } from '../command/recording-command';
|
|
31
|
+
import { ModelState } from '../features/model/model-state';
|
|
32
|
+
import { getRelativeLocation } from '../utils/layout-util';
|
|
33
|
+
import { CreateEdgeOperationHandler, CreateNodeOperationHandler } from './create-operation-handler';
|
|
34
|
+
import { OperationHandler } from './operation-handler';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Helper interface for {@link ModelState} implementations of diagram languages that use a (serializable) JSON-based source model.
|
|
38
|
+
* Has to be implemented in order to reuse the {@link JsonOperationHandler} API.
|
|
39
|
+
*/
|
|
40
|
+
export interface JsonModelState<JsonObject extends AnyObject = AnyObject> extends ModelState {
|
|
41
|
+
readonly sourceModel: JsonObject;
|
|
42
|
+
updateSourceModel(sourceModel: JsonObject): void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export namespace JsonModelState {
|
|
46
|
+
export function is(modelState: ModelState): modelState is JsonModelState {
|
|
47
|
+
return hasObjectProp(modelState, 'sourceModel') && hasFunctionProp(modelState, 'updateSourceModel');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Simple base implementation of {@link AbstractRecordingCommand} that allows recording of changes made
|
|
53
|
+
* to the `sourceModel` of the given {@link JsonModelState} during the given `doExecute` function
|
|
54
|
+
*/
|
|
55
|
+
export class JsonRecordingCommand<JsonObject extends AnyObject = AnyObject> extends AbstractRecordingCommand<JsonObject> {
|
|
56
|
+
constructor(protected modelState: JsonModelState<JsonObject>, protected doExecute: () => MaybePromise<void>) {
|
|
57
|
+
super();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
protected override getJsonObject(): MaybePromise<JsonObject> {
|
|
61
|
+
return this.modelState.sourceModel;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
protected override postChange(newModel: JsonObject): MaybePromise<void> {
|
|
65
|
+
this.modelState.updateSourceModel(newModel);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Reusable {@link OperationHandler} base implementation for diagram languages that use a (serializable) JSON-based source model.
|
|
71
|
+
* To use this class (or its subclasses) the injected {@link ModelState} has to implement the {@link JsonModelState} interface.
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
@injectable()
|
|
75
|
+
export abstract class JsonOperationHandler extends OperationHandler {
|
|
76
|
+
protected commandOf(runnable: () => void): Command {
|
|
77
|
+
if (!JsonModelState.is(this.modelState)) {
|
|
78
|
+
throw new Error('Cannot create command. The underlying model state does not implement the `JsonModelState` interface');
|
|
79
|
+
}
|
|
80
|
+
return new JsonRecordingCommand(this.modelState, runnable);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Reusable {@link CreateNodeOperationHandler} base implementation for diagram languages that use a (serializable) JSON-based source model.
|
|
86
|
+
*/
|
|
87
|
+
@injectable()
|
|
88
|
+
export abstract class JsonCreateNodeOperationHandler extends JsonOperationHandler implements CreateNodeOperationHandler {
|
|
89
|
+
abstract elementTypeIds: string[];
|
|
90
|
+
abstract override label: string;
|
|
91
|
+
override readonly operationType = CreateNodeOperation.KIND;
|
|
92
|
+
|
|
93
|
+
abstract override createCommand(operation: CreateNodeOperation): MaybePromise<Command | undefined>;
|
|
94
|
+
|
|
95
|
+
getTriggerActions(): TriggerNodeCreationAction[] {
|
|
96
|
+
return this.elementTypeIds.map(typeId => TriggerNodeCreationAction.create(typeId));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Return the GModelElement that will contain the newly created node. It is usually
|
|
101
|
+
* the target element ({@link CreateNodeOperation.containerId}), but could also
|
|
102
|
+
* be e.g. an intermediate compartment, or even a different Node.
|
|
103
|
+
*
|
|
104
|
+
* @param operation
|
|
105
|
+
* @return the GModelElement that will contain the newly created node.
|
|
106
|
+
*/
|
|
107
|
+
getContainer(operation: CreateNodeOperation): GModelElement | undefined {
|
|
108
|
+
const index = this.modelState.index;
|
|
109
|
+
return operation.containerId ? index.get(operation.containerId) : undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
getLocation(operation: CreateNodeOperation): Point | undefined {
|
|
113
|
+
return operation.location;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Retrieves the diagram absolute location and the target container from the given {@link CreateNodeOperation}
|
|
118
|
+
* and converts the absolute location to coordinates relative to the given container.
|
|
119
|
+
* Relative coordinates can only be retrieved if the given container element is part of
|
|
120
|
+
* a hierarchy of {@link GBoundsAware} elements. This means each (recursive) parent element need to
|
|
121
|
+
* implement {@link GBoundsAware}. If that is not the case this method returns `undefined`.
|
|
122
|
+
* @param absoluteLocation The diagram absolute position.
|
|
123
|
+
* @param container The container element.
|
|
124
|
+
* @returns The relative position or `undefined`.
|
|
125
|
+
*/
|
|
126
|
+
getRelativeLocation(operation: CreateNodeOperation): Point | undefined {
|
|
127
|
+
const container = this.getContainer(operation) ?? this.modelState.root;
|
|
128
|
+
const absoluteLocation = this.getLocation(operation) ?? Point.ORIGIN;
|
|
129
|
+
return getRelativeLocation(absoluteLocation, container);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Reusable {@link CreateEdgeOperationHandler} base implementation for diagram languages that use a (serializable) JSON-based source model.
|
|
135
|
+
*/
|
|
136
|
+
@injectable()
|
|
137
|
+
export abstract class JsonCreateEdgeOperationHandler extends JsonOperationHandler implements CreateEdgeOperationHandler {
|
|
138
|
+
abstract elementTypeIds: string[];
|
|
139
|
+
abstract override label: string;
|
|
140
|
+
override readonly operationType = CreateEdgeOperation.KIND;
|
|
141
|
+
|
|
142
|
+
abstract override createCommand(operation: CreateEdgeOperation): MaybePromise<Command | undefined>;
|
|
143
|
+
|
|
144
|
+
getTriggerActions(): TriggerEdgeCreationAction[] {
|
|
145
|
+
return this.elementTypeIds.map(typeId => TriggerEdgeCreationAction.create(typeId));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -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 { Action, MaybePromise,
|
|
16
|
+
import { Action, MaybePromise, MessageAction, Operation } from '@eclipse-glsp/protocol';
|
|
17
17
|
import { inject, injectable } from 'inversify';
|
|
18
18
|
import { ActionHandler } from '../actions/action-handler';
|
|
19
19
|
import { Command } from '../command/command';
|
|
@@ -47,7 +47,7 @@ export class OperationActionHandler implements ActionHandler {
|
|
|
47
47
|
}
|
|
48
48
|
if (this.modelState.isReadonly) {
|
|
49
49
|
return [
|
|
50
|
-
|
|
50
|
+
MessageAction.create(`Server is in readonly-mode! Could not execute operation: ${action.kind}`, {
|
|
51
51
|
severity: 'WARNING'
|
|
52
52
|
})
|
|
53
53
|
];
|
|
@@ -13,9 +13,8 @@
|
|
|
13
13
|
*
|
|
14
14
|
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
********************************************************************************/
|
|
16
|
-
import { Args, CreateOperation,
|
|
16
|
+
import { Args, CreateOperation, Operation } from '@eclipse-glsp/protocol';
|
|
17
17
|
import { inject, injectable, optional } from 'inversify';
|
|
18
|
-
import { Command } from '../command/command';
|
|
19
18
|
import { ClientSessionInitializer } from '../session/client-session-initializer';
|
|
20
19
|
import { Registry } from '../utils/registry';
|
|
21
20
|
import { CreateOperationHandler } from './create-operation-handler';
|
|
@@ -35,16 +34,6 @@ export class OperationHandlerRegistry extends Registry<string, OperationHandler>
|
|
|
35
34
|
getOperationHandler(operation: Operation): OperationHandler | undefined {
|
|
36
35
|
return CreateOperation.is(operation) ? this.get(`${operation.kind}_${operation.elementTypeId}`) : this.get(operation.kind);
|
|
37
36
|
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Returns the matching command for the given operation.
|
|
41
|
-
*
|
|
42
|
-
* @param operation operation
|
|
43
|
-
* @return the matching command for the given operation
|
|
44
|
-
*/
|
|
45
|
-
getExecutableCommand(operation: Operation): MaybePromise<Command | undefined> {
|
|
46
|
-
return this.getOperationHandler(operation)?.createCommand(operation);
|
|
47
|
-
}
|
|
48
37
|
}
|
|
49
38
|
|
|
50
39
|
@injectable()
|
|
@@ -37,7 +37,7 @@ export abstract class OperationHandler {
|
|
|
37
37
|
*
|
|
38
38
|
* @returns the operation type that can be handled.
|
|
39
39
|
*/
|
|
40
|
-
abstract operationType: string;
|
|
40
|
+
abstract readonly operationType: string;
|
|
41
41
|
|
|
42
42
|
readonly label?: string;
|
|
43
43
|
|
|
@@ -46,7 +46,7 @@ export abstract class OperationHandler {
|
|
|
46
46
|
* is performed on the model(s).
|
|
47
47
|
*
|
|
48
48
|
* @param operation The operation to process.
|
|
49
|
-
* @return The created command to be executed on the command stack or `undefined` nothing should be done.
|
|
49
|
+
* @return The created command to be executed on the command stack or `undefined` if nothing should be done.
|
|
50
50
|
*/
|
|
51
51
|
abstract createCommand(operation: Operation): MaybePromise<Command | undefined>;
|
|
52
52
|
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
|
|
17
|
+
import { Action } from '@eclipse-glsp/protocol';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A helper interface that allows the server to mark actions that have been received from the client.
|
|
21
|
+
*/
|
|
22
|
+
export interface ClientAction extends Action {
|
|
23
|
+
__receivedFromClient: true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export namespace ClientAction {
|
|
27
|
+
export function is(object: unknown): object is ClientAction {
|
|
28
|
+
return Action.is(object) && '__receivedFromClient' in object && object.__receivedFromClient === true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Mark the given action as {@link ClientAction} by attaching the "__receivedFromClient" property
|
|
33
|
+
* @param action The action that should be marked as client action
|
|
34
|
+
*/
|
|
35
|
+
export function mark(action: Action): void {
|
|
36
|
+
(action as ClientAction).__receivedFromClient = true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
InitializeClientSessionParameters,
|
|
21
21
|
InitializeParameters
|
|
22
22
|
} from '@eclipse-glsp/protocol';
|
|
23
|
+
import * as assert from 'assert';
|
|
23
24
|
import { expect } from 'chai';
|
|
24
25
|
import { Container, ContainerModule } from 'inversify';
|
|
25
26
|
import * as sinon from 'sinon';
|
|
@@ -28,7 +29,6 @@ import { ClientSessionManager } from '../session/client-session-manager';
|
|
|
28
29
|
import * as mock from '../test/mock-util';
|
|
29
30
|
import { Logger } from '../utils/logger';
|
|
30
31
|
import { DefaultGLSPServer } from './glsp-server';
|
|
31
|
-
import assert = require('assert');
|
|
32
32
|
|
|
33
33
|
describe('test DefaultGLSPServer', () => {
|
|
34
34
|
const container = new Container();
|
|
@@ -36,8 +36,8 @@ describe('test DefaultGLSPServer', () => {
|
|
|
36
36
|
const diagramType = 'myDiagram';
|
|
37
37
|
const applicationId = 'Test';
|
|
38
38
|
const protocolVersion = '1.0.0';
|
|
39
|
-
const
|
|
40
|
-
|
|
39
|
+
const actionKinds = new Map<string, string[]>();
|
|
40
|
+
actionKinds.set(diagramType, ['A1', 'A2']);
|
|
41
41
|
const sessionManager = new mock.StubClientSessionManager();
|
|
42
42
|
const spy_sessionManager_getOrCreate = sinon.spy(sessionManager, 'getOrCreateClientSession');
|
|
43
43
|
const spy_sessionManager_dispose = sinon.spy(sessionManager, 'disposeClientSession');
|
|
@@ -53,7 +53,7 @@ describe('test DefaultGLSPServer', () => {
|
|
|
53
53
|
bind(Logger).toConstantValue(new mock.StubLogger());
|
|
54
54
|
bind(GLSPClientProxy).toConstantValue(new mock.StubGLSPClientProxy());
|
|
55
55
|
bind(ClientSessionManager).toConstantValue(sessionManager);
|
|
56
|
-
bind(GlobalActionProvider).toConstantValue(
|
|
56
|
+
bind(GlobalActionProvider).toConstantValue(<GlobalActionProvider>{ actionKinds });
|
|
57
57
|
bind(GLSPServerListener).toConstantValue(listener1);
|
|
58
58
|
})
|
|
59
59
|
);
|
|
@@ -70,7 +70,7 @@ describe('test DefaultGLSPServer', () => {
|
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
it('Test calls before server initialization (should throw errors)', async () => {
|
|
73
|
-
assert.rejects(() => glspServer.initializeClientSession({ clientSessionId: 'id', diagramType: 'type' }));
|
|
73
|
+
assert.rejects(() => glspServer.initializeClientSession({ clientSessionId: 'id', diagramType: 'type', clientActionKinds: [] }));
|
|
74
74
|
assert.rejects(() => glspServer.disposeClientSession({ clientSessionId: 'id' }));
|
|
75
75
|
assert.throws(() => glspServer.process({ clientId: 'id', action: { kind: 'action' } }));
|
|
76
76
|
});
|
|
@@ -109,8 +109,8 @@ describe('test DefaultGLSPServer', () => {
|
|
|
109
109
|
const initializeParameters: InitializeParameters = { applicationId, protocolVersion };
|
|
110
110
|
const result = await glspServer.initialize(initializeParameters);
|
|
111
111
|
expect(result.protocolVersion).to.be.equal(protocolVersion);
|
|
112
|
-
expect(result.serverActions[diagramType]).to.be.equal(
|
|
113
|
-
expect(result.serverActions[diagramType]).to.be.equal(
|
|
112
|
+
expect(result.serverActions[diagramType]).to.be.equal(actionKinds.get(diagramType));
|
|
113
|
+
expect(result.serverActions[diagramType]).to.be.equal(actionKinds.get(diagramType));
|
|
114
114
|
expect(spy_listener1_initialize.calledWith(glspServer));
|
|
115
115
|
expect(spy_listener2_initialize.notCalled);
|
|
116
116
|
});
|
|
@@ -119,8 +119,8 @@ describe('test DefaultGLSPServer', () => {
|
|
|
119
119
|
const initializeParameters: InitializeParameters = { applicationId, protocolVersion };
|
|
120
120
|
const result = await glspServer.initialize(initializeParameters);
|
|
121
121
|
expect(result.protocolVersion).to.be.equal(protocolVersion);
|
|
122
|
-
expect(result.serverActions[diagramType]).to.be.equal(
|
|
123
|
-
expect(result.serverActions[diagramType]).to.be.equal(
|
|
122
|
+
expect(result.serverActions[diagramType]).to.be.equal(actionKinds.get(diagramType));
|
|
123
|
+
expect(result.serverActions[diagramType]).to.be.equal(actionKinds.get(diagramType));
|
|
124
124
|
});
|
|
125
125
|
|
|
126
126
|
it('initialize - subsequent call with other parameters', async () => {
|
|
@@ -131,7 +131,8 @@ describe('test DefaultGLSPServer', () => {
|
|
|
131
131
|
it('initialize client session', async () => {
|
|
132
132
|
const initializeClientSessionParameters: InitializeClientSessionParameters = {
|
|
133
133
|
clientSessionId,
|
|
134
|
-
diagramType
|
|
134
|
+
diagramType,
|
|
135
|
+
clientActionKinds: []
|
|
135
136
|
};
|
|
136
137
|
await glspServer.initializeClientSession(initializeClientSessionParameters);
|
|
137
138
|
expect(spy_sessionManager_getOrCreate.calledWith(initializeClientSessionParameters));
|
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
ActionMessage,
|
|
18
18
|
Args,
|
|
19
19
|
DisposeClientSessionParameters,
|
|
20
|
-
distinctAdd,
|
|
21
20
|
GLSPClientProxy,
|
|
22
21
|
GLSPServer,
|
|
23
22
|
GLSPServerListener,
|
|
@@ -25,9 +24,10 @@ import {
|
|
|
25
24
|
InitializeParameters,
|
|
26
25
|
InitializeResult,
|
|
27
26
|
MaybePromise,
|
|
28
|
-
|
|
27
|
+
MessageAction,
|
|
29
28
|
ServerActions,
|
|
30
|
-
|
|
29
|
+
distinctAdd,
|
|
30
|
+
remove
|
|
31
31
|
} from '@eclipse-glsp/protocol';
|
|
32
32
|
import { inject, injectable, multiInject, optional } from 'inversify';
|
|
33
33
|
import { GlobalActionProvider } from '../actions/global-action-provider';
|
|
@@ -35,6 +35,7 @@ import { ClientSession } from '../session/client-session';
|
|
|
35
35
|
import { ClientSessionManager } from '../session/client-session-manager';
|
|
36
36
|
import { GLSPServerError } from '../utils/glsp-server-error';
|
|
37
37
|
import { Logger } from '../utils/logger';
|
|
38
|
+
import { ClientAction } from './client-action';
|
|
38
39
|
|
|
39
40
|
@injectable()
|
|
40
41
|
export class DefaultGLSPServer implements GLSPServer {
|
|
@@ -50,8 +51,7 @@ export class DefaultGLSPServer implements GLSPServer {
|
|
|
50
51
|
protected actionProvider: GlobalActionProvider;
|
|
51
52
|
|
|
52
53
|
@inject(GLSPClientProxy)
|
|
53
|
-
|
|
54
|
-
protected glspClientProxy?: GLSPClientProxy;
|
|
54
|
+
protected glspClientProxy: GLSPClientProxy;
|
|
55
55
|
|
|
56
56
|
protected initializeResult?: InitializeResult;
|
|
57
57
|
|
|
@@ -97,7 +97,7 @@ export class DefaultGLSPServer implements GLSPServer {
|
|
|
97
97
|
this.applicationId = params.applicationId;
|
|
98
98
|
const serverActions: ServerActions = {};
|
|
99
99
|
|
|
100
|
-
this.actionProvider.
|
|
100
|
+
this.actionProvider.actionKinds.forEach((kinds, diagramType) => (serverActions[diagramType] = kinds));
|
|
101
101
|
|
|
102
102
|
let result = { protocolVersion: DefaultGLSPServer.PROTOCOL_VERSION, serverActions };
|
|
103
103
|
|
|
@@ -149,8 +149,9 @@ export class DefaultGLSPServer implements GLSPServer {
|
|
|
149
149
|
if (!clientSession) {
|
|
150
150
|
throw new Error(`No client session has been initialized for client id: ${clientSessionId}`);
|
|
151
151
|
}
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
const action = message.action;
|
|
153
|
+
ClientAction.mark(action);
|
|
154
|
+
clientSession.actionDispatcher.dispatch(action).catch(error => this.handleProcessError(message, error));
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
protected handleProcessError(message: ActionMessage, reason: any): void | PromiseLike<void> {
|
|
@@ -162,16 +163,12 @@ export class DefaultGLSPServer implements GLSPServer {
|
|
|
162
163
|
details = reason.cause?.toString?.();
|
|
163
164
|
errorMsg = reason.message;
|
|
164
165
|
}
|
|
165
|
-
const errorAction =
|
|
166
|
+
const errorAction = MessageAction.create(errorMsg, { severity: 'ERROR', details });
|
|
166
167
|
this.sendToClient({ clientId: message.clientId, action: errorAction });
|
|
167
168
|
}
|
|
168
169
|
|
|
169
170
|
protected sendToClient(message: ActionMessage): void {
|
|
170
|
-
|
|
171
|
-
this.glspClientProxy.process(message);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
throw new Error("Could not send message to client. No 'GLSPClientProxy' is connected");
|
|
171
|
+
this.glspClientProxy.process(message);
|
|
175
172
|
}
|
|
176
173
|
|
|
177
174
|
getClientSession(sessionId: string): ClientSession | undefined {
|