@eclipse-glsp/server 1.1.0-RC05 → 1.1.0-next.44aae0c.44

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 (40) hide show
  1. package/lib/common/command/command-stack.d.ts +7 -6
  2. package/lib/common/command/command-stack.d.ts.map +1 -1
  3. package/lib/common/command/command-stack.js +6 -6
  4. package/lib/common/command/command-stack.js.map +1 -1
  5. package/lib/common/command/command-stack.spec.js +31 -31
  6. package/lib/common/command/command-stack.spec.js.map +1 -1
  7. package/lib/common/command/command.d.ts +7 -6
  8. package/lib/common/command/command.d.ts.map +1 -1
  9. package/lib/common/command/command.js +19 -15
  10. package/lib/common/command/command.js.map +1 -1
  11. package/lib/common/command/command.spec.js +8 -8
  12. package/lib/common/command/command.spec.js.map +1 -1
  13. package/lib/common/command/recording-command.d.ts +8 -8
  14. package/lib/common/command/recording-command.d.ts.map +1 -1
  15. package/lib/common/command/recording-command.js +4 -4
  16. package/lib/common/command/recording-command.js.map +1 -1
  17. package/lib/common/command/recording-command.spec.js +8 -8
  18. package/lib/common/command/recording-command.spec.js.map +1 -1
  19. package/lib/common/command/undo-redo-action-handler.d.ts +2 -2
  20. package/lib/common/command/undo-redo-action-handler.d.ts.map +1 -1
  21. package/lib/common/command/undo-redo-action-handler.js +4 -4
  22. package/lib/common/command/undo-redo-action-handler.js.map +1 -1
  23. package/lib/common/operations/operation-action-handler.d.ts +1 -1
  24. package/lib/common/operations/operation-action-handler.d.ts.map +1 -1
  25. package/lib/common/operations/operation-action-handler.js +3 -3
  26. package/lib/common/operations/operation-action-handler.js.map +1 -1
  27. package/lib/common/test/mock-util.d.ts +7 -1
  28. package/lib/common/test/mock-util.d.ts.map +1 -1
  29. package/lib/common/test/mock-util.js +23 -1
  30. package/lib/common/test/mock-util.js.map +1 -1
  31. package/package.json +4 -4
  32. package/src/common/command/command-stack.spec.ts +32 -32
  33. package/src/common/command/command-stack.ts +10 -9
  34. package/src/common/command/command.spec.ts +9 -10
  35. package/src/common/command/command.ts +23 -19
  36. package/src/common/command/recording-command.spec.ts +8 -8
  37. package/src/common/command/recording-command.ts +8 -8
  38. package/src/common/command/undo-redo-action-handler.ts +4 -4
  39. package/src/common/operations/operation-action-handler.ts +3 -3
  40. package/src/common/test/mock-util.ts +21 -0
@@ -15,7 +15,7 @@
15
15
  ********************************************************************************/
16
16
  import { expect } from 'chai';
17
17
  import * as sinon from 'sinon';
18
- import { StubCommand } from '../test/mock-util';
18
+ import { expectToThrowAsync, StubCommand } from '../test/mock-util';
19
19
  import { CompoundCommand } from './command';
20
20
 
21
21
  describe('CompoundCommand', () => {
@@ -32,18 +32,18 @@ describe('CompoundCommand', () => {
32
32
  });
33
33
 
34
34
  describe('execute', () => {
35
- it('Should execute the subcommands in order', () => {
36
- compoundCommand.execute();
35
+ it('Should execute the subcommands in order', async () => {
36
+ await compoundCommand.execute();
37
37
  expect(command1.execute.calledOnce).to.be.true;
38
38
  expect(command2.execute.calledOnce).to.be.true;
39
39
  expect(command3.execute.calledOnce).to.be.true;
40
40
  expect(command1.execute.calledBefore(command2.execute)).to.be.true;
41
41
  expect(command2.execute.calledBefore(command3.execute)).to.be.true;
42
42
  });
43
- it('Should undo partially executed subcommands in case of an error', () => {
43
+ it('Should undo partially executed subcommands in case of an error', async () => {
44
44
  command3.execute.throwsException();
45
45
 
46
- expect(() => compoundCommand.execute()).to.throw();
46
+ await expectToThrowAsync(() => compoundCommand.execute());
47
47
 
48
48
  expect(command1.execute.calledOnce).to.be.true;
49
49
  expect(command2.execute.calledOnce).to.be.true;
@@ -54,8 +54,8 @@ describe('CompoundCommand', () => {
54
54
  });
55
55
 
56
56
  describe('undo', () => {
57
- it('Should undo the subcommands in reverse order', () => {
58
- compoundCommand.undo();
57
+ it('Should undo the subcommands in reverse order', async () => {
58
+ await compoundCommand.undo();
59
59
  expect(command1.undo.calledOnce).to.be.true;
60
60
  expect(command2.undo.calledOnce).to.be.true;
61
61
  expect(command3.undo.calledOnce).to.be.true;
@@ -63,10 +63,9 @@ describe('CompoundCommand', () => {
63
63
  expect(command2.undo.calledAfter(command3.undo)).to.be.true;
64
64
  });
65
65
 
66
- it('Should redo partially undone subcommands in case of an error', () => {
66
+ it('Should redo partially undone subcommands in case of an error', async () => {
67
67
  command1.undo.throwsException();
68
-
69
- expect(() => compoundCommand.undo()).to.throw();
68
+ await expectToThrowAsync(() => compoundCommand.undo());
70
69
 
71
70
  expect(command1.undo.calledOnce).to.be.true;
72
71
  expect(command2.undo.calledOnce).to.be.true;
@@ -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
 
17
- import { flatPush, MaybeArray } from '@eclipse-glsp/protocol';
17
+ import { flatPush, MaybeArray, MaybePromise } from '@eclipse-glsp/protocol';
18
18
 
19
19
  /**
20
20
  * A command implements a specific modification of the source model, which can be applied by invoking `execute()`.
@@ -30,19 +30,19 @@ export interface Command {
30
30
  /**
31
31
  * Performs the command activity required for the effect (e.g. source model change).
32
32
  */
33
- execute(): void;
33
+ execute(): MaybePromise<void>;
34
34
 
35
35
  /**
36
36
  * Performs the command activity required to `undo` the effects of a preceding `execute` (or `redo`).
37
37
  * The effect, if any, of calling `undo` before `execute` or `redo` have been called, is undefined.
38
38
  */
39
- undo(): void;
39
+ undo(): MaybePromise<void>;
40
40
 
41
41
  /**
42
42
  * Performs the command activity required to `redo` the effect after undoing the effect.
43
43
  * The effect, if any, of calling `redo` before `undo` is called is undefined.
44
44
  */
45
- redo(): void;
45
+ redo(): MaybePromise<void>;
46
46
 
47
47
  /**
48
48
  * Returns whether the command can be undone.
@@ -71,18 +71,18 @@ export class CompoundCommand implements Command {
71
71
  flatPush(this.commands, commands);
72
72
  }
73
73
 
74
- execute(): void {
74
+ async execute(): Promise<void> {
75
75
  const alreadyExecuted: Command[] = [];
76
76
 
77
77
  try {
78
- this.commands.forEach(command => {
79
- command.execute();
78
+ for (const command of this.commands) {
79
+ await command.execute();
80
80
  alreadyExecuted.unshift(command);
81
- });
81
+ }
82
82
  } catch (err) {
83
83
  for (const command of alreadyExecuted) {
84
84
  if (Command.canUndo(command)) {
85
- command.undo();
85
+ await command.undo();
86
86
  } else {
87
87
  break;
88
88
  }
@@ -91,29 +91,33 @@ export class CompoundCommand implements Command {
91
91
  }
92
92
  }
93
93
 
94
- undo(): void {
94
+ async undo(): Promise<void> {
95
95
  const alreadyUndone: Command[] = [];
96
96
  try {
97
- [...this.commands].reverse().forEach(command => {
98
- command.undo();
97
+ for (const command of [...this.commands].reverse()) {
98
+ await command.undo();
99
99
  alreadyUndone.unshift(command);
100
- });
100
+ }
101
101
  } catch (err) {
102
- alreadyUndone.forEach(command => command.redo());
102
+ for (const command of alreadyUndone) {
103
+ await command.redo();
104
+ }
103
105
  throw err;
104
106
  }
105
107
  }
106
108
 
107
- redo(): void {
109
+ async redo(): Promise<void> {
108
110
  const alreadyRedone: Command[] = [];
109
111
 
110
112
  try {
111
- this.commands.forEach(command => {
112
- command.redo();
113
+ for (const command of this.commands) {
114
+ await command.redo();
113
115
  alreadyRedone.unshift(command);
114
- });
116
+ }
115
117
  } catch (err) {
116
- alreadyRedone.forEach(command => command.undo());
118
+ for (const command of alreadyRedone) {
119
+ await command.undo();
120
+ }
117
121
  throw err;
118
122
  }
119
123
  }
@@ -39,36 +39,36 @@ describe('RecordingCommand', () => {
39
39
  beforeState = JSON.parse(JSON.stringify(jsonObject));
40
40
  });
41
41
 
42
- it('should be undoable after execution', () => {
42
+ it('should be undoable after execution', async () => {
43
43
  // eslint-disable-next-line @typescript-eslint/no-empty-function
44
44
  const command = new RecordingCommand(jsonObject, () => {});
45
45
  expect(command.canUndo()).to.be.false;
46
- command.execute();
46
+ await command.execute();
47
47
  expect(command.canUndo()).to.be.true;
48
48
  });
49
49
 
50
- it('should restore the pre execution state when undo is called', () => {
50
+ it('should restore the pre execution state when undo is called', async () => {
51
51
  const command = new RecordingCommand(jsonObject, () => {
52
52
  jsonObject.string = 'bar';
53
53
  jsonObject.flag = false;
54
54
  jsonObject.maybe = { hello: 'world' };
55
55
  });
56
- command.execute();
56
+ await command.execute();
57
57
  expect(jsonObject).to.not.be.deep.equals(beforeState);
58
- command.undo();
58
+ await command.undo();
59
59
  expect(jsonObject).to.be.deep.equals(beforeState);
60
60
  });
61
61
 
62
- it('should restore the post execution state when redo is called', () => {
62
+ it('should restore the post execution state when redo is called', async () => {
63
63
  const command = new RecordingCommand(jsonObject, () => {
64
64
  jsonObject.string = 'bar';
65
65
  jsonObject.flag = false;
66
66
  jsonObject.maybe = { hello: 'world' };
67
67
  });
68
- command.execute();
68
+ await command.execute();
69
69
  const afterState = JSON.parse(JSON.stringify(jsonObject));
70
70
  jsonObject = JSON.parse(JSON.stringify(afterState));
71
- command.redo();
71
+ await command.redo();
72
72
  expect(jsonObject).to.be.deep.equals(afterState);
73
73
  });
74
74
  });
@@ -15,7 +15,7 @@
15
15
  ********************************************************************************/
16
16
 
17
17
  import { GModelRootSchema } from '@eclipse-glsp/graph';
18
- import { AnyObject } from '@eclipse-glsp/protocol';
18
+ import { AnyObject, MaybePromise } from '@eclipse-glsp/protocol';
19
19
  import * as jsonPatch from 'fast-json-patch';
20
20
  import { GModelSerializer } from '../features/model/gmodel-serializer';
21
21
  import { ModelState } from '../features/model/model-state';
@@ -28,9 +28,9 @@ export abstract class AbstractRecordingCommand<JsonObject extends AnyObject> imp
28
28
  protected undoPatch?: jsonPatch.Operation[];
29
29
  protected redoPatch?: jsonPatch.Operation[];
30
30
 
31
- execute(): void {
31
+ async execute(): Promise<void> {
32
32
  const beforeState = this.deepClone(this.getJsonObject());
33
- this.doExecute();
33
+ await this.doExecute();
34
34
  const afterState = this.getJsonObject();
35
35
  this.undoPatch = jsonPatch.compare(afterState, beforeState);
36
36
  this.redoPatch = jsonPatch.compare(beforeState, afterState);
@@ -46,7 +46,7 @@ export abstract class AbstractRecordingCommand<JsonObject extends AnyObject> imp
46
46
  /**
47
47
  * The actual execution i.e. series of changes applied to the JSOn object that should be captured.
48
48
  */
49
- protected abstract doExecute(): void;
49
+ protected abstract doExecute(): MaybePromise<void>;
50
50
 
51
51
  protected applyPatch(object: JsonObject, patch: jsonPatch.Operation[]): void {
52
52
  jsonPatch.applyPatch(object, patch, false, true);
@@ -84,7 +84,7 @@ export abstract class AbstractRecordingCommand<JsonObject extends AnyObject> imp
84
84
  * the the given `doExecute` function.
85
85
  */
86
86
  export class RecordingCommand<JsonObject extends AnyObject = AnyObject> extends AbstractRecordingCommand<JsonObject> {
87
- constructor(protected jsonObject: JsonObject, protected doExecute: () => void) {
87
+ constructor(protected jsonObject: JsonObject, protected doExecute: () => MaybePromise<void>) {
88
88
  super();
89
89
  }
90
90
 
@@ -98,12 +98,12 @@ export class RecordingCommand<JsonObject extends AnyObject = AnyObject> extends
98
98
  * to the `GModelRoot` ({@link ModelState.root}) during the given `doExecute` function
99
99
  */
100
100
  export class GModelRecordingCommand extends AbstractRecordingCommand<GModelRootSchema> {
101
- constructor(protected modelState: ModelState, protected serializer: GModelSerializer, protected doExecute: () => void) {
101
+ constructor(protected modelState: ModelState, protected serializer: GModelSerializer, protected doExecute: () => MaybePromise<void>) {
102
102
  super();
103
103
  }
104
104
 
105
- override execute(): void {
106
- super.execute();
105
+ override async execute(): Promise<void> {
106
+ await super.execute();
107
107
  this.modelState.index.indexRoot(this.modelState.root);
108
108
  }
109
109
 
@@ -39,17 +39,17 @@ export class UndoRedoActionHandler implements ActionHandler {
39
39
  return [];
40
40
  }
41
41
 
42
- protected undo(): MaybePromise<Action[]> {
42
+ protected async undo(): Promise<Action[]> {
43
43
  if (this.commandStack.canUndo()) {
44
- this.commandStack.undo();
44
+ await this.commandStack.undo();
45
45
  return this.modelSubmissionHandler.submitModel('undo');
46
46
  }
47
47
  return [];
48
48
  }
49
49
 
50
- protected redo(): MaybePromise<Action[]> {
50
+ protected async redo(): Promise<Action[]> {
51
51
  if (this.commandStack.canRedo()) {
52
- this.commandStack.redo();
52
+ await this.commandStack.redo();
53
53
  return this.modelSubmissionHandler.submitModel('redo');
54
54
  }
55
55
  return [];
@@ -66,13 +66,13 @@ export class OperationActionHandler implements ActionHandler {
66
66
  protected async executeHandler(operation: Operation, handler: OperationHandler): Promise<Action[]> {
67
67
  const command = await handler.execute(operation);
68
68
  if (command) {
69
- this.executeCommand(command);
69
+ await this.executeCommand(command);
70
70
  }
71
71
  return this.modelSubmissionHandler.submitModel('operation');
72
72
  }
73
73
 
74
- protected executeCommand(command: Command): void {
75
- this.commandStack.execute(command);
74
+ protected async executeCommand(command: Command): Promise<void> {
75
+ return this.commandStack.execute(command);
76
76
  }
77
77
 
78
78
  protected submitModel(): MaybePromise<Action[]> {
@@ -25,11 +25,13 @@ import {
25
25
  EdgeTypeHint,
26
26
  InitializeClientSessionParameters,
27
27
  MaybeArray,
28
+ MaybePromise,
28
29
  Point,
29
30
  RequestEditValidationAction,
30
31
  ShapeTypeHint,
31
32
  ValidationStatus
32
33
  } from '@eclipse-glsp/protocol';
34
+ import { expect } from 'chai';
33
35
  import { Container } from 'inversify';
34
36
  import { MessageConnection } from 'vscode-jsonrpc';
35
37
  import { ActionDispatcher } from '../actions/action-dispatcher';
@@ -53,6 +55,25 @@ export async function delay(ms: number): Promise<void> {
53
55
  return new Promise(resolve => setTimeout(resolve, ms));
54
56
  }
55
57
 
58
+ /**
59
+ * Consumes a maybe async function and checks for error
60
+ * @param method - The function to check
61
+ * @param message - Optional message to match with error message
62
+ */
63
+ export async function expectToThrowAsync(toEvaluate: () => MaybePromise<void>, message?: string): Promise<void> {
64
+ let err: Error | undefined = undefined;
65
+ try {
66
+ await toEvaluate();
67
+ } catch (error: any) {
68
+ err = error;
69
+ }
70
+ if (message) {
71
+ expect(err?.message).to.be.equal(message);
72
+ } else {
73
+ expect(err).to.be.an('Error');
74
+ }
75
+ }
76
+
56
77
  export function createClientSession(
57
78
  id: string,
58
79
  diagramType: string,