@theia/variable-resolver 1.48.1 → 1.48.2

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 (41) hide show
  1. package/README.md +114 -114
  2. package/lib/browser/common-variable-contribution.d.ts +16 -16
  3. package/lib/browser/common-variable-contribution.js +161 -161
  4. package/lib/browser/index.d.ts +3 -3
  5. package/lib/browser/index.js +21 -21
  6. package/lib/browser/variable-input-schema.d.ts +2 -2
  7. package/lib/browser/variable-input-schema.js +130 -130
  8. package/lib/browser/variable-input.d.ts +20 -20
  9. package/lib/browser/variable-input.js +2 -2
  10. package/lib/browser/variable-quick-open-service.d.ts +14 -14
  11. package/lib/browser/variable-quick-open-service.js +69 -69
  12. package/lib/browser/variable-resolver-frontend-contribution.d.ts +13 -13
  13. package/lib/browser/variable-resolver-frontend-contribution.js +53 -53
  14. package/lib/browser/variable-resolver-frontend-contribution.spec.d.ts +4 -4
  15. package/lib/browser/variable-resolver-frontend-contribution.spec.js +82 -82
  16. package/lib/browser/variable-resolver-frontend-module.d.ts +3 -3
  17. package/lib/browser/variable-resolver-frontend-module.js +37 -37
  18. package/lib/browser/variable-resolver-service.d.ts +50 -50
  19. package/lib/browser/variable-resolver-service.js +162 -162
  20. package/lib/browser/variable-resolver-service.spec.d.ts +1 -1
  21. package/lib/browser/variable-resolver-service.spec.js +75 -75
  22. package/lib/browser/variable.d.ts +55 -55
  23. package/lib/browser/variable.js +73 -73
  24. package/lib/browser/variable.spec.d.ts +1 -1
  25. package/lib/browser/variable.spec.js +90 -90
  26. package/lib/common/variable-types.d.ts +7 -7
  27. package/lib/common/variable-types.js +17 -17
  28. package/package.json +4 -4
  29. package/src/browser/common-variable-contribution.ts +151 -151
  30. package/src/browser/index.ts +19 -19
  31. package/src/browser/variable-input-schema.ts +131 -131
  32. package/src/browser/variable-input.ts +47 -47
  33. package/src/browser/variable-quick-open-service.ts +62 -62
  34. package/src/browser/variable-resolver-frontend-contribution.spec.ts +98 -98
  35. package/src/browser/variable-resolver-frontend-contribution.ts +50 -50
  36. package/src/browser/variable-resolver-frontend-module.ts +40 -40
  37. package/src/browser/variable-resolver-service.spec.ts +83 -83
  38. package/src/browser/variable-resolver-service.ts +185 -185
  39. package/src/browser/variable.spec.ts +106 -106
  40. package/src/browser/variable.ts +111 -111
  41. package/src/common/variable-types.ts +23 -23
@@ -1,106 +1,106 @@
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, ContainerModule } from '@theia/core/shared/inversify';
19
- import { ILogger, Disposable } from '@theia/core/lib/common';
20
- import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
21
- import { Variable, VariableRegistry } from './variable';
22
-
23
- const expect = chai.expect;
24
- let variableRegistry: VariableRegistry;
25
-
26
- before(() => {
27
- chai.config.showDiff = true;
28
- chai.config.includeStack = true;
29
- });
30
-
31
- describe('variable api', () => {
32
- let testContainer: Container;
33
-
34
- before(() => {
35
- testContainer = new Container();
36
- const module = new ContainerModule((bind, unbind, isBound, rebind) => {
37
- bind(ILogger).to(MockLogger);
38
- bind(VariableRegistry).toSelf();
39
- });
40
- testContainer.load(module);
41
- });
42
-
43
- beforeEach(() => {
44
- variableRegistry = testContainer.get<VariableRegistry>(VariableRegistry);
45
- });
46
-
47
- it('should register and return variable', () => {
48
- registerTestVariable();
49
-
50
- const variable = variableRegistry.getVariable(TEST_VARIABLE.name);
51
- expect(variable).is.not.undefined;
52
- if (variable) {
53
- expect(variable.name).is.equal(TEST_VARIABLE.name);
54
- }
55
- });
56
-
57
- it('should not register a variable for already existed name', () => {
58
- const variables: Variable[] = [
59
- {
60
- name: 'workspaceRoot',
61
- description: 'workspace root URI',
62
- resolve: () => Promise.resolve('')
63
- },
64
- {
65
- name: 'workspaceRoot',
66
- description: 'workspace root URI 2',
67
- resolve: () => Promise.resolve('')
68
- }
69
- ];
70
- variables.forEach(v => variableRegistry.registerVariable(v));
71
-
72
- const registeredVariables = variableRegistry.getVariables();
73
- expect(registeredVariables.length).to.be.equal(1);
74
- expect(registeredVariables[0].name).to.be.equal('workspaceRoot');
75
- expect(registeredVariables[0].description).to.be.equal('workspace root URI');
76
- });
77
-
78
- it('should dispose variable', () => {
79
- const disposable = registerTestVariable();
80
- disposable.dispose();
81
-
82
- const variable = variableRegistry.getVariable(TEST_VARIABLE.name);
83
- expect(variable).is.undefined;
84
- });
85
-
86
- it('should unregister variables on dispose', () => {
87
- registerTestVariable();
88
-
89
- let variables = variableRegistry.getVariables();
90
- expect(variables.length).to.be.equal(1);
91
-
92
- variableRegistry.dispose();
93
-
94
- variables = variableRegistry.getVariables();
95
- expect(variables.length).to.be.equal(0);
96
- });
97
- });
98
-
99
- const TEST_VARIABLE: Variable = {
100
- name: 'workspaceRoot',
101
- resolve: () => Promise.resolve('')
102
- };
103
-
104
- function registerTestVariable(): Disposable {
105
- return variableRegistry.registerVariable(TEST_VARIABLE);
106
- }
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, ContainerModule } from '@theia/core/shared/inversify';
19
+ import { ILogger, Disposable } from '@theia/core/lib/common';
20
+ import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
21
+ import { Variable, VariableRegistry } from './variable';
22
+
23
+ const expect = chai.expect;
24
+ let variableRegistry: VariableRegistry;
25
+
26
+ before(() => {
27
+ chai.config.showDiff = true;
28
+ chai.config.includeStack = true;
29
+ });
30
+
31
+ describe('variable api', () => {
32
+ let testContainer: Container;
33
+
34
+ before(() => {
35
+ testContainer = new Container();
36
+ const module = new ContainerModule((bind, unbind, isBound, rebind) => {
37
+ bind(ILogger).to(MockLogger);
38
+ bind(VariableRegistry).toSelf();
39
+ });
40
+ testContainer.load(module);
41
+ });
42
+
43
+ beforeEach(() => {
44
+ variableRegistry = testContainer.get<VariableRegistry>(VariableRegistry);
45
+ });
46
+
47
+ it('should register and return variable', () => {
48
+ registerTestVariable();
49
+
50
+ const variable = variableRegistry.getVariable(TEST_VARIABLE.name);
51
+ expect(variable).is.not.undefined;
52
+ if (variable) {
53
+ expect(variable.name).is.equal(TEST_VARIABLE.name);
54
+ }
55
+ });
56
+
57
+ it('should not register a variable for already existed name', () => {
58
+ const variables: Variable[] = [
59
+ {
60
+ name: 'workspaceRoot',
61
+ description: 'workspace root URI',
62
+ resolve: () => Promise.resolve('')
63
+ },
64
+ {
65
+ name: 'workspaceRoot',
66
+ description: 'workspace root URI 2',
67
+ resolve: () => Promise.resolve('')
68
+ }
69
+ ];
70
+ variables.forEach(v => variableRegistry.registerVariable(v));
71
+
72
+ const registeredVariables = variableRegistry.getVariables();
73
+ expect(registeredVariables.length).to.be.equal(1);
74
+ expect(registeredVariables[0].name).to.be.equal('workspaceRoot');
75
+ expect(registeredVariables[0].description).to.be.equal('workspace root URI');
76
+ });
77
+
78
+ it('should dispose variable', () => {
79
+ const disposable = registerTestVariable();
80
+ disposable.dispose();
81
+
82
+ const variable = variableRegistry.getVariable(TEST_VARIABLE.name);
83
+ expect(variable).is.undefined;
84
+ });
85
+
86
+ it('should unregister variables on dispose', () => {
87
+ registerTestVariable();
88
+
89
+ let variables = variableRegistry.getVariables();
90
+ expect(variables.length).to.be.equal(1);
91
+
92
+ variableRegistry.dispose();
93
+
94
+ variables = variableRegistry.getVariables();
95
+ expect(variables.length).to.be.equal(0);
96
+ });
97
+ });
98
+
99
+ const TEST_VARIABLE: Variable = {
100
+ name: 'workspaceRoot',
101
+ resolve: () => Promise.resolve('')
102
+ };
103
+
104
+ function registerTestVariable(): Disposable {
105
+ return variableRegistry.registerVariable(TEST_VARIABLE);
106
+ }
@@ -1,111 +1,111 @@
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 } from '@theia/core/shared/inversify';
18
- import { Disposable, DisposableCollection, MaybePromise } from '@theia/core';
19
- import URI from '@theia/core/lib/common/uri';
20
- import { CommandIdVariables } from '../common/variable-types';
21
-
22
- /**
23
- * Variable can be used inside of strings using ${variableName} syntax.
24
- */
25
- export interface Variable {
26
-
27
- /**
28
- * A unique name of this variable.
29
- */
30
- readonly name: string;
31
-
32
- /**
33
- * A human-readable description of this variable.
34
- */
35
- readonly description?: string;
36
-
37
- /**
38
- * Resolve to a string value of this variable or
39
- * `undefined` if variable cannot be resolved.
40
- * Never reject.
41
- */
42
- resolve(
43
- context?: URI,
44
- argument?: string,
45
- configurationSection?: string,
46
- commandIdVariables?: CommandIdVariables,
47
- configuration?: unknown
48
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
- ): MaybePromise<any>;
50
- }
51
-
52
- export const VariableContribution = Symbol('VariableContribution');
53
- /**
54
- * The variable contribution should be implemented to register custom variables.
55
- */
56
- export interface VariableContribution {
57
- registerVariables(variables: VariableRegistry): void;
58
- }
59
-
60
- /**
61
- * The variable registry manages variables.
62
- */
63
- @injectable()
64
- export class VariableRegistry implements Disposable {
65
-
66
- protected readonly variables: Map<string, Variable> = new Map();
67
- protected readonly toDispose = new DisposableCollection();
68
-
69
- dispose(): void {
70
- this.toDispose.dispose();
71
- }
72
-
73
- /**
74
- * Register the given variable.
75
- * Do nothing if a variable is already registered for the given variable name.
76
- */
77
- registerVariable(variable: Variable): Disposable {
78
- if (this.variables.has(variable.name)) {
79
- console.warn(`A variables with name ${variable.name} is already registered.`);
80
- return Disposable.NULL;
81
- }
82
- this.variables.set(variable.name, variable);
83
- const disposable = {
84
- dispose: () => this.variables.delete(variable.name)
85
- };
86
- this.toDispose.push(disposable);
87
- return disposable;
88
- }
89
-
90
- /**
91
- * Return all registered variables.
92
- */
93
- getVariables(): Variable[] {
94
- return [...this.variables.values()];
95
- }
96
-
97
- /**
98
- * Get a variable for the given name or `undefined` if none.
99
- */
100
- getVariable(name: string): Variable | undefined {
101
- return this.variables.get(name);
102
- }
103
-
104
- /**
105
- * Register an array of variables.
106
- * Do nothing if a variable is already registered for the given variable name.
107
- */
108
- registerVariables(variables: Variable[]): Disposable[] {
109
- return variables.map(v => this.registerVariable(v));
110
- }
111
- }
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 } from '@theia/core/shared/inversify';
18
+ import { Disposable, DisposableCollection, MaybePromise } from '@theia/core';
19
+ import URI from '@theia/core/lib/common/uri';
20
+ import { CommandIdVariables } from '../common/variable-types';
21
+
22
+ /**
23
+ * Variable can be used inside of strings using ${variableName} syntax.
24
+ */
25
+ export interface Variable {
26
+
27
+ /**
28
+ * A unique name of this variable.
29
+ */
30
+ readonly name: string;
31
+
32
+ /**
33
+ * A human-readable description of this variable.
34
+ */
35
+ readonly description?: string;
36
+
37
+ /**
38
+ * Resolve to a string value of this variable or
39
+ * `undefined` if variable cannot be resolved.
40
+ * Never reject.
41
+ */
42
+ resolve(
43
+ context?: URI,
44
+ argument?: string,
45
+ configurationSection?: string,
46
+ commandIdVariables?: CommandIdVariables,
47
+ configuration?: unknown
48
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
+ ): MaybePromise<any>;
50
+ }
51
+
52
+ export const VariableContribution = Symbol('VariableContribution');
53
+ /**
54
+ * The variable contribution should be implemented to register custom variables.
55
+ */
56
+ export interface VariableContribution {
57
+ registerVariables(variables: VariableRegistry): void;
58
+ }
59
+
60
+ /**
61
+ * The variable registry manages variables.
62
+ */
63
+ @injectable()
64
+ export class VariableRegistry implements Disposable {
65
+
66
+ protected readonly variables: Map<string, Variable> = new Map();
67
+ protected readonly toDispose = new DisposableCollection();
68
+
69
+ dispose(): void {
70
+ this.toDispose.dispose();
71
+ }
72
+
73
+ /**
74
+ * Register the given variable.
75
+ * Do nothing if a variable is already registered for the given variable name.
76
+ */
77
+ registerVariable(variable: Variable): Disposable {
78
+ if (this.variables.has(variable.name)) {
79
+ console.warn(`A variables with name ${variable.name} is already registered.`);
80
+ return Disposable.NULL;
81
+ }
82
+ this.variables.set(variable.name, variable);
83
+ const disposable = {
84
+ dispose: () => this.variables.delete(variable.name)
85
+ };
86
+ this.toDispose.push(disposable);
87
+ return disposable;
88
+ }
89
+
90
+ /**
91
+ * Return all registered variables.
92
+ */
93
+ getVariables(): Variable[] {
94
+ return [...this.variables.values()];
95
+ }
96
+
97
+ /**
98
+ * Get a variable for the given name or `undefined` if none.
99
+ */
100
+ getVariable(name: string): Variable | undefined {
101
+ return this.variables.get(name);
102
+ }
103
+
104
+ /**
105
+ * Register an array of variables.
106
+ * Do nothing if a variable is already registered for the given variable name.
107
+ */
108
+ registerVariables(variables: Variable[]): Disposable[] {
109
+ return variables.map(v => this.registerVariable(v));
110
+ }
111
+ }
@@ -1,23 +1,23 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2022 Ericsson 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
- /**
18
- * Holds variable-names to command id mappings (e.g. Provided by specific plugins / extensions)
19
- * see "variables": https://code.visualstudio.com/api/references/contribution-points#contributes.debuggers
20
- */
21
- export interface CommandIdVariables {
22
- [id: string]: string
23
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 Ericsson 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
+ /**
18
+ * Holds variable-names to command id mappings (e.g. Provided by specific plugins / extensions)
19
+ * see "variables": https://code.visualstudio.com/api/references/contribution-points#contributes.debuggers
20
+ */
21
+ export interface CommandIdVariables {
22
+ [id: string]: string
23
+ }