@eclipse-glsp/client 2.3.0-next.318 → 2.3.0-next.319

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 (59) hide show
  1. package/lib/base/action-handler-registry.d.ts +10 -1
  2. package/lib/base/action-handler-registry.d.ts.map +1 -1
  3. package/lib/base/action-handler-registry.js +40 -2
  4. package/lib/base/action-handler-registry.js.map +1 -1
  5. package/lib/base/default.module.d.ts.map +1 -1
  6. package/lib/base/default.module.js +5 -0
  7. package/lib/base/default.module.js.map +1 -1
  8. package/lib/base/feedback/feedback-action-dispatcher.d.ts +28 -1
  9. package/lib/base/feedback/feedback-action-dispatcher.d.ts.map +1 -1
  10. package/lib/base/feedback/feedback-action-dispatcher.js +23 -1
  11. package/lib/base/feedback/feedback-action-dispatcher.js.map +1 -1
  12. package/lib/base/feedback/feedback-command.d.ts +8 -3
  13. package/lib/base/feedback/feedback-command.d.ts.map +1 -1
  14. package/lib/base/feedback/feedback-command.js +13 -2
  15. package/lib/base/feedback/feedback-command.js.map +1 -1
  16. package/lib/base/feedback/index.d.ts +1 -0
  17. package/lib/base/feedback/index.d.ts.map +1 -1
  18. package/lib/base/feedback/index.js +1 -0
  19. package/lib/base/feedback/index.js.map +1 -1
  20. package/lib/base/feedback/set-model-command.d.ts +25 -0
  21. package/lib/base/feedback/set-model-command.d.ts.map +1 -0
  22. package/lib/base/feedback/set-model-command.js +65 -0
  23. package/lib/base/feedback/set-model-command.js.map +1 -0
  24. package/lib/base/feedback/update-model-command.d.ts +17 -6
  25. package/lib/base/feedback/update-model-command.d.ts.map +1 -1
  26. package/lib/base/feedback/update-model-command.js +8 -28
  27. package/lib/base/feedback/update-model-command.js.map +1 -1
  28. package/lib/base/ranked.d.ts +10 -0
  29. package/lib/base/ranked.d.ts.map +1 -1
  30. package/lib/base/ranked.js +6 -0
  31. package/lib/base/ranked.js.map +1 -1
  32. package/lib/base/selection-service.spec.js +4 -0
  33. package/lib/base/selection-service.spec.js.map +1 -1
  34. package/lib/features/bounds/set-bounds-feedback-command.d.ts +1 -1
  35. package/lib/features/bounds/set-bounds-feedback-command.d.ts.map +1 -1
  36. package/lib/features/bounds/set-bounds-feedback-command.js +2 -1
  37. package/lib/features/bounds/set-bounds-feedback-command.js.map +1 -1
  38. package/lib/features/hints/type-hint-provider.d.ts +17 -2
  39. package/lib/features/hints/type-hint-provider.d.ts.map +1 -1
  40. package/lib/features/hints/type-hint-provider.js +12 -12
  41. package/lib/features/hints/type-hint-provider.js.map +1 -1
  42. package/lib/tsconfig.tsbuildinfo +1 -1
  43. package/lib/utils/contribution-provider.d.ts +27 -0
  44. package/lib/utils/contribution-provider.d.ts.map +1 -0
  45. package/lib/utils/contribution-provider.js +56 -0
  46. package/lib/utils/contribution-provider.js.map +1 -0
  47. package/package.json +3 -3
  48. package/src/base/action-handler-registry.ts +41 -2
  49. package/src/base/default.module.ts +7 -0
  50. package/src/base/feedback/feedback-action-dispatcher.ts +49 -1
  51. package/src/base/feedback/feedback-command.ts +15 -4
  52. package/src/base/feedback/index.ts +2 -0
  53. package/src/base/feedback/set-model-command.ts +45 -0
  54. package/src/base/feedback/update-model-command.ts +8 -45
  55. package/src/base/ranked.ts +14 -0
  56. package/src/base/selection-service.spec.ts +7 -1
  57. package/src/features/bounds/set-bounds-feedback-command.ts +2 -1
  58. package/src/features/hints/type-hint-provider.ts +5 -5
  59. package/src/utils/contribution-provider.ts +65 -0
@@ -0,0 +1,27 @@
1
+ /*******************************************************************************
2
+ * Copyright (C) 2017 TypeFox and others.
3
+ * Modifications: (c) 2024 EclipseSource and others.
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the Eclipse Public License v. 2.0 which is available at
7
+ * http://www.eclipse.org/legal/epl-2.0.
8
+ *
9
+ * This Source Code may also be made available under the following Secondary
10
+ * Licenses when the conditions for such availability set forth in the Eclipse
11
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ * with the GNU Classpath Exception which is available at
13
+ * https://www.gnu.org/software/classpath/license.html.
14
+ *
15
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ *******************************************************************************/
17
+ import { BindingContext } from '@eclipse-glsp/sprotty';
18
+ import { interfaces } from 'inversify';
19
+ export interface IContributionProvider<T extends object> {
20
+ /**
21
+ * @param recursive `true` if the contributions should be collected from the parent containers as well. Otherwise, `false`.
22
+ * It is `false` by default.
23
+ */
24
+ getContributions(recursive?: boolean): T[];
25
+ }
26
+ export declare function bindContributionProvider(context: Pick<BindingContext, 'bind'> | interfaces.Bind, id: symbol): void;
27
+ //# sourceMappingURL=contribution-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contribution-provider.d.ts","sourceRoot":"","sources":["../../src/utils/contribution-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;iFAeiF;AAIjF,OAAO,EAAE,cAAc,EAAS,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,MAAM,WAAW,qBAAqB,CAAC,CAAC,SAAS,MAAM;IACnD;;;OAGG;IACH,gBAAgB,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,CAAC,EAAE,CAAC;CAC9C;AA8BD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAMlH"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ /*******************************************************************************
3
+ * Copyright (C) 2017 TypeFox and others.
4
+ * Modifications: (c) 2024 EclipseSource and others.
5
+ *
6
+ * This program and the accompanying materials are made available under the
7
+ * terms of the Eclipse Public License v. 2.0 which is available at
8
+ * http://www.eclipse.org/legal/epl-2.0.
9
+ *
10
+ * This Source Code may also be made available under the following Secondary
11
+ * Licenses when the conditions for such availability set forth in the Eclipse
12
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
13
+ * with the GNU Classpath Exception which is available at
14
+ * https://www.gnu.org/software/classpath/license.html.
15
+ *
16
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
17
+ *******************************************************************************/
18
+ // eslint-disable-next-line max-len
19
+ // based on https://github.com/eclipse-theia/theia/blob/9ff0cedff1d591b0eb4be97a05f6d992789d0a24/packages/core/src/common/contribution-provider.ts
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.bindContributionProvider = void 0;
22
+ const sprotty_1 = require("@eclipse-glsp/sprotty");
23
+ class ContainerBasedContributionProvider {
24
+ constructor(serviceIdentifier, container) {
25
+ this.serviceIdentifier = serviceIdentifier;
26
+ this.container = container;
27
+ }
28
+ getContributions(recursive) {
29
+ if (this.services === undefined) {
30
+ const currentServices = [];
31
+ let currentContainer = this.container;
32
+ while (currentContainer !== undefined) {
33
+ if (currentContainer.isBound(this.serviceIdentifier)) {
34
+ try {
35
+ currentServices.push(...currentContainer.getAll(this.serviceIdentifier));
36
+ }
37
+ catch (error) {
38
+ console.error(error);
39
+ }
40
+ }
41
+ currentContainer = recursive === true && currentContainer.parent ? currentContainer.parent : undefined;
42
+ }
43
+ this.services = currentServices;
44
+ }
45
+ return this.services;
46
+ }
47
+ }
48
+ function bindContributionProvider(context, id) {
49
+ const bind = typeof context === 'object' ? context.bind.bind(context) : context;
50
+ bind(sprotty_1.TYPES.IContributionProvider)
51
+ .toDynamicValue(ctx => new ContainerBasedContributionProvider(id, ctx.container))
52
+ .inSingletonScope()
53
+ .whenTargetNamed(id);
54
+ }
55
+ exports.bindContributionProvider = bindContributionProvider;
56
+ //# sourceMappingURL=contribution-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contribution-provider.js","sourceRoot":"","sources":["../../src/utils/contribution-provider.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;iFAeiF;AACjF,mCAAmC;AACnC,kJAAkJ;;;AAElJ,mDAA8D;AAW9D,MAAM,kCAAkC;IAGpC,YACuB,iBAAkD,EAClD,SAA+B;QAD/B,sBAAiB,GAAjB,iBAAiB,CAAiC;QAClD,cAAS,GAAT,SAAS,CAAsB;IACnD,CAAC;IAEJ,gBAAgB,CAAC,SAAmB;QAChC,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE;YAC7B,MAAM,eAAe,GAAQ,EAAE,CAAC;YAChC,IAAI,gBAAgB,GAAqC,IAAI,CAAC,SAAS,CAAC;YACxE,OAAO,gBAAgB,KAAK,SAAS,EAAE;gBACnC,IAAI,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE;oBAClD,IAAI;wBACA,eAAe,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;qBAC5E;oBAAC,OAAO,KAAK,EAAE;wBACZ,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;qBACxB;iBACJ;gBACD,gBAAgB,GAAG,SAAS,KAAK,IAAI,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;aAC1G;YACD,IAAI,CAAC,QAAQ,GAAG,eAAe,CAAC;SACnC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;CACJ;AAED,SAAgB,wBAAwB,CAAC,OAAuD,EAAE,EAAU;IACxG,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAChF,IAAI,CAAC,eAAK,CAAC,qBAAqB,CAAC;SAC5B,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,kCAAkC,CAAC,EAAE,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;SAChF,gBAAgB,EAAE;SAClB,eAAe,CAAC,EAAE,CAAC,CAAC;AAC7B,CAAC;AAND,4DAMC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eclipse-glsp/client",
3
- "version": "2.3.0-next.318+645e72f",
3
+ "version": "2.3.0-next.319+5e43503",
4
4
  "description": "A sprotty-based client for GLSP",
5
5
  "keywords": [
6
6
  "eclipse",
@@ -47,7 +47,7 @@
47
47
  "watch": "tsc -w"
48
48
  },
49
49
  "dependencies": {
50
- "@eclipse-glsp/sprotty": "2.3.0-next.318+645e72f",
50
+ "@eclipse-glsp/sprotty": "2.3.0-next.319+5e43503",
51
51
  "autocompleter": "^9.1.0",
52
52
  "file-saver": "^2.0.5",
53
53
  "lodash": "4.17.21"
@@ -59,5 +59,5 @@
59
59
  "publishConfig": {
60
60
  "access": "public"
61
61
  },
62
- "gitHead": "645e72fe0e157729e056b93d9a3faa3df61fa1b2"
62
+ "gitHead": "5e435038399d7acf5408a64348e212b8393ea205"
63
63
  }
@@ -14,17 +14,56 @@
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
16
 
17
- import { injectable } from 'inversify';
18
- import { ActionHandlerRegistry } from '@eclipse-glsp/sprotty';
17
+ import { ActionHandlerRegistration, ActionHandlerRegistry, IActionHandler, IActionHandlerInitializer, TYPES } from '@eclipse-glsp/sprotty';
18
+ import { inject, injectable, named } from 'inversify';
19
+ import { IContributionProvider } from '../utils/contribution-provider';
19
20
 
20
21
  @injectable()
21
22
  export class GLSPActionHandlerRegistry extends ActionHandlerRegistry {
23
+ @inject(TYPES.IContributionProvider)
24
+ @named(TYPES.ActionHandlerRegistration)
25
+ protected readonly registrations: IContributionProvider<ActionHandlerRegistration>;
26
+
27
+ @inject(TYPES.IContributionProvider)
28
+ @named(TYPES.IActionHandlerInitializer)
29
+ protected readonly initializers: IContributionProvider<IActionHandlerInitializer>;
30
+
31
+ protected initialized = false;
32
+
33
+ constructor() {
34
+ super([], []);
35
+ }
36
+
37
+ protected init(): void {
38
+ if (!this.initialized) {
39
+ this.initialized = true;
40
+ this.registrations.getContributions().forEach(registration => this.register(registration.actionKind, registration.factory()));
41
+ this.initializers.getContributions().forEach(initializer => this.initializeActionHandler(initializer));
42
+ }
43
+ }
44
+
45
+ override register(key: string, instance: IActionHandler): void {
46
+ this.init();
47
+ super.register(key, instance);
48
+ }
49
+
50
+ override get(key: string): IActionHandler[] {
51
+ this.init();
52
+ return super.get(key);
53
+ }
54
+
55
+ override initializeActionHandler(initializer: IActionHandlerInitializer): void {
56
+ this.init();
57
+ super.initializeActionHandler(initializer);
58
+ }
59
+
22
60
  /**
23
61
  * Retrieve a set of all action kinds for which (at least) one
24
62
  * handler is registered
25
63
  * @returns the set of handled action kinds
26
64
  */
27
65
  getHandledActionKinds(): string[] {
66
+ this.init();
28
67
  return Array.from(this.elements.keys());
29
68
  }
30
69
  }
@@ -22,6 +22,7 @@ import {
22
22
  MoveCommand,
23
23
  SetDirtyStateAction,
24
24
  SetEditModeAction,
25
+ SetModelCommand,
25
26
  TYPES,
26
27
  bindAsService,
27
28
  bindOrRebind,
@@ -31,10 +32,12 @@ import {
31
32
  } from '@eclipse-glsp/sprotty';
32
33
  import '@vscode/codicons/dist/codicon.css';
33
34
  import '../../css/glsp-sprotty.css';
35
+ import { bindContributionProvider } from '../utils/contribution-provider';
34
36
  import { GLSPActionDispatcher } from './action-dispatcher';
35
37
  import { GLSPActionHandlerRegistry } from './action-handler-registry';
36
38
  import { GLSPCommandStack } from './command-stack';
37
39
  import { EditorContextService } from './editor-context-service';
40
+ import { FeedbackAwareSetModelCommand } from './feedback';
38
41
  import { ModifyCssFeedbackCommand } from './feedback/css-feedback';
39
42
  import { FeedbackActionDispatcher } from './feedback/feedback-action-dispatcher';
40
43
  import { FeedbackAwareUpdateModelCommand } from './feedback/update-model-command';
@@ -73,6 +76,7 @@ export const defaultModule = new FeatureModule((bind, unbind, isBound, rebind, .
73
76
  // Model update initialization ------------------------------------
74
77
  bind(TYPES.IFeedbackActionDispatcher).to(FeedbackActionDispatcher).inSingletonScope();
75
78
  configureCommand(context, FeedbackAwareUpdateModelCommand);
79
+ rebind(SetModelCommand).to(FeedbackAwareSetModelCommand);
76
80
 
77
81
  bind(GLSPMouseTool).toSelf().inSingletonScope();
78
82
  bindOrRebind(context, MouseTool).toService(GLSPMouseTool);
@@ -84,6 +88,9 @@ export const defaultModule = new FeatureModule((bind, unbind, isBound, rebind, .
84
88
  bindOrRebind(context, TYPES.ICommandStack).to(GLSPCommandStack).inSingletonScope();
85
89
  bind(GLSPActionDispatcher).toSelf().inSingletonScope();
86
90
  bindOrRebind(context, TYPES.IActionDispatcher).toService(GLSPActionDispatcher);
91
+
92
+ bindContributionProvider(bind, TYPES.ActionHandlerRegistration);
93
+ bindContributionProvider(bind, TYPES.IActionHandlerInitializer);
87
94
  bind(GLSPActionHandlerRegistry).toSelf().inSingletonScope();
88
95
  bindOrRebind(context, ActionHandlerRegistry).toService(GLSPActionHandlerRegistry);
89
96
 
@@ -13,8 +13,21 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
+ import {
17
+ Action,
18
+ ActionHandlerRegistry,
19
+ Command,
20
+ CommandActionHandler,
21
+ CommandExecutionContext,
22
+ Disposable,
23
+ IActionDispatcher,
24
+ ICommand,
25
+ ILogger,
26
+ TYPES,
27
+ toTypeGuard
28
+ } from '@eclipse-glsp/sprotty';
16
29
  import { inject, injectable } from 'inversify';
17
- import { Action, Disposable, IActionDispatcher, ILogger, TYPES } from '@eclipse-glsp/sprotty';
30
+ import { getFeedbackRank } from './feedback-command';
18
31
 
19
32
  export interface IFeedbackEmitter {}
20
33
 
@@ -57,6 +70,16 @@ export interface IFeedbackActionDispatcher {
57
70
  * Retrieve all `actions` sent out by currently registered `feedbackEmitter`.
58
71
  */
59
72
  getRegisteredFeedback(): Action[];
73
+
74
+ /**
75
+ * Retrieves all commands based on the registered feedback actions, ordered by their rank (lowest rank first).
76
+ */
77
+ getFeedbackCommands(): Command[];
78
+
79
+ /**
80
+ * Applies all current feedback commands to the given command execution context.
81
+ */
82
+ applyFeedbackCommands(context: CommandExecutionContext): Promise<void>;
60
83
  }
61
84
 
62
85
  @injectable()
@@ -66,6 +89,8 @@ export class FeedbackActionDispatcher implements IFeedbackActionDispatcher {
66
89
  @inject(TYPES.IActionDispatcherProvider) protected actionDispatcher: () => Promise<IActionDispatcher>;
67
90
  @inject(TYPES.ILogger) protected logger: ILogger;
68
91
 
92
+ @inject(ActionHandlerRegistry) protected actionHandlerRegistry: ActionHandlerRegistry;
93
+
69
94
  registerFeedback(feedbackEmitter: IFeedbackEmitter, feedbackActions: Action[], cleanupActions?: Action[] | undefined): Disposable {
70
95
  if (feedbackActions.length > 0) {
71
96
  this.registeredFeedback.set(feedbackEmitter, feedbackActions);
@@ -97,6 +122,29 @@ export class FeedbackActionDispatcher implements IFeedbackActionDispatcher {
97
122
  return result;
98
123
  }
99
124
 
125
+ getFeedbackCommands(): Command[] {
126
+ return this.getRegisteredFeedback()
127
+ .flatMap(action => this.actionToCommands(action))
128
+ .sort((left, right) => getFeedbackRank(left) - getFeedbackRank(right));
129
+ }
130
+
131
+ async applyFeedbackCommands(context: CommandExecutionContext): Promise<void> {
132
+ const feedbackCommands = this.getFeedbackCommands() ?? [];
133
+ if (feedbackCommands?.length > 0) {
134
+ const results = feedbackCommands.map(command => command.execute(context));
135
+ await Promise.all(results);
136
+ }
137
+ }
138
+
139
+ protected actionToCommands(action: Action): ICommand[] {
140
+ return (
141
+ this.actionHandlerRegistry
142
+ ?.get(action.kind)
143
+ .filter(toTypeGuard(CommandActionHandler))
144
+ .map(handler => handler.handle(action)) ?? []
145
+ );
146
+ }
147
+
100
148
  protected async dispatchFeedback(actions: Action[], feedbackEmitter: IFeedbackEmitter): Promise<void> {
101
149
  try {
102
150
  const actionDispatcher = await this.actionDispatcher();
@@ -13,11 +13,16 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
- import { Command, CommandExecutionContext, CommandReturn } from '@eclipse-glsp/sprotty';
16
+ /* eslint-disable deprecation/deprecation */
17
+ import { Command, CommandExecutionContext, CommandReturn, ICommand } from '@eclipse-glsp/sprotty';
18
+ import { Ranked } from '../ranked';
17
19
 
18
- export abstract class FeedbackCommand extends Command {
19
- // used by the `FeedbackAwareUpdateModelCommand`
20
- readonly priority: number = 0;
20
+ export abstract class FeedbackCommand extends Command implements Ranked {
21
+ /** @deprecated Use rank instead. Please note that a lower rank implies higher priority, so the order is reversed. */
22
+ readonly priority?: number = 0;
23
+
24
+ // backwards compatibility: convert any existing priority to an equivalent rank
25
+ readonly rank: number = this.priority ? -this.priority : Ranked.DEFAULT_RANK;
21
26
 
22
27
  undo(context: CommandExecutionContext): CommandReturn {
23
28
  return context.root;
@@ -27,3 +32,9 @@ export abstract class FeedbackCommand extends Command {
27
32
  return context.root;
28
33
  }
29
34
  }
35
+
36
+ /** Used for backwards compatibility, otherwise use Ranked.getRank or Ranked sort functions. */
37
+ export function getFeedbackRank(command: ICommand): number {
38
+ const feedbackCommand = command as Partial<FeedbackCommand>;
39
+ return feedbackCommand?.priority ? -feedbackCommand.priority : feedbackCommand.rank ?? Ranked.DEFAULT_RANK;
40
+ }
@@ -16,4 +16,6 @@
16
16
  export * from './css-feedback';
17
17
  export * from './feedback-action-dispatcher';
18
18
  export * from './feedback-command';
19
+ export * from './set-model-command';
19
20
  export * from './update-model-command';
21
+
@@ -0,0 +1,45 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2024 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 { CommandExecutionContext, GModelRoot, ILogger, SetModelAction, SetModelCommand, TYPES } from '@eclipse-glsp/sprotty';
17
+ import { inject, injectable, optional } from 'inversify';
18
+ import { IFeedbackActionDispatcher } from './feedback-action-dispatcher';
19
+
20
+ @injectable()
21
+ export class FeedbackAwareSetModelCommand extends SetModelCommand {
22
+ @inject(TYPES.ILogger)
23
+ protected logger: ILogger;
24
+
25
+ @inject(TYPES.IFeedbackActionDispatcher)
26
+ @optional()
27
+ protected feedbackActionDispatcher?: IFeedbackActionDispatcher;
28
+
29
+ constructor(@inject(TYPES.Action) action: SetModelAction) {
30
+ super(action);
31
+ }
32
+
33
+ override execute(context: CommandExecutionContext): GModelRoot {
34
+ const root = super.execute(context);
35
+ this.applyFeedback(root, context);
36
+ return root;
37
+ }
38
+
39
+ protected applyFeedback(newRoot: GModelRoot, context: CommandExecutionContext): void {
40
+ // Create a temporary context which defines the `newRoot` as `root`
41
+ // This way we do not corrupt the redo/undo behavior of the super class
42
+ const tempContext: CommandExecutionContext = { ...context, root: newRoot };
43
+ this.feedbackActionDispatcher?.applyFeedbackCommands(tempContext);
44
+ }
45
+ }
@@ -13,25 +13,20 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
- import { inject, injectable, optional } from 'inversify';
17
16
  import {
18
- ActionHandlerRegistry,
19
17
  Animation,
20
- Command,
21
- CommandActionHandler,
22
18
  CommandExecutionContext,
23
19
  CommandReturn,
20
+ GModelRoot,
24
21
  ILogger,
25
22
  MorphEdgesAnimation,
26
- GModelRoot,
27
23
  TYPES,
28
24
  UpdateAnimationData,
29
25
  UpdateModelAction,
30
- UpdateModelCommand,
31
- toTypeGuard
26
+ UpdateModelCommand
32
27
  } from '@eclipse-glsp/sprotty';
28
+ import { inject, injectable, optional } from 'inversify';
33
29
  import { IFeedbackActionDispatcher } from './feedback-action-dispatcher';
34
- import { FeedbackCommand } from './feedback-command';
35
30
 
36
31
  /**
37
32
  * A special {@link UpdateModelCommand} that retrieves all registered {@link Action}s from the {@link IFeedbackActionDispatcher}
@@ -47,50 +42,18 @@ export class FeedbackAwareUpdateModelCommand extends UpdateModelCommand {
47
42
  @optional()
48
43
  protected feedbackActionDispatcher: IFeedbackActionDispatcher;
49
44
 
50
- protected actionHandlerRegistry?: ActionHandlerRegistry;
51
-
52
- constructor(
53
- @inject(TYPES.Action) action: UpdateModelAction,
54
- @inject(TYPES.ActionHandlerRegistryProvider)
55
- actionHandlerRegistryProvider: () => Promise<ActionHandlerRegistry>
56
- ) {
45
+ constructor(@inject(TYPES.Action) action: UpdateModelAction) {
57
46
  super({ animate: true, ...action });
58
- actionHandlerRegistryProvider().then(registry => (this.actionHandlerRegistry = registry));
59
47
  }
60
48
 
61
49
  protected override performUpdate(oldRoot: GModelRoot, newRoot: GModelRoot, context: CommandExecutionContext): CommandReturn {
62
- if (this.feedbackActionDispatcher && this.actionHandlerRegistry) {
63
- // Create a temporary context which defines the `newRoot` as `root`
64
- // This way we do not corrupt the redo/undo behavior of the super class
65
- const tempContext: CommandExecutionContext = {
66
- ...context,
67
- root: newRoot
68
- };
69
-
70
- const feedbackCommands = this.getFeedbackCommands(this.actionHandlerRegistry);
71
- feedbackCommands.forEach(command => command.execute(tempContext));
72
- }
73
-
50
+ // Create a temporary context which defines the `newRoot` as `root`
51
+ // This way we do not corrupt the redo/undo behavior of the super class
52
+ const tempContext: CommandExecutionContext = { ...context, root: newRoot };
53
+ this.feedbackActionDispatcher?.applyFeedbackCommands(tempContext);
74
54
  return super.performUpdate(oldRoot, newRoot, context);
75
55
  }
76
56
 
77
- protected getFeedbackCommands(registry: ActionHandlerRegistry): Command[] {
78
- const result: Command[] = [];
79
- this.feedbackActionDispatcher.getRegisteredFeedback().forEach(action => {
80
- const commands = registry
81
- .get(action.kind)
82
- .filter<CommandActionHandler>(toTypeGuard(CommandActionHandler))
83
- .map(handler => handler.handle(action));
84
- result.push(...commands);
85
- });
86
- // sort commands descanting by priority
87
- return result.sort((a, b) => this.getPriority(b) - this.getPriority(a));
88
- }
89
-
90
- protected getPriority(command: Partial<FeedbackCommand>): number {
91
- return command.priority ?? 0;
92
- }
93
-
94
57
  // Override the `createAnimations` implementation and remove the animation for edge morphing. Otherwise routing & reconnect
95
58
  // handles flicker after each server update.
96
59
  protected override createAnimations(data: UpdateAnimationData, root: GModelRoot, context: CommandExecutionContext): Animation[] {
@@ -21,11 +21,16 @@ import { AnyObject, hasNumberProp } from '@eclipse-glsp/sprotty';
21
21
  * orderable by a type or rank/priority.
22
22
  */
23
23
  export interface Ranked {
24
+ /**
25
+ * A rank implies the position of this element within a sequence of other ranked elements.
26
+ * A lower rank implies a position earlier in the list.
27
+ */
24
28
  rank: number;
25
29
  }
26
30
 
27
31
  export namespace Ranked {
28
32
  export const DEFAULT_RANK = 0;
33
+
29
34
  export function is(object: unknown): object is Ranked {
30
35
  return AnyObject.is(object) && hasNumberProp(object, 'rank');
31
36
  }
@@ -39,4 +44,13 @@ export namespace Ranked {
39
44
  export function getRank(object: unknown): number {
40
45
  return is(object) ? object.rank : DEFAULT_RANK;
41
46
  }
47
+
48
+ /** Sort function for lowest rank first. */
49
+ export const sortAsc = (left: unknown, right: unknown): number => getRank(left) - getRank(right);
50
+
51
+ /** Sort function for highest rank first. */
52
+ export const sortDesc = (left: unknown, right: unknown): number => getRank(right) - getRank(left);
53
+
54
+ /** Default sort function for rank: Lowest rank first */
55
+ export const sort = sortAsc;
42
56
  }
@@ -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, Disposable, GModelRoot, GNode, TYPES, initializeContainer } from '@eclipse-glsp/sprotty';
16
+ import { Action, Command, CommandExecutionContext, Disposable, GModelRoot, GNode, TYPES, initializeContainer } from '@eclipse-glsp/sprotty';
17
17
  import { AssertionError, expect } from 'chai';
18
18
  import { Container, injectable } from 'inversify';
19
19
  import * as sinon from 'sinon';
@@ -44,6 +44,12 @@ class MockFeedbackActionDispatcher implements IFeedbackActionDispatcher {
44
44
  const actions = this.getRegisteredFeedback();
45
45
  return actions.length === 1 ? (actions[0] as SelectFeedbackAction) : undefined;
46
46
  }
47
+
48
+ getFeedbackCommands(): Command[] {
49
+ return [];
50
+ }
51
+
52
+ async applyFeedbackCommands(context: CommandExecutionContext): Promise<void> {}
47
53
  }
48
54
 
49
55
  class MockSelectionListener implements ISelectionListener {
@@ -24,6 +24,7 @@ import {
24
24
  isLayoutContainer
25
25
  } from '@eclipse-glsp/sprotty';
26
26
  import { inject, injectable } from 'inversify';
27
+ import { Ranked } from '../../base';
27
28
  import { GLSPActionDispatcher } from '../../base/action-dispatcher';
28
29
  import { FeedbackCommand } from '../../base/feedback/feedback-command';
29
30
  import { LocalRequestBoundsAction } from './local-bounds';
@@ -48,7 +49,7 @@ export namespace SetBoundsFeedbackAction {
48
49
  export class SetBoundsFeedbackCommand extends SetBoundsCommand implements FeedbackCommand {
49
50
  static override readonly KIND: string = SetBoundsFeedbackAction.KIND;
50
51
 
51
- readonly priority: number = 0;
52
+ readonly rank: number = Ranked.DEFAULT_RANK;
52
53
 
53
54
  @inject(TYPES.IActionDispatcher) protected actionDispatcher: GLSPActionDispatcher;
54
55
 
@@ -13,19 +13,18 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
- import { inject, injectable } from 'inversify';
17
16
  import {
18
17
  Action,
19
18
  CommandExecutionContext,
20
19
  Connectable,
21
20
  EdgeTypeHint,
22
- IActionHandler,
23
- RequestTypeHintsAction,
24
21
  GModelElement,
25
22
  GModelElementSchema,
26
23
  GModelRoot,
27
24
  GRoutableElement,
28
25
  GShapeElement,
26
+ IActionHandler,
27
+ RequestTypeHintsAction,
29
28
  SetTypeHintsAction,
30
29
  ShapeTypeHint,
31
30
  TYPES,
@@ -36,16 +35,17 @@ import {
36
35
  isConnectable,
37
36
  moveFeature
38
37
  } from '@eclipse-glsp/sprotty';
38
+ import { inject, injectable } from 'inversify';
39
39
 
40
40
  import { GLSPActionDispatcher } from '../../base/action-dispatcher';
41
41
  import { IFeedbackActionDispatcher } from '../../base/feedback/feedback-action-dispatcher';
42
42
  import { FeedbackCommand } from '../../base/feedback/feedback-command';
43
43
  import { IDiagramStartup } from '../../base/model/diagram-loader';
44
+ import { GEdge } from '../../model';
44
45
  import { getElementTypeId } from '../../utils/gmodel-util';
45
46
  import { resizeFeature } from '../change-bounds/model';
46
47
  import { reconnectFeature } from '../reconnect/model';
47
48
  import { containerFeature, isContainable, reparentFeature } from './model';
48
- import { GEdge } from '../../model';
49
49
 
50
50
  /**
51
51
  * Is dispatched by the {@link TypeHintProvider} to apply the type hints received from the server
@@ -78,7 +78,7 @@ type CanConnectFn = Connectable['canConnect'];
78
78
  @injectable()
79
79
  export class ApplyTypeHintsCommand extends FeedbackCommand {
80
80
  public static KIND = ApplyTypeHintsAction.KIND;
81
- public override readonly priority = 10;
81
+ public override readonly rank: number = -10;
82
82
 
83
83
  @inject(TYPES.ITypeHintProvider)
84
84
  protected typeHintProvider: ITypeHintProvider;
@@ -0,0 +1,65 @@
1
+ /*******************************************************************************
2
+ * Copyright (C) 2017 TypeFox and others.
3
+ * Modifications: (c) 2024 EclipseSource and others.
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the Eclipse Public License v. 2.0 which is available at
7
+ * http://www.eclipse.org/legal/epl-2.0.
8
+ *
9
+ * This Source Code may also be made available under the following Secondary
10
+ * Licenses when the conditions for such availability set forth in the Eclipse
11
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ * with the GNU Classpath Exception which is available at
13
+ * https://www.gnu.org/software/classpath/license.html.
14
+ *
15
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ *******************************************************************************/
17
+ // eslint-disable-next-line max-len
18
+ // based on https://github.com/eclipse-theia/theia/blob/9ff0cedff1d591b0eb4be97a05f6d992789d0a24/packages/core/src/common/contribution-provider.ts
19
+
20
+ import { BindingContext, TYPES } from '@eclipse-glsp/sprotty';
21
+ import { interfaces } from 'inversify';
22
+
23
+ export interface IContributionProvider<T extends object> {
24
+ /**
25
+ * @param recursive `true` if the contributions should be collected from the parent containers as well. Otherwise, `false`.
26
+ * It is `false` by default.
27
+ */
28
+ getContributions(recursive?: boolean): T[];
29
+ }
30
+
31
+ class ContainerBasedContributionProvider<T extends object> implements IContributionProvider<T> {
32
+ protected services: T[] | undefined;
33
+
34
+ constructor(
35
+ protected readonly serviceIdentifier: interfaces.ServiceIdentifier<T>,
36
+ protected readonly container: interfaces.Container
37
+ ) {}
38
+
39
+ getContributions(recursive?: boolean): T[] {
40
+ if (this.services === undefined) {
41
+ const currentServices: T[] = [];
42
+ let currentContainer: interfaces.Container | undefined = this.container;
43
+ while (currentContainer !== undefined) {
44
+ if (currentContainer.isBound(this.serviceIdentifier)) {
45
+ try {
46
+ currentServices.push(...currentContainer.getAll(this.serviceIdentifier));
47
+ } catch (error) {
48
+ console.error(error);
49
+ }
50
+ }
51
+ currentContainer = recursive === true && currentContainer.parent ? currentContainer.parent : undefined;
52
+ }
53
+ this.services = currentServices;
54
+ }
55
+ return this.services;
56
+ }
57
+ }
58
+
59
+ export function bindContributionProvider(context: Pick<BindingContext, 'bind'> | interfaces.Bind, id: symbol): void {
60
+ const bind = typeof context === 'object' ? context.bind.bind(context) : context;
61
+ bind(TYPES.IContributionProvider)
62
+ .toDynamicValue(ctx => new ContainerBasedContributionProvider(id, ctx.container))
63
+ .inSingletonScope()
64
+ .whenTargetNamed(id);
65
+ }