@eclipse-glsp/server 1.1.0-RC10 → 1.1.0-next.2ae7567.68

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 (259) hide show
  1. package/lib/browser/launch/worker-server-launcher.js +2 -1
  2. package/lib/browser/launch/worker-server-launcher.js.map +1 -1
  3. package/lib/common/actions/action-dispatcher.d.ts +2 -1
  4. package/lib/common/actions/action-dispatcher.d.ts.map +1 -1
  5. package/lib/common/actions/action-dispatcher.js +9 -6
  6. package/lib/common/actions/action-dispatcher.js.map +1 -1
  7. package/lib/common/actions/action-handler-registry.js +4 -2
  8. package/lib/common/actions/action-handler-registry.js.map +1 -1
  9. package/lib/common/actions/client-action-handler.d.ts +17 -8
  10. package/lib/common/actions/client-action-handler.d.ts.map +1 -1
  11. package/lib/common/actions/client-action-handler.js +32 -21
  12. package/lib/common/actions/client-action-handler.js.map +1 -1
  13. package/lib/common/actions/global-action-provider.d.ts +6 -21
  14. package/lib/common/actions/global-action-provider.d.ts.map +1 -1
  15. package/lib/common/actions/global-action-provider.js +17 -21
  16. package/lib/common/actions/global-action-provider.js.map +1 -1
  17. package/lib/common/command/command-stack.js +2 -1
  18. package/lib/common/command/command-stack.js.map +1 -1
  19. package/lib/common/command/recording-command.d.ts +9 -15
  20. package/lib/common/command/recording-command.d.ts.map +1 -1
  21. package/lib/common/command/recording-command.js +12 -26
  22. package/lib/common/command/recording-command.js.map +1 -1
  23. package/lib/common/command/undo-redo-action-handler.js +2 -1
  24. package/lib/common/command/undo-redo-action-handler.js.map +1 -1
  25. package/lib/common/di/client-session-module.d.ts +9 -1
  26. package/lib/common/di/client-session-module.d.ts.map +1 -1
  27. package/lib/common/di/client-session-module.js +9 -9
  28. package/lib/common/di/client-session-module.js.map +1 -1
  29. package/lib/common/di/diagram-module.d.ts +23 -1
  30. package/lib/common/di/diagram-module.d.ts.map +1 -1
  31. package/lib/common/di/diagram-module.js +23 -53
  32. package/lib/common/di/diagram-module.js.map +1 -1
  33. package/lib/common/di/glsp-module.js +2 -1
  34. package/lib/common/di/glsp-module.js.map +1 -1
  35. package/lib/common/di/server-module.d.ts +0 -1
  36. package/lib/common/di/server-module.d.ts.map +1 -1
  37. package/lib/common/di/server-module.js +0 -1
  38. package/lib/common/di/server-module.js.map +1 -1
  39. package/lib/common/features/clipboard/request-clipboard-data-action-handler.d.ts.map +1 -1
  40. package/lib/common/features/clipboard/request-clipboard-data-action-handler.js +2 -1
  41. package/lib/common/features/clipboard/request-clipboard-data-action-handler.js.map +1 -1
  42. package/lib/common/features/contextactions/command-palette-action-provider.js +2 -1
  43. package/lib/common/features/contextactions/command-palette-action-provider.js.map +1 -1
  44. package/lib/common/features/contextactions/context-actions-provider-registry.js +2 -1
  45. package/lib/common/features/contextactions/context-actions-provider-registry.js.map +1 -1
  46. package/lib/common/features/contextactions/context-menu-item-provider.js +2 -1
  47. package/lib/common/features/contextactions/context-menu-item-provider.js.map +1 -1
  48. package/lib/common/features/contextactions/request-context-actions-handler.js +2 -1
  49. package/lib/common/features/contextactions/request-context-actions-handler.js.map +1 -1
  50. package/lib/common/features/contextactions/tool-palette-item-provider.js +4 -2
  51. package/lib/common/features/contextactions/tool-palette-item-provider.js.map +1 -1
  52. package/lib/common/features/directediting/context-edit-validator-registry.js +2 -1
  53. package/lib/common/features/directediting/context-edit-validator-registry.js.map +1 -1
  54. package/lib/common/features/directediting/label-edit-validator.js +2 -1
  55. package/lib/common/features/directediting/label-edit-validator.js.map +1 -1
  56. package/lib/common/features/directediting/request-edit-validation-handler.js +2 -1
  57. package/lib/common/features/directediting/request-edit-validation-handler.js.map +1 -1
  58. package/lib/common/features/layout/computed-bounds-action-handler.js +2 -1
  59. package/lib/common/features/layout/computed-bounds-action-handler.js.map +1 -1
  60. package/lib/common/features/layout/layout-operation-handler.js +2 -1
  61. package/lib/common/features/layout/layout-operation-handler.js.map +1 -1
  62. package/lib/common/features/model/gmodel-factory.js +2 -1
  63. package/lib/common/features/model/gmodel-factory.js.map +1 -1
  64. package/lib/common/features/model/gmodel-index.js +2 -1
  65. package/lib/common/features/model/gmodel-index.js.map +1 -1
  66. package/lib/common/features/model/gmodel-serializer.d.ts +10 -10
  67. package/lib/common/features/model/gmodel-serializer.d.ts.map +1 -1
  68. package/lib/common/features/model/gmodel-serializer.js +2 -1
  69. package/lib/common/features/model/gmodel-serializer.js.map +1 -1
  70. package/lib/common/features/model/model-state.d.ts.map +1 -1
  71. package/lib/common/features/model/model-state.js +5 -1
  72. package/lib/common/features/model/model-state.js.map +1 -1
  73. package/lib/common/features/model/model-submission-handler.d.ts +30 -3
  74. package/lib/common/features/model/model-submission-handler.d.ts.map +1 -1
  75. package/lib/common/features/model/model-submission-handler.js +73 -8
  76. package/lib/common/features/model/model-submission-handler.js.map +1 -1
  77. package/lib/common/features/model/request-model-action-handler.d.ts +5 -6
  78. package/lib/common/features/model/request-model-action-handler.d.ts.map +1 -1
  79. package/lib/common/features/model/request-model-action-handler.js +37 -14
  80. package/lib/common/features/model/request-model-action-handler.js.map +1 -1
  81. package/lib/common/features/model/save-model-action-handler.js +2 -1
  82. package/lib/common/features/model/save-model-action-handler.js.map +1 -1
  83. package/lib/common/features/navigation/navigation-target-provider-registry.js +2 -1
  84. package/lib/common/features/navigation/navigation-target-provider-registry.js.map +1 -1
  85. package/lib/common/features/navigation/navigation-target-resolver.js +2 -1
  86. package/lib/common/features/navigation/navigation-target-resolver.js.map +1 -1
  87. package/lib/common/features/navigation/request-navigation-targets-action-handler.js +2 -1
  88. package/lib/common/features/navigation/request-navigation-targets-action-handler.js.map +1 -1
  89. package/lib/common/features/navigation/resolve-navigation-targets-action-handler.js +2 -1
  90. package/lib/common/features/navigation/resolve-navigation-targets-action-handler.js.map +1 -1
  91. package/lib/common/features/popup/request-popup-model-action-handler.js +2 -1
  92. package/lib/common/features/popup/request-popup-model-action-handler.js.map +1 -1
  93. package/lib/common/features/progress/progress-service.d.ts +44 -0
  94. package/lib/common/features/progress/progress-service.d.ts.map +1 -0
  95. package/lib/common/features/progress/progress-service.js +51 -0
  96. package/lib/common/features/progress/progress-service.js.map +1 -0
  97. package/lib/common/features/type-hints/edge-creation-checker.d.ts +42 -0
  98. package/lib/common/features/type-hints/edge-creation-checker.d.ts.map +1 -0
  99. package/lib/common/features/type-hints/edge-creation-checker.js +20 -0
  100. package/lib/common/features/type-hints/edge-creation-checker.js.map +1 -0
  101. package/lib/common/features/type-hints/request-check-edge-action-handler.d.ts +29 -0
  102. package/lib/common/features/type-hints/request-check-edge-action-handler.d.ts.map +1 -0
  103. package/lib/common/features/type-hints/request-check-edge-action-handler.js +72 -0
  104. package/lib/common/features/type-hints/request-check-edge-action-handler.js.map +1 -0
  105. package/lib/common/{diagram → features/type-hints}/request-type-hints-action-handler.d.ts +2 -3
  106. package/lib/common/features/type-hints/request-type-hints-action-handler.d.ts.map +1 -0
  107. package/lib/common/{diagram → features/type-hints}/request-type-hints-action-handler.js +3 -3
  108. package/lib/common/features/type-hints/request-type-hints-action-handler.js.map +1 -0
  109. package/lib/common/features/validation/model-validator.d.ts +47 -2
  110. package/lib/common/features/validation/model-validator.d.ts.map +1 -1
  111. package/lib/common/features/validation/model-validator.js +80 -1
  112. package/lib/common/features/validation/model-validator.js.map +1 -1
  113. package/lib/common/features/validation/request-markers-handler.d.ts +15 -0
  114. package/lib/common/features/validation/request-markers-handler.d.ts.map +1 -1
  115. package/lib/common/features/validation/request-markers-handler.js +5 -10
  116. package/lib/common/features/validation/request-markers-handler.js.map +1 -1
  117. package/lib/common/gmodel/apply-label-edit-operation-handler.js +2 -1
  118. package/lib/common/gmodel/apply-label-edit-operation-handler.js.map +1 -1
  119. package/lib/common/gmodel/change-bounds-operation-handler.js +2 -1
  120. package/lib/common/gmodel/change-bounds-operation-handler.js.map +1 -1
  121. package/lib/common/gmodel/change-routing-points-operation-handler.js +2 -1
  122. package/lib/common/gmodel/change-routing-points-operation-handler.js.map +1 -1
  123. package/lib/common/gmodel/cut-operation-handler.js +2 -1
  124. package/lib/common/gmodel/cut-operation-handler.js.map +1 -1
  125. package/lib/common/gmodel/delete-operation-handler.js +2 -1
  126. package/lib/common/gmodel/delete-operation-handler.js.map +1 -1
  127. package/lib/common/gmodel/gmodel-create-edge-operation-handler.d.ts +3 -3
  128. package/lib/common/gmodel/gmodel-create-edge-operation-handler.d.ts.map +1 -1
  129. package/lib/common/gmodel/gmodel-create-edge-operation-handler.js +2 -1
  130. package/lib/common/gmodel/gmodel-create-edge-operation-handler.js.map +1 -1
  131. package/lib/common/gmodel/gmodel-create-node-operation-handler.d.ts +3 -3
  132. package/lib/common/gmodel/gmodel-create-node-operation-handler.d.ts.map +1 -1
  133. package/lib/common/gmodel/gmodel-create-node-operation-handler.js +2 -1
  134. package/lib/common/gmodel/gmodel-create-node-operation-handler.js.map +1 -1
  135. package/lib/common/gmodel/gmodel-diagram-module.js +2 -1
  136. package/lib/common/gmodel/gmodel-diagram-module.js.map +1 -1
  137. package/lib/common/gmodel/paste-operation-handler.d.ts.map +1 -1
  138. package/lib/common/gmodel/paste-operation-handler.js +2 -1
  139. package/lib/common/gmodel/paste-operation-handler.js.map +1 -1
  140. package/lib/common/gmodel/reconnect-edge-operation-handler.js +2 -1
  141. package/lib/common/gmodel/reconnect-edge-operation-handler.js.map +1 -1
  142. package/lib/common/index.d.ts +3 -1
  143. package/lib/common/index.d.ts.map +1 -1
  144. package/lib/common/index.js +3 -1
  145. package/lib/common/index.js.map +1 -1
  146. package/lib/common/launch/glsp-server-launcher.js +2 -1
  147. package/lib/common/launch/glsp-server-launcher.js.map +1 -1
  148. package/lib/common/launch/jsonrpc-server-launcher.js +2 -1
  149. package/lib/common/launch/jsonrpc-server-launcher.js.map +1 -1
  150. package/lib/common/operations/compound-operation-handler.d.ts +5 -0
  151. package/lib/common/operations/compound-operation-handler.d.ts.map +1 -1
  152. package/lib/common/operations/compound-operation-handler.js +8 -2
  153. package/lib/common/operations/compound-operation-handler.js.map +1 -1
  154. package/lib/common/operations/create-operation-handler.d.ts +19 -5
  155. package/lib/common/operations/create-operation-handler.d.ts.map +1 -1
  156. package/lib/common/operations/create-operation-handler.js +2 -1
  157. package/lib/common/operations/create-operation-handler.js.map +1 -1
  158. package/lib/common/operations/json-operation-handler.d.ts +94 -0
  159. package/lib/common/operations/json-operation-handler.d.ts.map +1 -0
  160. package/lib/common/operations/json-operation-handler.js +120 -0
  161. package/lib/common/operations/json-operation-handler.js.map +1 -0
  162. package/lib/common/operations/operation-action-handler.d.ts.map +1 -1
  163. package/lib/common/operations/operation-action-handler.js +3 -2
  164. package/lib/common/operations/operation-action-handler.js.map +1 -1
  165. package/lib/common/operations/operation-handler-registry.d.ts +1 -9
  166. package/lib/common/operations/operation-handler-registry.d.ts.map +1 -1
  167. package/lib/common/operations/operation-handler-registry.js +4 -12
  168. package/lib/common/operations/operation-handler-registry.js.map +1 -1
  169. package/lib/common/operations/operation-handler.d.ts +2 -2
  170. package/lib/common/operations/operation-handler.d.ts.map +1 -1
  171. package/lib/common/operations/operation-handler.js +2 -1
  172. package/lib/common/operations/operation-handler.js.map +1 -1
  173. package/lib/common/protocol/client-action.d.ts +31 -0
  174. package/lib/common/protocol/client-action.d.ts.map +1 -0
  175. package/lib/common/protocol/client-action.js +35 -0
  176. package/lib/common/protocol/client-action.js.map +1 -0
  177. package/lib/common/protocol/glsp-server.d.ts +1 -1
  178. package/lib/common/protocol/glsp-server.d.ts.map +1 -1
  179. package/lib/common/protocol/glsp-server.js +9 -10
  180. package/lib/common/protocol/glsp-server.js.map +1 -1
  181. package/lib/common/session/client-session-factory.js +5 -4
  182. package/lib/common/session/client-session-factory.js.map +1 -1
  183. package/lib/common/session/client-session-manager.js +2 -1
  184. package/lib/common/session/client-session-manager.js.map +1 -1
  185. package/lib/common/utils/client-options-util.d.ts +3 -0
  186. package/lib/common/utils/client-options-util.d.ts.map +1 -1
  187. package/lib/common/utils/client-options-util.js +5 -15
  188. package/lib/common/utils/client-options-util.js.map +1 -1
  189. package/lib/common/utils/console-logger.js +2 -1
  190. package/lib/common/utils/console-logger.js.map +1 -1
  191. package/lib/common/utils/logger.js +2 -1
  192. package/lib/common/utils/logger.js.map +1 -1
  193. package/lib/common/utils/promise-queue.d.ts.map +1 -1
  194. package/lib/common/utils/promise-queue.js +3 -6
  195. package/lib/common/utils/promise-queue.js.map +1 -1
  196. package/lib/common/utils/registry.d.ts +3 -1
  197. package/lib/common/utils/registry.d.ts.map +1 -1
  198. package/lib/common/utils/registry.js +15 -4
  199. package/lib/common/utils/registry.js.map +1 -1
  200. package/lib/node/abstract-json-model-storage.d.ts.map +1 -1
  201. package/lib/node/abstract-json-model-storage.js +10 -3
  202. package/lib/node/abstract-json-model-storage.js.map +1 -1
  203. package/lib/node/gmodel/gmodel-storage.d.ts.map +1 -1
  204. package/lib/node/gmodel/gmodel-storage.js +4 -2
  205. package/lib/node/gmodel/gmodel-storage.js.map +1 -1
  206. package/lib/node/launch/cli-parser.js +1 -1
  207. package/lib/node/launch/cli-parser.js.map +1 -1
  208. package/lib/node/launch/socket-server-launcher.js +2 -1
  209. package/lib/node/launch/socket-server-launcher.js.map +1 -1
  210. package/lib/node/launch/websocket-server-launcher.js +2 -1
  211. package/lib/node/launch/websocket-server-launcher.js.map +1 -1
  212. package/package.json +4 -5
  213. package/src/common/actions/action-dispatcher.spec.ts +3 -2
  214. package/src/common/actions/action-dispatcher.ts +8 -5
  215. package/src/common/actions/client-action-handler.ts +28 -18
  216. package/src/common/actions/global-action-provider.spec.ts +4 -15
  217. package/src/common/actions/global-action-provider.ts +21 -25
  218. package/src/common/command/recording-command.spec.ts +15 -5
  219. package/src/common/command/recording-command.ts +16 -27
  220. package/src/common/di/client-session-module.ts +17 -10
  221. package/src/common/di/diagram-module.ts +31 -70
  222. package/src/common/di/server-module.ts +0 -1
  223. package/src/common/features/clipboard/request-clipboard-data-action-handler.ts +3 -3
  224. package/src/common/features/model/gmodel-serializer.ts +11 -11
  225. package/src/common/features/model/model-state.ts +3 -0
  226. package/src/common/features/model/model-submission-handler.ts +64 -7
  227. package/src/common/features/model/request-model-action-handler.ts +37 -17
  228. package/src/common/features/progress/progress-service.ts +74 -0
  229. package/src/common/features/type-hints/edge-creation-checker.ts +44 -0
  230. package/src/common/features/type-hints/request-check-edge-action-handler.ts +62 -0
  231. package/src/common/{diagram → features/type-hints}/request-type-hints-action-handler.spec.ts +2 -2
  232. package/src/common/{diagram → features/type-hints}/request-type-hints-action-handler.ts +2 -3
  233. package/src/common/features/validation/model-validator.ts +75 -3
  234. package/src/common/features/validation/request-markers-handler.ts +4 -10
  235. package/src/common/gmodel/gmodel-create-edge-operation-handler.ts +3 -3
  236. package/src/common/gmodel/gmodel-create-node-operation-handler.ts +3 -3
  237. package/src/common/gmodel/paste-operation-handler.ts +2 -2
  238. package/src/common/index.ts +3 -1
  239. package/src/common/operations/compound-operation-handler.ts +6 -1
  240. package/src/common/operations/create-operation-handler.ts +22 -5
  241. package/src/common/operations/json-operation-handler.ts +147 -0
  242. package/src/common/operations/operation-action-handler.ts +2 -2
  243. package/src/common/operations/operation-handler-registry.ts +1 -12
  244. package/src/common/operations/operation-handler.ts +2 -2
  245. package/src/common/protocol/client-action.ts +38 -0
  246. package/src/common/protocol/glsp-server.spec.ts +11 -10
  247. package/src/common/protocol/glsp-server.ts +11 -14
  248. package/src/common/session/client-session-factory.spec.ts +2 -2
  249. package/src/common/session/client-session-factory.ts +3 -3
  250. package/src/common/session/client-session-manager.spec.ts +4 -3
  251. package/src/common/utils/client-options-util.ts +8 -0
  252. package/src/common/utils/promise-queue.ts +4 -5
  253. package/src/common/utils/registry.spec.ts +3 -1
  254. package/src/common/utils/registry.ts +8 -3
  255. package/src/node/abstract-json-model-storage.ts +8 -2
  256. package/src/node/gmodel/gmodel-storage.ts +3 -3
  257. package/src/node/launch/cli-parser.ts +1 -1
  258. package/lib/common/diagram/request-type-hints-action-handler.d.ts.map +0 -1
  259. package/lib/common/diagram/request-type-hints-action-handler.js.map +0 -1
@@ -13,11 +13,13 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
- import { Action, RequestModelAction, ServerMessageAction, ServerStatusAction } from '@eclipse-glsp/protocol';
16
+ import { Action, RequestModelAction, StatusAction } from '@eclipse-glsp/protocol';
17
17
  import { inject, injectable } from 'inversify';
18
18
  import { ActionDispatcher } from '../../actions/action-dispatcher';
19
19
  import { ActionHandler } from '../../actions/action-handler';
20
+ import { ClientOptionsUtil } from '../../utils/client-options-util';
20
21
  import { Logger } from '../../utils/logger';
22
+ import { ProgressMonitor, ProgressService } from '../progress/progress-service';
21
23
  import { ModelState } from './model-state';
22
24
  import { ModelSubmissionHandler } from './model-submission-handler';
23
25
  import { SourceModelStorage } from './source-model-storage';
@@ -41,27 +43,45 @@ export class RequestModelActionHandler implements ActionHandler {
41
43
  @inject(ModelSubmissionHandler)
42
44
  protected submissionHandler: ModelSubmissionHandler;
43
45
 
46
+ @inject(ProgressService)
47
+ protected progressService: ProgressService;
48
+
44
49
  async execute(action: RequestModelAction): Promise<Action[]> {
45
50
  this.logger.debug('Execute RequestModelAction:', action);
46
51
  this.modelState.setAll(action.options ?? {});
47
52
 
48
- this.notifyClient('Model loading in progress');
49
- await this.sourceModelStorage.loadSourceModel(action);
50
- // Clear the previous notification.
51
- this.notifyClient();
52
- return this.submissionHandler.submitModel();
53
+ const isReconnecting = ClientOptionsUtil.isReconnecting(action.options);
54
+
55
+ const progress = this.reportModelLoading('Model loading in progress');
56
+
57
+ if (isReconnecting) {
58
+ await this.handleReconnect(action);
59
+ } else {
60
+ await this.sourceModelStorage.loadSourceModel(action);
61
+ }
62
+ this.reportModelLoadingFinished(progress);
63
+
64
+ return this.submissionHandler.submitInitialModel(action);
65
+ }
66
+
67
+ protected async handleReconnect(action: RequestModelAction): Promise<void> {
68
+ const oldModelRoot = this.modelState.root;
69
+ if (oldModelRoot) {
70
+ // decrease revision by one, as each submit will increase it by one;
71
+ // the next save would produce warning that source model was changed otherwise
72
+ this.modelState.root.revision = (this.modelState.root.revision ?? 0) - 1;
73
+ } else {
74
+ await this.sourceModelStorage.loadSourceModel(action);
75
+ }
76
+ }
77
+
78
+ protected reportModelLoading(message: string): ProgressMonitor {
79
+ this.actionDispatcher.dispatch(StatusAction.create(message, { severity: 'INFO' }));
80
+ return this.progressService.start(message);
53
81
  }
54
82
 
55
- /**
56
- * Send a message and status notification with the given message to the client.
57
- * An empty message is an indication for the client to clear previously received notifications.
58
- * @param message The message that should be sent to the client
59
- */
60
- protected notifyClient(message = ''): void {
61
- const severity = message.length > 0 ? 'INFO' : 'NONE';
62
- this.actionDispatcher.dispatchAll(
63
- ServerMessageAction.create(message, { severity }),
64
- ServerStatusAction.create(message, { severity })
65
- );
83
+ protected reportModelLoadingFinished(monitor: ProgressMonitor): void {
84
+ this.actionDispatcher.dispatch(StatusAction.create('', { severity: 'NONE' }));
85
+ monitor.end();
66
86
  }
67
87
  }
@@ -0,0 +1,74 @@
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 { EndProgressAction, StartProgressAction, UpdateProgressAction } from '@eclipse-glsp/protocol';
17
+ import { inject, injectable } from 'inversify';
18
+ import * as uuid from 'uuid';
19
+ import { ActionDispatcher } from '../../actions/action-dispatcher';
20
+
21
+ export const ProgressService = Symbol('ProgressService');
22
+
23
+ /**
24
+ * Service for starting and monitoring progress reporting to the client.
25
+ */
26
+ export interface ProgressService {
27
+ /**
28
+ * Start a progress reporting.
29
+ * @param title The title shown in the UI for the progress reporting.
30
+ * @param options Additional optional options for the progress reporting.
31
+ * @returns a monitor to update and end the progress reporting later.
32
+ */
33
+ start(title: string, options?: ProgressOptions): ProgressMonitor;
34
+ }
35
+
36
+ /**
37
+ * Optional progress reporting options.
38
+ */
39
+ export interface ProgressOptions {
40
+ /** A message shown in the UI. */
41
+ message?: string;
42
+ /* The percentage (value range: 0 to 100) to show in the progress reporting. */
43
+ percentage?: number;
44
+ }
45
+
46
+ /**
47
+ * The monitor of a progress reporting, which can be used to update and end the reporting.
48
+ */
49
+ export interface ProgressMonitor {
50
+ /**
51
+ * Updates an ongoing progress reporting.
52
+ * @param options Updated message and/or percentage (value range: 0 to 100).
53
+ */
54
+ update(options: { message?: string; percentage?: number }): void;
55
+ /**
56
+ * Ends an ongoing progress reporting.
57
+ */
58
+ end(): void;
59
+ }
60
+
61
+ @injectable()
62
+ export class DefaultProgressService implements ProgressService {
63
+ @inject(ActionDispatcher)
64
+ protected actionDispatcher: ActionDispatcher;
65
+
66
+ start(title: string, options?: ProgressOptions): ProgressMonitor {
67
+ const progressId = uuid.v4();
68
+ this.actionDispatcher.dispatch(StartProgressAction.create({ progressId, title, ...options }));
69
+ return {
70
+ update: updateOptions => this.actionDispatcher.dispatch(UpdateProgressAction.create(progressId, updateOptions)),
71
+ end: () => this.actionDispatcher.dispatch(EndProgressAction.create(progressId))
72
+ };
73
+ }
74
+ }
@@ -0,0 +1,44 @@
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 { GModelElement } from '@eclipse-glsp/graph';
18
+
19
+ /**
20
+ * Optional service used to check the validity of an edge being created. Used in combination with `dynamic`
21
+ * `EdgeTypeHints`.
22
+ * A dynamic edge type hint is used for cases where a plain list of allowed source and target element ids is not enough
23
+ * to determine wether an edge being created is valid. In this cases the client will query the server to determine wether the edge
24
+ * is valid. The `EdgeCreationChecker` then checks the given edge information and returns wether the edge being created is
25
+ * valid.
26
+ */
27
+ export interface EdgeCreationChecker {
28
+ /**
29
+ * Checks wether the given source element for an edge being created is valid i.e. if the
30
+ * given source is and allowed source element for the given edge type.
31
+ *
32
+ * @returns `true` if the edge source is valid, `false` otherwise
33
+ */
34
+ isValidSource(edgeType: string, sourceElement: GModelElement): boolean;
35
+
36
+ /**
37
+ * Checks wether the given information for an edge being created is valid i.e. if the
38
+ * given target is an allowed target for the given source and edge type.
39
+ *
40
+ * @return `true` if the edge target is valid, `false` otherwise
41
+ */
42
+ isValidTarget(edgeType: string, sourceElement: GModelElement, targetElement: GModelElement): boolean;
43
+ }
44
+ export const EdgeCreationChecker = Symbol('EdgeCreationChecker');
@@ -0,0 +1,62 @@
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 { Action, CheckEdgeResultAction, MaybePromise, RequestCheckEdgeAction } from '@eclipse-glsp/protocol';
17
+ import { inject, injectable, optional } from 'inversify';
18
+ import { ActionHandler } from '../../actions/action-handler';
19
+ import { DiagramConfiguration } from '../../diagram/diagram-configuration';
20
+ import { GLSPServerError, getOrThrow } from '../../utils/glsp-server-error';
21
+ import { ModelState } from '../model/model-state';
22
+ import { EdgeCreationChecker } from './edge-creation-checker';
23
+
24
+ @injectable()
25
+ export class RequestCheckEdgeActionHandler implements ActionHandler {
26
+ @inject(ModelState)
27
+ protected modelState: ModelState;
28
+
29
+ @inject(DiagramConfiguration)
30
+ protected diagramConfiguration: DiagramConfiguration;
31
+
32
+ @inject(EdgeCreationChecker)
33
+ @optional()
34
+ protected edgeCreationChecker?: EdgeCreationChecker;
35
+
36
+ readonly actionKinds: string[] = [RequestCheckEdgeAction.KIND];
37
+
38
+ execute(action: RequestCheckEdgeAction): MaybePromise<Action[]> {
39
+ const hasDynamicHint = this.diagramConfiguration.edgeTypeHints.some(hint => hint.elementTypeId === action.edgeType && hint.dynamic);
40
+ const { edgeType, sourceElementId, targetElementId } = action;
41
+ const isValid = this.edgeCreationChecker && hasDynamicHint ? this.validate(action) : true;
42
+
43
+ return [CheckEdgeResultAction.create({ edgeType, isValid, sourceElementId, targetElementId })];
44
+ }
45
+
46
+ protected validate(action: RequestCheckEdgeAction): boolean {
47
+ const sourceElement = getOrThrow(
48
+ this.modelState.index.get(action.sourceElementId),
49
+ 'Invalid `RequestCheckEdgeTargetAction`!. Could not find a source element with id: ' + action.sourceElementId
50
+ );
51
+ const targetElement = action.targetElementId ? this.modelState.index.get(action.targetElementId) : undefined;
52
+
53
+ if (action.targetElementId && !targetElement) {
54
+ throw new GLSPServerError(
55
+ 'Invalid `RequestCheckEdgeTargetAction`! Could not find a target element with id: ' + action.targetElementId
56
+ );
57
+ }
58
+ return targetElement
59
+ ? this.edgeCreationChecker!.isValidTarget(action.edgeType, sourceElement, targetElement)
60
+ : this.edgeCreationChecker!.isValidSource(action.edgeType, sourceElement);
61
+ }
62
+ }
@@ -16,8 +16,8 @@
16
16
  import { EdgeTypeHint, RequestTypeHintsAction, SetTypeHintsAction, ShapeTypeHint } from '@eclipse-glsp/protocol';
17
17
  import { expect } from 'chai';
18
18
  import { Container, ContainerModule } from 'inversify';
19
- import * as mock from '../test/mock-util';
20
- import { DiagramConfiguration } from './diagram-configuration';
19
+ import { DiagramConfiguration } from '../../diagram/diagram-configuration';
20
+ import * as mock from '../../test/mock-util';
21
21
  import { RequestTypeHintsActionHandler } from './request-type-hints-action-handler';
22
22
 
23
23
  describe('test RequestTypeHintsActionHandler', () => {
@@ -15,13 +15,12 @@
15
15
  ********************************************************************************/
16
16
  import { Action, MaybePromise, RequestTypeHintsAction, SetTypeHintsAction } from '@eclipse-glsp/protocol';
17
17
  import { inject, injectable } from 'inversify';
18
- import { ActionHandler } from '../actions/action-handler';
19
- import { DiagramConfiguration } from './diagram-configuration';
18
+ import { ActionHandler } from '../../actions/action-handler';
19
+ import { DiagramConfiguration } from '../../diagram/diagram-configuration';
20
20
 
21
21
  @injectable()
22
22
  export class RequestTypeHintsActionHandler implements ActionHandler {
23
23
  @inject(DiagramConfiguration) protected diagramConfiguration: DiagramConfiguration;
24
- static KINDS = [RequestTypeHintsAction.KIND];
25
24
 
26
25
  execute(action: RequestTypeHintsAction): MaybePromise<Action[]> {
27
26
  return [
@@ -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
- * @returns A list of {@link Marker}s for the validated {@link GModelElement}s.
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 { GGraph } from '@eclipse-glsp/graph';
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
- let markers: Marker[] = [];
42
- const currentModelIndex = this.modelState.index;
43
- for (const elementID of elementIDs) {
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 { CreateOperationHandler, CreateOperationKind } from '../operations/create-operation-handler';
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 CreateOperationHandler {
32
- override readonly operationType: CreateOperationKind = CreateEdgeOperation.KIND;
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 { CreateOperationHandler, CreateOperationKind } from '../operations/create-operation-handler';
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 CreateOperationHandler {
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: CreateOperationKind = CreateNodeOperation.KIND;
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));
@@ -14,7 +14,7 @@
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
16
  import { GBoundsAware, GEdge, GModelElement, isGBoundsAware } from '@eclipse-glsp/graph';
17
- import { EditorContext, MaybePromise, PasteOperation, Point, SModelElementSchema } from '@eclipse-glsp/protocol';
17
+ import { EditorContext, GModelElementSchema, MaybePromise, PasteOperation, Point } from '@eclipse-glsp/protocol';
18
18
  import { inject, injectable } from 'inversify';
19
19
  import * as uuid from 'uuid';
20
20
  import { Command } from '../command/command';
@@ -38,7 +38,7 @@ export class GModelPasteOperationHandler extends GModelOperationHandler {
38
38
  }
39
39
 
40
40
  protected getCopiedElements(jsonString: string): GModelElement[] {
41
- const schemas: SModelElementSchema[] = JSON.parse(jsonString);
41
+ const schemas: GModelElementSchema[] = JSON.parse(jsonString);
42
42
  return schemas.map(schema => this.modelSerializer.createElement(schema, this.modelState.root));
43
43
  }
44
44
 
@@ -33,7 +33,6 @@ export * from './di/multi-binding';
33
33
  export * from './di/server-module';
34
34
  export * from './di/service-identifiers';
35
35
  export * from './diagram/diagram-configuration';
36
- export * from './diagram/request-type-hints-action-handler';
37
36
  export * from './features/clipboard/request-clipboard-data-action-handler';
38
37
  export * from './features/contextactions/command-palette-action-provider';
39
38
  export * from './features/contextactions/context-actions-provider';
@@ -65,12 +64,15 @@ export * from './features/navigation/request-navigation-targets-action-handler';
65
64
  export * from './features/navigation/resolve-navigation-targets-action-handler';
66
65
  export * from './features/popup/popup-model-factory';
67
66
  export * from './features/popup/request-popup-model-action-handler';
67
+ export * from './features/type-hints/edge-creation-checker';
68
+ export * from './features/type-hints/request-type-hints-action-handler';
68
69
  export * from './features/validation/model-validator';
69
70
  export * from './features/validation/request-markers-handler';
70
71
  export * from './gmodel/index';
71
72
  export * from './launch/glsp-server-launcher';
72
73
  export * from './operations/compound-operation-handler';
73
74
  export * from './operations/create-operation-handler';
75
+ export * from './operations/json-operation-handler';
74
76
  export * from './operations/operation-action-handler';
75
77
  export * from './operations/operation-handler';
76
78
  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.getExecutableCommand(op));
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 CreateOperation}s. Depending on its
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 CreateOperationHandler extends OperationHandler {
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: CreateOperationKind;
35
- getTriggerActions(): (TriggerEdgeCreationAction | TriggerNodeCreationAction)[];
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
  }