@theia/variable-resolver 1.53.0-next.55 → 1.53.0-next.64
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/README.md +114 -114
- package/package.json +3 -3
- package/src/browser/common-variable-contribution.ts +151 -151
- package/src/browser/index.ts +19 -19
- package/src/browser/variable-input-schema.ts +131 -131
- package/src/browser/variable-input.ts +47 -47
- package/src/browser/variable-quick-open-service.ts +62 -62
- package/src/browser/variable-resolver-frontend-contribution.spec.ts +98 -98
- package/src/browser/variable-resolver-frontend-contribution.ts +50 -50
- package/src/browser/variable-resolver-frontend-module.ts +40 -40
- package/src/browser/variable-resolver-service.spec.ts +83 -83
- package/src/browser/variable-resolver-service.ts +185 -185
- package/src/browser/variable.spec.ts +106 -106
- package/src/browser/variable.ts +111 -111
- package/src/common/variable-types.ts +23 -23
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 Red Hat, Inc. 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-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
|
|
18
|
-
|
|
19
|
-
let disableJSDOM = enableJSDOM();
|
|
20
|
-
|
|
21
|
-
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
|
|
22
|
-
FrontendApplicationConfigProvider.set({});
|
|
23
|
-
|
|
24
|
-
import * as chai from 'chai';
|
|
25
|
-
import { Container, ContainerModule } from '@theia/core/shared/inversify';
|
|
26
|
-
import { ILogger, bindContributionProvider } from '@theia/core/lib/common';
|
|
27
|
-
import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
|
|
28
|
-
import { VariableContribution, VariableRegistry } from './variable';
|
|
29
|
-
import { VariableQuickOpenService } from './variable-quick-open-service';
|
|
30
|
-
import { VariableResolverFrontendContribution } from './variable-resolver-frontend-contribution';
|
|
31
|
-
|
|
32
|
-
disableJSDOM();
|
|
33
|
-
|
|
34
|
-
const expect = chai.expect;
|
|
35
|
-
|
|
36
|
-
before(() => {
|
|
37
|
-
chai.config.showDiff = true;
|
|
38
|
-
chai.config.includeStack = true;
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('variable-resolver-frontend-contribution', () => {
|
|
42
|
-
|
|
43
|
-
let testContainer: Container;
|
|
44
|
-
let variableRegistry: VariableRegistry;
|
|
45
|
-
|
|
46
|
-
before(() => {
|
|
47
|
-
disableJSDOM = enableJSDOM();
|
|
48
|
-
|
|
49
|
-
testContainer = new Container();
|
|
50
|
-
const module = new ContainerModule((bind, unbind, isBound, rebind) => {
|
|
51
|
-
bindContributionProvider(bind, VariableContribution);
|
|
52
|
-
bind(VariableContribution).toConstantValue(new TestVariableContribution());
|
|
53
|
-
|
|
54
|
-
bind(ILogger).to(MockLogger);
|
|
55
|
-
bind(VariableRegistry).toSelf().inSingletonScope();
|
|
56
|
-
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
-
bind(VariableQuickOpenService).toConstantValue({} as any); // mock VariableQuickOpenService
|
|
59
|
-
|
|
60
|
-
bind(VariableResolverFrontendContribution).toSelf();
|
|
61
|
-
});
|
|
62
|
-
testContainer.load(module);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
after(() => {
|
|
66
|
-
disableJSDOM();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
beforeEach(() => {
|
|
70
|
-
variableRegistry = testContainer.get<VariableRegistry>(VariableRegistry);
|
|
71
|
-
|
|
72
|
-
const variableRegistrar = testContainer.get(VariableResolverFrontendContribution);
|
|
73
|
-
variableRegistrar.onStart();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should register all variables from the contribution points', () => {
|
|
77
|
-
const variables = variableRegistry.getVariables();
|
|
78
|
-
expect(variables.length).to.be.equal(2);
|
|
79
|
-
expect(variables[0].name).to.be.equal('file');
|
|
80
|
-
expect(variables[1].name).to.be.equal('lineNumber');
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
export class TestVariableContribution implements VariableContribution {
|
|
85
|
-
|
|
86
|
-
registerVariables(variables: VariableRegistry): void {
|
|
87
|
-
variables.registerVariable({
|
|
88
|
-
name: 'file',
|
|
89
|
-
description: 'Resolves to file name opened in the current editor',
|
|
90
|
-
resolve: () => Promise.resolve('package.json')
|
|
91
|
-
});
|
|
92
|
-
variables.registerVariable({
|
|
93
|
-
name: 'lineNumber',
|
|
94
|
-
description: 'Resolves to current line number',
|
|
95
|
-
resolve: () => Promise.resolve('5')
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 Red Hat, Inc. 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-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
|
|
18
|
+
|
|
19
|
+
let disableJSDOM = enableJSDOM();
|
|
20
|
+
|
|
21
|
+
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
|
|
22
|
+
FrontendApplicationConfigProvider.set({});
|
|
23
|
+
|
|
24
|
+
import * as chai from 'chai';
|
|
25
|
+
import { Container, ContainerModule } from '@theia/core/shared/inversify';
|
|
26
|
+
import { ILogger, bindContributionProvider } from '@theia/core/lib/common';
|
|
27
|
+
import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
|
|
28
|
+
import { VariableContribution, VariableRegistry } from './variable';
|
|
29
|
+
import { VariableQuickOpenService } from './variable-quick-open-service';
|
|
30
|
+
import { VariableResolverFrontendContribution } from './variable-resolver-frontend-contribution';
|
|
31
|
+
|
|
32
|
+
disableJSDOM();
|
|
33
|
+
|
|
34
|
+
const expect = chai.expect;
|
|
35
|
+
|
|
36
|
+
before(() => {
|
|
37
|
+
chai.config.showDiff = true;
|
|
38
|
+
chai.config.includeStack = true;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('variable-resolver-frontend-contribution', () => {
|
|
42
|
+
|
|
43
|
+
let testContainer: Container;
|
|
44
|
+
let variableRegistry: VariableRegistry;
|
|
45
|
+
|
|
46
|
+
before(() => {
|
|
47
|
+
disableJSDOM = enableJSDOM();
|
|
48
|
+
|
|
49
|
+
testContainer = new Container();
|
|
50
|
+
const module = new ContainerModule((bind, unbind, isBound, rebind) => {
|
|
51
|
+
bindContributionProvider(bind, VariableContribution);
|
|
52
|
+
bind(VariableContribution).toConstantValue(new TestVariableContribution());
|
|
53
|
+
|
|
54
|
+
bind(ILogger).to(MockLogger);
|
|
55
|
+
bind(VariableRegistry).toSelf().inSingletonScope();
|
|
56
|
+
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
+
bind(VariableQuickOpenService).toConstantValue({} as any); // mock VariableQuickOpenService
|
|
59
|
+
|
|
60
|
+
bind(VariableResolverFrontendContribution).toSelf();
|
|
61
|
+
});
|
|
62
|
+
testContainer.load(module);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
after(() => {
|
|
66
|
+
disableJSDOM();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
beforeEach(() => {
|
|
70
|
+
variableRegistry = testContainer.get<VariableRegistry>(VariableRegistry);
|
|
71
|
+
|
|
72
|
+
const variableRegistrar = testContainer.get(VariableResolverFrontendContribution);
|
|
73
|
+
variableRegistrar.onStart();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should register all variables from the contribution points', () => {
|
|
77
|
+
const variables = variableRegistry.getVariables();
|
|
78
|
+
expect(variables.length).to.be.equal(2);
|
|
79
|
+
expect(variables[0].name).to.be.equal('file');
|
|
80
|
+
expect(variables[1].name).to.be.equal('lineNumber');
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
export class TestVariableContribution implements VariableContribution {
|
|
85
|
+
|
|
86
|
+
registerVariables(variables: VariableRegistry): void {
|
|
87
|
+
variables.registerVariable({
|
|
88
|
+
name: 'file',
|
|
89
|
+
description: 'Resolves to file name opened in the current editor',
|
|
90
|
+
resolve: () => Promise.resolve('package.json')
|
|
91
|
+
});
|
|
92
|
+
variables.registerVariable({
|
|
93
|
+
name: 'lineNumber',
|
|
94
|
+
description: 'Resolves to current line number',
|
|
95
|
+
resolve: () => Promise.resolve('5')
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 Red Hat, Inc. 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-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { injectable, inject, named } from '@theia/core/shared/inversify';
|
|
18
|
-
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
|
19
|
-
import { Command, CommandContribution, CommandRegistry, ContributionProvider } from '@theia/core/lib/common';
|
|
20
|
-
import { VariableContribution, VariableRegistry } from './variable';
|
|
21
|
-
import { VariableQuickOpenService } from './variable-quick-open-service';
|
|
22
|
-
|
|
23
|
-
export const LIST_VARIABLES: Command = {
|
|
24
|
-
id: 'variable.list',
|
|
25
|
-
label: 'Variable: List All'
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
@injectable()
|
|
29
|
-
export class VariableResolverFrontendContribution implements FrontendApplicationContribution, CommandContribution {
|
|
30
|
-
|
|
31
|
-
constructor(
|
|
32
|
-
@inject(ContributionProvider) @named(VariableContribution)
|
|
33
|
-
protected readonly contributionProvider: ContributionProvider<VariableContribution>,
|
|
34
|
-
@inject(VariableRegistry) protected readonly variableRegistry: VariableRegistry,
|
|
35
|
-
@inject(VariableQuickOpenService) protected readonly variableQuickOpenService: VariableQuickOpenService
|
|
36
|
-
) { }
|
|
37
|
-
|
|
38
|
-
onStart(): void {
|
|
39
|
-
this.contributionProvider.getContributions().forEach(contrib =>
|
|
40
|
-
contrib.registerVariables(this.variableRegistry)
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
registerCommands(commands: CommandRegistry): void {
|
|
45
|
-
commands.registerCommand(LIST_VARIABLES, {
|
|
46
|
-
isEnabled: () => true,
|
|
47
|
-
execute: () => this.variableQuickOpenService.open()
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 Red Hat, Inc. 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-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { injectable, inject, named } from '@theia/core/shared/inversify';
|
|
18
|
+
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
|
19
|
+
import { Command, CommandContribution, CommandRegistry, ContributionProvider } from '@theia/core/lib/common';
|
|
20
|
+
import { VariableContribution, VariableRegistry } from './variable';
|
|
21
|
+
import { VariableQuickOpenService } from './variable-quick-open-service';
|
|
22
|
+
|
|
23
|
+
export const LIST_VARIABLES: Command = {
|
|
24
|
+
id: 'variable.list',
|
|
25
|
+
label: 'Variable: List All'
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
@injectable()
|
|
29
|
+
export class VariableResolverFrontendContribution implements FrontendApplicationContribution, CommandContribution {
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
@inject(ContributionProvider) @named(VariableContribution)
|
|
33
|
+
protected readonly contributionProvider: ContributionProvider<VariableContribution>,
|
|
34
|
+
@inject(VariableRegistry) protected readonly variableRegistry: VariableRegistry,
|
|
35
|
+
@inject(VariableQuickOpenService) protected readonly variableQuickOpenService: VariableQuickOpenService
|
|
36
|
+
) { }
|
|
37
|
+
|
|
38
|
+
onStart(): void {
|
|
39
|
+
this.contributionProvider.getContributions().forEach(contrib =>
|
|
40
|
+
contrib.registerVariables(this.variableRegistry)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
registerCommands(commands: CommandRegistry): void {
|
|
45
|
+
commands.registerCommand(LIST_VARIABLES, {
|
|
46
|
+
isEnabled: () => true,
|
|
47
|
+
execute: () => this.variableQuickOpenService.open()
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 Red Hat, Inc. 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-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
18
|
-
import { bindContributionProvider, CommandContribution } from '@theia/core';
|
|
19
|
-
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
|
20
|
-
import { VariableRegistry, VariableContribution } from './variable';
|
|
21
|
-
import { VariableQuickOpenService } from './variable-quick-open-service';
|
|
22
|
-
import { VariableResolverFrontendContribution } from './variable-resolver-frontend-contribution';
|
|
23
|
-
import { VariableResolverService } from './variable-resolver-service';
|
|
24
|
-
import { CommonVariableContribution } from './common-variable-contribution';
|
|
25
|
-
|
|
26
|
-
export default new ContainerModule(bind => {
|
|
27
|
-
bind(VariableRegistry).toSelf().inSingletonScope();
|
|
28
|
-
bind(VariableResolverService).toSelf().inSingletonScope();
|
|
29
|
-
bindContributionProvider(bind, VariableContribution);
|
|
30
|
-
|
|
31
|
-
bind(VariableResolverFrontendContribution).toSelf().inSingletonScope();
|
|
32
|
-
for (const identifier of [FrontendApplicationContribution, CommandContribution]) {
|
|
33
|
-
bind(identifier).toService(VariableResolverFrontendContribution);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
bind(VariableQuickOpenService).toSelf().inSingletonScope();
|
|
37
|
-
|
|
38
|
-
bind(CommonVariableContribution).toSelf().inSingletonScope();
|
|
39
|
-
bind(VariableContribution).toService(CommonVariableContribution);
|
|
40
|
-
});
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 Red Hat, Inc. 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-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
18
|
+
import { bindContributionProvider, CommandContribution } from '@theia/core';
|
|
19
|
+
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
|
20
|
+
import { VariableRegistry, VariableContribution } from './variable';
|
|
21
|
+
import { VariableQuickOpenService } from './variable-quick-open-service';
|
|
22
|
+
import { VariableResolverFrontendContribution } from './variable-resolver-frontend-contribution';
|
|
23
|
+
import { VariableResolverService } from './variable-resolver-service';
|
|
24
|
+
import { CommonVariableContribution } from './common-variable-contribution';
|
|
25
|
+
|
|
26
|
+
export default new ContainerModule(bind => {
|
|
27
|
+
bind(VariableRegistry).toSelf().inSingletonScope();
|
|
28
|
+
bind(VariableResolverService).toSelf().inSingletonScope();
|
|
29
|
+
bindContributionProvider(bind, VariableContribution);
|
|
30
|
+
|
|
31
|
+
bind(VariableResolverFrontendContribution).toSelf().inSingletonScope();
|
|
32
|
+
for (const identifier of [FrontendApplicationContribution, CommandContribution]) {
|
|
33
|
+
bind(identifier).toService(VariableResolverFrontendContribution);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
bind(VariableQuickOpenService).toSelf().inSingletonScope();
|
|
37
|
+
|
|
38
|
+
bind(CommonVariableContribution).toSelf().inSingletonScope();
|
|
39
|
+
bind(VariableContribution).toService(CommonVariableContribution);
|
|
40
|
+
});
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 Red Hat, Inc. 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-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import * as chai from 'chai';
|
|
18
|
-
import { Container } from '@theia/core/shared/inversify';
|
|
19
|
-
import { cancelled } from '@theia/core/lib/common';
|
|
20
|
-
import { VariableRegistry } from './variable';
|
|
21
|
-
import { VariableResolverService } from './variable-resolver-service';
|
|
22
|
-
|
|
23
|
-
const expect = chai.expect;
|
|
24
|
-
|
|
25
|
-
before(() => {
|
|
26
|
-
chai.config.showDiff = true;
|
|
27
|
-
chai.config.includeStack = true;
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('variable-resolver-service', () => {
|
|
31
|
-
|
|
32
|
-
let testContainer: Container;
|
|
33
|
-
let variableRegistry: VariableRegistry;
|
|
34
|
-
let variableResolverService: VariableResolverService;
|
|
35
|
-
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
testContainer = new Container();
|
|
38
|
-
testContainer.bind(VariableRegistry).toSelf().inSingletonScope();
|
|
39
|
-
testContainer.bind(VariableResolverService).toSelf().inSingletonScope();
|
|
40
|
-
variableRegistry = testContainer.get(VariableRegistry);
|
|
41
|
-
variableRegistry.registerVariable({
|
|
42
|
-
name: 'file',
|
|
43
|
-
description: 'current file',
|
|
44
|
-
resolve: () => Promise.resolve('package.json')
|
|
45
|
-
});
|
|
46
|
-
variableRegistry.registerVariable({
|
|
47
|
-
name: 'lineNumber',
|
|
48
|
-
description: 'current line number',
|
|
49
|
-
resolve: () => Promise.resolve('6')
|
|
50
|
-
});
|
|
51
|
-
variableResolverService = testContainer.get(VariableResolverService);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should resolve known variables in a text', async () => {
|
|
55
|
-
const resolved = await variableResolverService.resolve('file: ${file}; line: ${lineNumber}');
|
|
56
|
-
expect(resolved).is.equal('file: package.json; line: 6');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should resolve known variables in a string array', async () => {
|
|
60
|
-
const resolved = await variableResolverService.resolveArray(['file: ${file}', 'line: ${lineNumber}']);
|
|
61
|
-
expect(resolved!.length).to.be.equal(2);
|
|
62
|
-
expect(resolved).to.contain('file: package.json');
|
|
63
|
-
expect(resolved).to.contain('line: 6');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should skip unknown variables', async () => {
|
|
67
|
-
const resolved = await variableResolverService.resolve('workspace: ${workspaceRoot}; file: ${file}; line: ${lineNumber}');
|
|
68
|
-
expect(resolved).is.equal('workspace: ${workspaceRoot}; file: package.json; line: 6');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should return undefined when a variable throws with `cancelled()` while resolving', async () => {
|
|
72
|
-
variableRegistry.registerVariable({
|
|
73
|
-
name: 'command',
|
|
74
|
-
resolve: (contextUri, commandId) => {
|
|
75
|
-
if (commandId === 'testCommand') {
|
|
76
|
-
throw cancelled();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
const resolved = await variableResolverService.resolve('workspace: ${command:testCommand}; file: ${file}; line: ${lineNumber}');
|
|
81
|
-
expect(resolved).equal(undefined);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 Red Hat, Inc. 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-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import * as chai from 'chai';
|
|
18
|
+
import { Container } from '@theia/core/shared/inversify';
|
|
19
|
+
import { cancelled } from '@theia/core/lib/common';
|
|
20
|
+
import { VariableRegistry } from './variable';
|
|
21
|
+
import { VariableResolverService } from './variable-resolver-service';
|
|
22
|
+
|
|
23
|
+
const expect = chai.expect;
|
|
24
|
+
|
|
25
|
+
before(() => {
|
|
26
|
+
chai.config.showDiff = true;
|
|
27
|
+
chai.config.includeStack = true;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('variable-resolver-service', () => {
|
|
31
|
+
|
|
32
|
+
let testContainer: Container;
|
|
33
|
+
let variableRegistry: VariableRegistry;
|
|
34
|
+
let variableResolverService: VariableResolverService;
|
|
35
|
+
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
testContainer = new Container();
|
|
38
|
+
testContainer.bind(VariableRegistry).toSelf().inSingletonScope();
|
|
39
|
+
testContainer.bind(VariableResolverService).toSelf().inSingletonScope();
|
|
40
|
+
variableRegistry = testContainer.get(VariableRegistry);
|
|
41
|
+
variableRegistry.registerVariable({
|
|
42
|
+
name: 'file',
|
|
43
|
+
description: 'current file',
|
|
44
|
+
resolve: () => Promise.resolve('package.json')
|
|
45
|
+
});
|
|
46
|
+
variableRegistry.registerVariable({
|
|
47
|
+
name: 'lineNumber',
|
|
48
|
+
description: 'current line number',
|
|
49
|
+
resolve: () => Promise.resolve('6')
|
|
50
|
+
});
|
|
51
|
+
variableResolverService = testContainer.get(VariableResolverService);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should resolve known variables in a text', async () => {
|
|
55
|
+
const resolved = await variableResolverService.resolve('file: ${file}; line: ${lineNumber}');
|
|
56
|
+
expect(resolved).is.equal('file: package.json; line: 6');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should resolve known variables in a string array', async () => {
|
|
60
|
+
const resolved = await variableResolverService.resolveArray(['file: ${file}', 'line: ${lineNumber}']);
|
|
61
|
+
expect(resolved!.length).to.be.equal(2);
|
|
62
|
+
expect(resolved).to.contain('file: package.json');
|
|
63
|
+
expect(resolved).to.contain('line: 6');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should skip unknown variables', async () => {
|
|
67
|
+
const resolved = await variableResolverService.resolve('workspace: ${workspaceRoot}; file: ${file}; line: ${lineNumber}');
|
|
68
|
+
expect(resolved).is.equal('workspace: ${workspaceRoot}; file: package.json; line: 6');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should return undefined when a variable throws with `cancelled()` while resolving', async () => {
|
|
72
|
+
variableRegistry.registerVariable({
|
|
73
|
+
name: 'command',
|
|
74
|
+
resolve: (contextUri, commandId) => {
|
|
75
|
+
if (commandId === 'testCommand') {
|
|
76
|
+
throw cancelled();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const resolved = await variableResolverService.resolve('workspace: ${command:testCommand}; file: ${file}; line: ${lineNumber}');
|
|
81
|
+
expect(resolved).equal(undefined);
|
|
82
|
+
});
|
|
83
|
+
});
|