@eclipse-glsp/server 2.8.0-next.5 → 2.8.0-next.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common/features/directediting/context-edit-validator.js +3 -3
- package/lib/common/features/directediting/context-edit-validator.js.map +1 -1
- package/package.json +8 -8
- package/src/common/features/directediting/context-edit-validator.ts +2 -2
- package/src/browser/di/browser-action-dispatch-scope.spec.ts +0 -75
- package/src/common/actions/action-handler-registry.spec.ts +0 -52
- package/src/common/actions/global-action-provider.spec.ts +0 -68
- package/src/common/command/command-stack.spec.ts +0 -239
- package/src/common/command/command.spec.ts +0 -92
- package/src/common/command/recording-command.spec.ts +0 -86
- package/src/common/di/binding-target.spec.ts +0 -147
- package/src/common/di/multi-bindings.spec.ts +0 -133
- package/src/common/features/contextactions/context-actions-provider-registry.spec.ts +0 -69
- package/src/common/features/contextactions/request-context-actions-handler.spec.ts +0 -75
- package/src/common/features/contextactions/tool-palette-item-provider.spec.ts +0 -46
- package/src/common/features/directediting/context-edit-validator-registry.spec.ts +0 -54
- package/src/common/features/directediting/request-edit-validation-handler.spec.ts +0 -131
- package/src/common/features/model/gmodel-serializer.spec.ts +0 -141
- package/src/common/features/type-hints/request-type-hints-action-handler.spec.ts +0 -59
- package/src/common/operations/operation-handler-registry.spec.ts +0 -50
- package/src/common/protocol/glsp-server.spec.ts +0 -154
- package/src/common/session/client-session-factory.spec.ts +0 -60
- package/src/common/session/client-session-manager.spec.ts +0 -83
- package/src/common/test/mock-util.ts +0 -281
- package/src/common/utils/action-queue.spec.ts +0 -133
- package/src/common/utils/promise-queue.spec.ts +0 -142
- package/src/common/utils/registry.spec.ts +0 -225
- package/src/node/actions/action-dispatcher.spec.ts +0 -678
- package/src/node/launch/cli-parser.spec.ts +0 -61
- package/src/node/launch/socket-cli-parser.spec.ts +0 -73
- package/src/node/launch/socket-server-launcher.spec.ts +0 -74
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2023-2026 EclipseSource and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
|
|
17
|
-
import { AnyObject, MaybePromise } from '@eclipse-glsp/protocol';
|
|
18
|
-
import { expect } from 'chai';
|
|
19
|
-
import { AbstractRecordingCommand } from './recording-command';
|
|
20
|
-
|
|
21
|
-
interface TestModel {
|
|
22
|
-
string: string;
|
|
23
|
-
number: number;
|
|
24
|
-
flag: boolean;
|
|
25
|
-
maybe?: AnyObject;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let jsonObject: TestModel;
|
|
29
|
-
|
|
30
|
-
class TestRecordingCommand<JsonObject extends AnyObject = AnyObject> extends AbstractRecordingCommand<JsonObject> {
|
|
31
|
-
constructor(
|
|
32
|
-
protected jsonObject: JsonObject,
|
|
33
|
-
protected doExecute: () => MaybePromise<void>
|
|
34
|
-
) {
|
|
35
|
-
super();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
protected getJsonObject(): MaybePromise<JsonObject> {
|
|
39
|
-
return this.jsonObject;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
describe('RecordingCommand', () => {
|
|
44
|
-
let beforeState: TestModel;
|
|
45
|
-
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
jsonObject = {
|
|
48
|
-
string: 'foo',
|
|
49
|
-
number: 0,
|
|
50
|
-
flag: true
|
|
51
|
-
};
|
|
52
|
-
beforeState = JSON.parse(JSON.stringify(jsonObject));
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should be undoable after execution', async () => {
|
|
56
|
-
const command = new TestRecordingCommand(jsonObject, () => {});
|
|
57
|
-
expect(command.canUndo()).to.be.false;
|
|
58
|
-
await command.execute();
|
|
59
|
-
expect(command.canUndo()).to.be.true;
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should restore the pre execution state when undo is called', async () => {
|
|
63
|
-
const command = new TestRecordingCommand(jsonObject, () => {
|
|
64
|
-
jsonObject.string = 'bar';
|
|
65
|
-
jsonObject.flag = false;
|
|
66
|
-
jsonObject.maybe = { hello: 'world' };
|
|
67
|
-
});
|
|
68
|
-
await command.execute();
|
|
69
|
-
expect(jsonObject).to.not.be.deep.equals(beforeState);
|
|
70
|
-
await command.undo();
|
|
71
|
-
expect(jsonObject).to.be.deep.equals(beforeState);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should restore the post execution state when redo is called', async () => {
|
|
75
|
-
const command = new TestRecordingCommand(jsonObject, () => {
|
|
76
|
-
jsonObject.string = 'bar';
|
|
77
|
-
jsonObject.flag = false;
|
|
78
|
-
jsonObject.maybe = { hello: 'world' };
|
|
79
|
-
});
|
|
80
|
-
await command.execute();
|
|
81
|
-
const afterState = JSON.parse(JSON.stringify(jsonObject));
|
|
82
|
-
jsonObject = JSON.parse(JSON.stringify(afterState));
|
|
83
|
-
await command.redo();
|
|
84
|
-
expect(jsonObject).to.be.deep.equals(afterState);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-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 { expect } from 'chai';
|
|
17
|
-
import { Container, ContainerModule, interfaces } from 'inversify';
|
|
18
|
-
import * as sinon from 'sinon';
|
|
19
|
-
import { applyBindingTarget } from './binding-target';
|
|
20
|
-
// Simple no op classes to construct inversify binding syntaxes.
|
|
21
|
-
class Target {}
|
|
22
|
-
|
|
23
|
-
class SubTarget extends Target {}
|
|
24
|
-
|
|
25
|
-
describe('BindingTarget', () => {
|
|
26
|
-
describe('bindTarget()', () => {
|
|
27
|
-
// Setup nested spies for the fluent inversify binding API
|
|
28
|
-
let context: {
|
|
29
|
-
bind: sinon.SinonStub<[serviceIdentifier: interfaces.ServiceIdentifier<any>], interfaces.BindingToSyntax<any>>;
|
|
30
|
-
isBound: sinon.SinonStub<[serviceIdentifier: interfaces.ServiceIdentifier<any>], boolean>;
|
|
31
|
-
};
|
|
32
|
-
let toSyntax: sinon.SinonStubbedInstance<interfaces.BindingToSyntax<any>>;
|
|
33
|
-
let whenOnSyntax: sinon.SinonStubbedInstance<interfaces.BindingWhenOnSyntax<any>>;
|
|
34
|
-
|
|
35
|
-
const setupStubs = (): {
|
|
36
|
-
context: {
|
|
37
|
-
bind: sinon.SinonStub<[serviceIdentifier: interfaces.ServiceIdentifier<any>], interfaces.BindingToSyntax<any>>;
|
|
38
|
-
isBound: sinon.SinonStub<[serviceIdentifier: interfaces.ServiceIdentifier<any>], boolean>;
|
|
39
|
-
};
|
|
40
|
-
toSyntax: sinon.SinonStubbedInstance<interfaces.BindingToSyntax<any>>;
|
|
41
|
-
inWhenOnSyntax: sinon.SinonStubbedInstance<interfaces.BindingInWhenOnSyntax<any>>;
|
|
42
|
-
whenOnSyntax: sinon.SinonStubbedInstance<interfaces.BindingWhenOnSyntax<any>>;
|
|
43
|
-
} => {
|
|
44
|
-
const container = new Container();
|
|
45
|
-
const bind = sinon.stub<[serviceIdentifier: interfaces.ServiceIdentifier<any>], interfaces.BindingToSyntax<any>>();
|
|
46
|
-
const isBound = sinon.stub<[serviceIdentifier: interfaces.ServiceIdentifier<any>], boolean>();
|
|
47
|
-
|
|
48
|
-
let toSyntax: sinon.SinonStubbedInstance<interfaces.BindingToSyntax<any>> = {} as any;
|
|
49
|
-
let inWhenOnSyntax: sinon.SinonStubbedInstance<interfaces.BindingInWhenOnSyntax<any>> = {} as any;
|
|
50
|
-
container.load(
|
|
51
|
-
new ContainerModule(_bind => {
|
|
52
|
-
const toStub = _bind('StubMe');
|
|
53
|
-
inWhenOnSyntax = sinon.stub(toStub.to(Target));
|
|
54
|
-
whenOnSyntax = sinon.stub(toStub.toConstantValue(''));
|
|
55
|
-
toSyntax = sinon.stub(toStub);
|
|
56
|
-
|
|
57
|
-
bind.returns(toSyntax);
|
|
58
|
-
toSyntax.to.returns(inWhenOnSyntax);
|
|
59
|
-
toSyntax.toSelf.returns(inWhenOnSyntax);
|
|
60
|
-
toSyntax.toDynamicValue.returns(inWhenOnSyntax);
|
|
61
|
-
toSyntax.toService.returns();
|
|
62
|
-
})
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
context: { bind, isBound },
|
|
67
|
-
toSyntax,
|
|
68
|
-
inWhenOnSyntax,
|
|
69
|
-
whenOnSyntax
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
beforeEach(() => {
|
|
74
|
-
const stubs = setupStubs();
|
|
75
|
-
context = stubs.context;
|
|
76
|
-
toSyntax = stubs.toSyntax;
|
|
77
|
-
whenOnSyntax = stubs.whenOnSyntax;
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('Bind to constructor', () => {
|
|
81
|
-
it('Should bind the service identifier `to` the given target with no scope', () => {
|
|
82
|
-
applyBindingTarget(context, Target, SubTarget);
|
|
83
|
-
expect(toSyntax.to.calledOnceWith(SubTarget)).to.be.true;
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('Should bind the service identifier `toSelf` with no scope', () => {
|
|
87
|
-
applyBindingTarget(context, Target, Target);
|
|
88
|
-
expect(toSyntax.toSelf.calledOnce).to.be.true;
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe('Bind to service', () => {
|
|
93
|
-
it('Should bind the service identifier `service` using the given target service with no scope', () => {
|
|
94
|
-
context.isBound.returns(true);
|
|
95
|
-
applyBindingTarget(context, Target, { service: SubTarget });
|
|
96
|
-
expect(toSyntax.toService.calledOnceWith(SubTarget)).to.be.true;
|
|
97
|
-
});
|
|
98
|
-
it('Should throw an error because the given target service is not bound', () => {
|
|
99
|
-
context.isBound.returns(false);
|
|
100
|
-
expect(() => applyBindingTarget(context, Target, { service: SubTarget, autoBind: false })).to.throw();
|
|
101
|
-
});
|
|
102
|
-
it('Should bind the unbound target service to itself before applying the toService binding', () => {
|
|
103
|
-
context.isBound.returns(false);
|
|
104
|
-
applyBindingTarget(context, Target, { service: SubTarget });
|
|
105
|
-
expect(context.bind.calledWith(Target)).to.be.true;
|
|
106
|
-
});
|
|
107
|
-
it('The return syntax should be no op and invocation of a syntax function should throw an error', () => {
|
|
108
|
-
context.isBound.returns(true);
|
|
109
|
-
const syntax = applyBindingTarget(context, Target, { service: SubTarget });
|
|
110
|
-
expect(() => {
|
|
111
|
-
syntax.inRequestScope();
|
|
112
|
-
}).to.throw(
|
|
113
|
-
`${Target.toString()} has been bound to 'service'.` +
|
|
114
|
-
"Using 'in','when' or 'on' bindings after" +
|
|
115
|
-
"a 'toService' binding is not possible."
|
|
116
|
-
);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
describe('Bind to constant value', () => {
|
|
121
|
-
it('Should bind the service identifier `toConstantValue` using the given target with no scope', () => {
|
|
122
|
-
const subTarget = new SubTarget();
|
|
123
|
-
applyBindingTarget(context, Target, { constantValue: subTarget });
|
|
124
|
-
expect(toSyntax.toConstantValue.calledOnceWith(subTarget)).to.be.true;
|
|
125
|
-
});
|
|
126
|
-
it("The return syntax's in functions should be no op and invocation should log a warning", () => {
|
|
127
|
-
const spy = sinon.spy(console, 'warn');
|
|
128
|
-
const subTarget = new SubTarget();
|
|
129
|
-
const syntax = applyBindingTarget(context, Target, { constantValue: subTarget });
|
|
130
|
-
syntax.inSingletonScope();
|
|
131
|
-
expect(
|
|
132
|
-
spy.calledWith(
|
|
133
|
-
`${Target.toString()} has been bound to 'constantValue'. Binding in Singleton scope has no effect.` +
|
|
134
|
-
'Constant value bindings are effectively Singleton bindings.'
|
|
135
|
-
)
|
|
136
|
-
).to.be.true;
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
describe('Bind to dynamic value', () => {
|
|
141
|
-
it('Should bind the service identifier `toDynamicValue` using the given factory function with no scope', () => {
|
|
142
|
-
applyBindingTarget(context, Target, { dynamicValue: context => new SubTarget() });
|
|
143
|
-
expect(toSyntax.toDynamicValue.calledOnce);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
});
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2023 STMicroelectronics and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
import { expect } from 'chai';
|
|
17
|
-
import { Container, ContainerModule, injectable } from 'inversify';
|
|
18
|
-
import { InstanceMultiBinding, MultiBinding } from './multi-binding';
|
|
19
|
-
|
|
20
|
-
@injectable()
|
|
21
|
-
class TestClass {}
|
|
22
|
-
|
|
23
|
-
@injectable()
|
|
24
|
-
class TestClass1 extends TestClass {}
|
|
25
|
-
|
|
26
|
-
@injectable()
|
|
27
|
-
class TestClass2 extends TestClass {}
|
|
28
|
-
|
|
29
|
-
@injectable()
|
|
30
|
-
class TestClass3 extends TestClass {}
|
|
31
|
-
|
|
32
|
-
describe('test implementations of MultiBinding', () => {
|
|
33
|
-
describe('test basic functionaly (ClassMultiBinding) ', () => {
|
|
34
|
-
const binding = new MultiBinding('TestClass');
|
|
35
|
-
it('add - new binding', () => {
|
|
36
|
-
binding.add(TestClass1);
|
|
37
|
-
expect(binding.contains(TestClass1)).true;
|
|
38
|
-
|
|
39
|
-
const result = binding.getAll();
|
|
40
|
-
expect(result.length).to.be.equal(1);
|
|
41
|
-
expect(result[0]).to.be.equal(TestClass1);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('add - existing binding', () => {
|
|
45
|
-
binding.add(TestClass1);
|
|
46
|
-
expect(binding.getAll().length).to.be.equal(1);
|
|
47
|
-
expect(binding.getAll()[0]).to.be.equal(TestClass1);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('remove - existing binding', () => {
|
|
51
|
-
expect(binding.contains(TestClass1)).true;
|
|
52
|
-
binding.remove(TestClass1);
|
|
53
|
-
expect(binding.contains(TestClass1)).false;
|
|
54
|
-
expect(binding.getAll()).to.have.length(0);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('remove - non-existing binding', () => {
|
|
58
|
-
const previousSize = binding.getAll().length;
|
|
59
|
-
binding.remove(TestClass2);
|
|
60
|
-
expect(binding.getAll()).to.have.length(previousSize);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('addAll - TestClass1 & TestClass2', () => {
|
|
64
|
-
binding.addAll([TestClass1, TestClass2]);
|
|
65
|
-
|
|
66
|
-
const result = binding.getAll();
|
|
67
|
-
expect(result.length).to.be.equal(2);
|
|
68
|
-
expect(result.includes(TestClass1)).true;
|
|
69
|
-
expect(result.includes(TestClass2)).true;
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('rebind- TestClass2 to TestClass3', () => {
|
|
73
|
-
binding.rebind(TestClass2, TestClass3);
|
|
74
|
-
const result = binding.getAll();
|
|
75
|
-
expect(result.length).to.be.equal(2);
|
|
76
|
-
expect(result.includes(TestClass1)).true;
|
|
77
|
-
expect(result.includes(TestClass3)).true;
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('rebind- TestClass2 to TestClass3- should fail', () => {
|
|
81
|
-
binding.rebind(TestClass2, TestClass3);
|
|
82
|
-
const result = binding.getAll();
|
|
83
|
-
expect(result.length).to.be.equal(2);
|
|
84
|
-
expect(result.includes(TestClass1)).true;
|
|
85
|
-
expect(result.includes(TestClass3)).true;
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('removeAll- TestClass1 & TestClass3', () => {
|
|
89
|
-
binding.removeAll([TestClass1, TestClass3]);
|
|
90
|
-
const result = binding.getAll();
|
|
91
|
-
expect(result).to.have.length(0);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('test applyBinding', () => {
|
|
96
|
-
it('apply binding of ClassMultiBinding', () => {
|
|
97
|
-
const testContainer = new Container();
|
|
98
|
-
const testModule = new ContainerModule((bind, unbind, isBound, rebind) => {
|
|
99
|
-
const context = { bind, unbind, isBound, rebind };
|
|
100
|
-
const binding = new MultiBinding('TestClass');
|
|
101
|
-
binding.addAll([TestClass1, TestClass2, TestClass3]);
|
|
102
|
-
binding.applyBindings(context);
|
|
103
|
-
});
|
|
104
|
-
testContainer.load(testModule);
|
|
105
|
-
const result = testContainer.getAll('TestClass');
|
|
106
|
-
expect(result).to.have.length(3);
|
|
107
|
-
expect(result.find(instance => instance instanceof TestClass1)).to.not.be.undefined;
|
|
108
|
-
expect(result.find(instance => instance instanceof TestClass2)).to.not.be.undefined;
|
|
109
|
-
expect(result.find(instance => instance instanceof TestClass3)).to.not.be.undefined;
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('apply binding of InstanceMultiBinding', () => {
|
|
113
|
-
const t1 = 't1';
|
|
114
|
-
const t2 = 't2';
|
|
115
|
-
const t3 = 't3';
|
|
116
|
-
const identifier = 'myStrings';
|
|
117
|
-
|
|
118
|
-
const testContainer = new Container();
|
|
119
|
-
const testModule = new ContainerModule((bind, unbind, isBound, rebind) => {
|
|
120
|
-
const context = { bind, unbind, isBound, rebind };
|
|
121
|
-
const binding = new InstanceMultiBinding<string>(identifier);
|
|
122
|
-
binding.addAll([t1, t2, t3]);
|
|
123
|
-
binding.applyBindings(context);
|
|
124
|
-
});
|
|
125
|
-
testContainer.load(testModule);
|
|
126
|
-
const result = testContainer.get<string[]>(identifier);
|
|
127
|
-
expect(result).to.have.length(3);
|
|
128
|
-
expect(result.includes(t1)).true;
|
|
129
|
-
expect(result.includes(t2)).true;
|
|
130
|
-
expect(result.includes(t3)).true;
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2026 STMicroelectronics and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
import { GModelElement } from '@eclipse-glsp/graph';
|
|
17
|
-
import { Args, LabeledAction, Point } from '@eclipse-glsp/protocol';
|
|
18
|
-
import { expect } from 'chai';
|
|
19
|
-
import { CommandPaletteActionProvider } from './command-palette-action-provider';
|
|
20
|
-
import { ContextActionsProvider } from './context-actions-provider';
|
|
21
|
-
import { ContextActionsProviderRegistry } from './context-actions-provider-registry';
|
|
22
|
-
import { DefaultToolPaletteItemProvider } from './tool-palette-item-provider';
|
|
23
|
-
|
|
24
|
-
describe('Test DefaultContextActionsProviderRegistry', () => {
|
|
25
|
-
it('check if default registry is empty', () => {
|
|
26
|
-
const contextActionsProvider: ContextActionsProvider[] = [];
|
|
27
|
-
const contextActionsProviderRegistry = new ContextActionsProviderRegistry(contextActionsProvider);
|
|
28
|
-
expect(contextActionsProviderRegistry.keys()).to.have.length(0);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('register DefaultToolPaletteItemProvider via ContextActionsProviders list', () => {
|
|
32
|
-
const contextActionsProvider: ContextActionsProvider[] = [new DefaultToolPaletteItemProvider()];
|
|
33
|
-
const contextActionsProviderRegistry = new ContextActionsProviderRegistry(contextActionsProvider);
|
|
34
|
-
expect(contextActionsProviderRegistry.keys()).to.have.length(1);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('register DefaultToolPaletteItemProvider via ToolPaletteItemProvider', () => {
|
|
38
|
-
const contextActionsProvider: ContextActionsProvider[] = [];
|
|
39
|
-
const contextActionsProviderRegistry = new ContextActionsProviderRegistry(
|
|
40
|
-
contextActionsProvider,
|
|
41
|
-
undefined,
|
|
42
|
-
undefined,
|
|
43
|
-
new DefaultToolPaletteItemProvider()
|
|
44
|
-
);
|
|
45
|
-
expect(contextActionsProviderRegistry.keys()).to.have.length(1);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('register CustomCommandPaletteActionProvider via CommandPaletteActionProvider', () => {
|
|
49
|
-
class CustomCommandPaletteActionProvider extends CommandPaletteActionProvider {
|
|
50
|
-
getPaletteActions(
|
|
51
|
-
_selectedElementIds: string[],
|
|
52
|
-
_selectedElements: GModelElement[],
|
|
53
|
-
_position: Point,
|
|
54
|
-
_args?: Args
|
|
55
|
-
): LabeledAction[] {
|
|
56
|
-
return [];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const contextActionsProvider: ContextActionsProvider[] = [];
|
|
61
|
-
const contextActionsProviderRegistry = new ContextActionsProviderRegistry(
|
|
62
|
-
contextActionsProvider,
|
|
63
|
-
undefined,
|
|
64
|
-
new CustomCommandPaletteActionProvider(),
|
|
65
|
-
undefined
|
|
66
|
-
);
|
|
67
|
-
expect(contextActionsProviderRegistry.keys()).to.have.length(1);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2023 STMicroelectronics and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
import { PaletteItem, RequestContextActions, SetContextActions } from '@eclipse-glsp/protocol';
|
|
17
|
-
import { expect } from 'chai';
|
|
18
|
-
import { OperationHandlerRegistry } from '../../operations/operation-handler-registry';
|
|
19
|
-
import * as mock from '../../test/mock-util';
|
|
20
|
-
import { ContextActionsProvider } from './context-actions-provider';
|
|
21
|
-
import { ContextActionsProviderRegistry } from './context-actions-provider-registry';
|
|
22
|
-
import { RequestContextActionsHandler } from './request-context-actions-handler';
|
|
23
|
-
import { DefaultToolPaletteItemProvider } from './tool-palette-item-provider';
|
|
24
|
-
|
|
25
|
-
describe('Test RequestContextActionsHandler', () => {
|
|
26
|
-
const operationHandlerRegistry = new OperationHandlerRegistry();
|
|
27
|
-
const stubANode = new mock.StubCreateNodeOperationHandler('ANode');
|
|
28
|
-
const stubBNode = new mock.StubCreateNodeOperationHandler('BNode');
|
|
29
|
-
const stubAEdge = new mock.StubCreateEdgeOperationHandler('AEdge');
|
|
30
|
-
const stubBEdge = new mock.StubCreateEdgeOperationHandler('BEdge');
|
|
31
|
-
operationHandlerRegistry.registerHandler(stubBNode);
|
|
32
|
-
operationHandlerRegistry.registerHandler(stubANode);
|
|
33
|
-
operationHandlerRegistry.registerHandler(stubBEdge);
|
|
34
|
-
operationHandlerRegistry.registerHandler(stubAEdge);
|
|
35
|
-
|
|
36
|
-
const contextActionsProvider: ContextActionsProvider[] = [];
|
|
37
|
-
const toolPaletteItemProvider = new DefaultToolPaletteItemProvider();
|
|
38
|
-
toolPaletteItemProvider.operationHandlerRegistry = operationHandlerRegistry;
|
|
39
|
-
|
|
40
|
-
const contextActionsProviderRegistry = new ContextActionsProviderRegistry(
|
|
41
|
-
contextActionsProvider,
|
|
42
|
-
undefined,
|
|
43
|
-
undefined,
|
|
44
|
-
toolPaletteItemProvider
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const requestContextActionsHandler = new RequestContextActionsHandler();
|
|
48
|
-
requestContextActionsHandler['contextActionsProviderRegistry'] = contextActionsProviderRegistry;
|
|
49
|
-
|
|
50
|
-
it('request ToolPaletteContextActions', async () => {
|
|
51
|
-
const actions = await requestContextActionsHandler.execute(
|
|
52
|
-
RequestContextActions.create({ contextId: 'tool-palette', editorContext: { selectedElementIds: [] } })
|
|
53
|
-
);
|
|
54
|
-
expect(actions).to.have.length(1);
|
|
55
|
-
const action = actions[0];
|
|
56
|
-
|
|
57
|
-
expect(SetContextActions.is(action)).to.be.true;
|
|
58
|
-
const setContextActions = action as SetContextActions;
|
|
59
|
-
expect(setContextActions.actions).to.have.length(2);
|
|
60
|
-
|
|
61
|
-
expect(PaletteItem.is(setContextActions.actions[0])).to.be.true;
|
|
62
|
-
const firstPaletteItem = setContextActions.actions[0] as PaletteItem;
|
|
63
|
-
expect(firstPaletteItem.label).to.be.equal('Nodes');
|
|
64
|
-
expect(firstPaletteItem.children).to.have.length(2);
|
|
65
|
-
expect(firstPaletteItem.children?.[0].label).to.be.equal('ANode');
|
|
66
|
-
expect(firstPaletteItem.children?.[1].label).to.be.equal('BNode');
|
|
67
|
-
|
|
68
|
-
expect(PaletteItem.is(setContextActions.actions[1])).to.be.true;
|
|
69
|
-
const secondPaletteItem = setContextActions.actions[1] as PaletteItem;
|
|
70
|
-
expect(secondPaletteItem.label).to.be.equal('Edges');
|
|
71
|
-
expect(secondPaletteItem.children).to.have.length(2);
|
|
72
|
-
expect(secondPaletteItem.children?.[0].label).to.be.equal('AEdge');
|
|
73
|
-
expect(secondPaletteItem.children?.[1].label).to.be.equal('BEdge');
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2023 STMicroelectronics and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
import { OperationHandlerRegistry } from '../../operations/operation-handler-registry';
|
|
17
|
-
import * as mock from '../../test/mock-util';
|
|
18
|
-
import { DefaultToolPaletteItemProvider } from './tool-palette-item-provider';
|
|
19
|
-
import { expect } from 'chai';
|
|
20
|
-
|
|
21
|
-
describe('Test DefaultToolPaletteItemProvider', () => {
|
|
22
|
-
const operationHandlerRegistry = new OperationHandlerRegistry();
|
|
23
|
-
const stubANode = new mock.StubCreateNodeOperationHandler('ANode');
|
|
24
|
-
const stubBNode = new mock.StubCreateNodeOperationHandler('BNode');
|
|
25
|
-
const stubAEdge = new mock.StubCreateEdgeOperationHandler('AEdge');
|
|
26
|
-
const stubBEdge = new mock.StubCreateEdgeOperationHandler('BEdge');
|
|
27
|
-
operationHandlerRegistry.registerHandler(stubBNode);
|
|
28
|
-
operationHandlerRegistry.registerHandler(stubANode);
|
|
29
|
-
operationHandlerRegistry.registerHandler(stubBEdge);
|
|
30
|
-
operationHandlerRegistry.registerHandler(stubAEdge);
|
|
31
|
-
|
|
32
|
-
it('test getItems', () => {
|
|
33
|
-
const toolPaletteItemProvider = new DefaultToolPaletteItemProvider();
|
|
34
|
-
toolPaletteItemProvider.operationHandlerRegistry = operationHandlerRegistry;
|
|
35
|
-
const items = toolPaletteItemProvider.getItems();
|
|
36
|
-
expect(items).to.have.length(2);
|
|
37
|
-
expect(items[0].label).to.be.equal('Nodes');
|
|
38
|
-
expect(items[0].children).to.have.length(2);
|
|
39
|
-
expect(items[0].children?.[0].label).to.be.equal('ANode');
|
|
40
|
-
expect(items[0].children?.[1].label).to.be.equal('BNode');
|
|
41
|
-
expect(items[1].label).to.be.equal('Edges');
|
|
42
|
-
expect(items[1].children).to.have.length(2);
|
|
43
|
-
expect(items[1].children?.[0].label).to.be.equal('AEdge');
|
|
44
|
-
expect(items[1].children?.[1].label).to.be.equal('BEdge');
|
|
45
|
-
});
|
|
46
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2023 STMicroelectronics and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
import { expect } from 'chai';
|
|
17
|
-
import { TestContextEditValidator, TestLabelEditValidator } from '../../test/mock-util';
|
|
18
|
-
import { DefaultModelState } from '../model/model-state';
|
|
19
|
-
import { ContextEditValidator } from './context-edit-validator';
|
|
20
|
-
import { DefaultContextEditValidatorRegistry } from './context-edit-validator-registry';
|
|
21
|
-
|
|
22
|
-
describe('Test DefaultContextEditValidatorRegistry', () => {
|
|
23
|
-
it('check if default registry is empty', () => {
|
|
24
|
-
const contextEditValidators: ContextEditValidator[] = [];
|
|
25
|
-
const contextEditValidatorRegistry = new DefaultContextEditValidatorRegistry(new DefaultModelState(), contextEditValidators);
|
|
26
|
-
expect(contextEditValidatorRegistry.keys()).to.have.length(0);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('register TestContextEditValidator via ContextEditValidators list', () => {
|
|
30
|
-
const contextEditValidators: ContextEditValidator[] = [new TestContextEditValidator()];
|
|
31
|
-
const contextEditValidatorsRegistry = new DefaultContextEditValidatorRegistry(new DefaultModelState(), contextEditValidators);
|
|
32
|
-
expect(contextEditValidatorsRegistry.keys()).to.have.length(1);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('register TestLabelEditValidator via LabelEditValidator', () => {
|
|
36
|
-
const contextEditValidators: ContextEditValidator[] = [];
|
|
37
|
-
const contextEditValidatorsRegistry = new DefaultContextEditValidatorRegistry(
|
|
38
|
-
new DefaultModelState(),
|
|
39
|
-
contextEditValidators,
|
|
40
|
-
new TestLabelEditValidator()
|
|
41
|
-
);
|
|
42
|
-
expect(contextEditValidatorsRegistry.keys()).to.have.length(1);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('register via ContextEditValidators list and LabelEditValidator', () => {
|
|
46
|
-
const contextEditValidators: ContextEditValidator[] = [new TestContextEditValidator()];
|
|
47
|
-
const contextEditValidatorsRegistry = new DefaultContextEditValidatorRegistry(
|
|
48
|
-
new DefaultModelState(),
|
|
49
|
-
contextEditValidators,
|
|
50
|
-
new TestLabelEditValidator()
|
|
51
|
-
);
|
|
52
|
-
expect(contextEditValidatorsRegistry.keys()).to.have.length(2);
|
|
53
|
-
});
|
|
54
|
-
});
|