@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.
- package/README.md +114 -114
- package/lib/browser/common-variable-contribution.d.ts +16 -16
- package/lib/browser/common-variable-contribution.js +161 -161
- package/lib/browser/index.d.ts +3 -3
- package/lib/browser/index.js +21 -21
- package/lib/browser/variable-input-schema.d.ts +2 -2
- package/lib/browser/variable-input-schema.js +130 -130
- package/lib/browser/variable-input.d.ts +20 -20
- package/lib/browser/variable-input.js +2 -2
- package/lib/browser/variable-quick-open-service.d.ts +14 -14
- package/lib/browser/variable-quick-open-service.js +69 -69
- package/lib/browser/variable-resolver-frontend-contribution.d.ts +13 -13
- package/lib/browser/variable-resolver-frontend-contribution.js +53 -53
- package/lib/browser/variable-resolver-frontend-contribution.spec.d.ts +4 -4
- package/lib/browser/variable-resolver-frontend-contribution.spec.js +82 -82
- package/lib/browser/variable-resolver-frontend-module.d.ts +3 -3
- package/lib/browser/variable-resolver-frontend-module.js +37 -37
- package/lib/browser/variable-resolver-service.d.ts +50 -50
- package/lib/browser/variable-resolver-service.js +162 -162
- package/lib/browser/variable-resolver-service.spec.d.ts +1 -1
- package/lib/browser/variable-resolver-service.spec.js +75 -75
- package/lib/browser/variable.d.ts +55 -55
- package/lib/browser/variable.js +73 -73
- package/lib/browser/variable.spec.d.ts +1 -1
- package/lib/browser/variable.spec.js +90 -90
- package/lib/common/variable-types.d.ts +7 -7
- package/lib/common/variable-types.js +17 -17
- package/package.json +4 -4
- 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,163 +1,163 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2018 Red Hat, Inc. and others.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
var VariableResolverService_1;
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.VariableResolverService = void 0;
|
|
20
|
-
const tslib_1 = require("tslib");
|
|
21
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
22
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
23
|
-
const variable_1 = require("./variable");
|
|
24
|
-
const core_1 = require("@theia/core");
|
|
25
|
-
/**
|
|
26
|
-
* The variable resolver service should be used to resolve variables in strings.
|
|
27
|
-
*/
|
|
28
|
-
let VariableResolverService = VariableResolverService_1 = class VariableResolverService {
|
|
29
|
-
/**
|
|
30
|
-
* Resolve the variables in the given string array.
|
|
31
|
-
* @param value The array of data to resolve variables in.
|
|
32
|
-
* @param options Options of the variable resolution.
|
|
33
|
-
* @returns Promise to array with variables resolved. Never rejects.
|
|
34
|
-
*
|
|
35
|
-
* @deprecated since 1.28.0 use {@link resolve} instead.
|
|
36
|
-
*/
|
|
37
|
-
resolveArray(value, options = {}) {
|
|
38
|
-
return this.resolve(value, options);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Resolve the variables for all strings found in the object and nested objects.
|
|
42
|
-
* @param value Data to resolve variables in.
|
|
43
|
-
* @param options Options of the variable resolution
|
|
44
|
-
* @returns Promise to object with variables resolved. Returns `undefined` if a variable resolution was cancelled.
|
|
45
|
-
*/
|
|
46
|
-
async resolve(value, options = {}) {
|
|
47
|
-
const context = new VariableResolverService_1.Context(this.variableRegistry, options);
|
|
48
|
-
try {
|
|
49
|
-
return await this.doResolve(value, context);
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
if ((0, core_1.isCancelled)(error)) {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async doResolve(value, context) {
|
|
59
|
-
// eslint-disable-next-line no-null/no-null
|
|
60
|
-
if (value === undefined || value === null) {
|
|
61
|
-
return value;
|
|
62
|
-
}
|
|
63
|
-
if (typeof value === 'string') {
|
|
64
|
-
return this.doResolveString(value, context);
|
|
65
|
-
}
|
|
66
|
-
if (Array.isArray(value)) {
|
|
67
|
-
return this.doResolveArray(value, context);
|
|
68
|
-
}
|
|
69
|
-
if (typeof value === 'object') {
|
|
70
|
-
return this.doResolveObject(value, context);
|
|
71
|
-
}
|
|
72
|
-
return value;
|
|
73
|
-
}
|
|
74
|
-
async doResolveObject(obj, context) {
|
|
75
|
-
const result = {};
|
|
76
|
-
for (const name of Object.keys(obj)) {
|
|
77
|
-
const value = obj[name];
|
|
78
|
-
const resolved = await this.doResolve(value, context);
|
|
79
|
-
result[name] = resolved;
|
|
80
|
-
}
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
async doResolveArray(values, context) {
|
|
84
|
-
const result = [];
|
|
85
|
-
for (const value of values) {
|
|
86
|
-
const resolved = await this.doResolve(value, context);
|
|
87
|
-
result.push(resolved);
|
|
88
|
-
}
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
async doResolveString(value, context) {
|
|
92
|
-
await this.resolveVariables(value, context);
|
|
93
|
-
return value.replace(VariableResolverService_1.VAR_REGEXP, (match, varName) => {
|
|
94
|
-
const varValue = context.get(varName);
|
|
95
|
-
return varValue !== undefined ? varValue : match;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
async resolveVariables(value, context) {
|
|
99
|
-
const variableRegExp = new RegExp(VariableResolverService_1.VAR_REGEXP);
|
|
100
|
-
let match;
|
|
101
|
-
// eslint-disable-next-line no-null/no-null
|
|
102
|
-
while ((match = variableRegExp.exec(value)) !== null) {
|
|
103
|
-
const variableName = match[1];
|
|
104
|
-
await context.resolve(variableName);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
VariableResolverService.VAR_REGEXP = /\$\{(.*?)\}/g;
|
|
109
|
-
(0, tslib_1.__decorate)([
|
|
110
|
-
(0, inversify_1.inject)(variable_1.VariableRegistry),
|
|
111
|
-
(0, tslib_1.__metadata)("design:type", variable_1.VariableRegistry)
|
|
112
|
-
], VariableResolverService.prototype, "variableRegistry", void 0);
|
|
113
|
-
VariableResolverService = VariableResolverService_1 = (0, tslib_1.__decorate)([
|
|
114
|
-
(0, inversify_1.injectable)()
|
|
115
|
-
], VariableResolverService);
|
|
116
|
-
exports.VariableResolverService = VariableResolverService;
|
|
117
|
-
(function (VariableResolverService) {
|
|
118
|
-
class Context {
|
|
119
|
-
constructor(variableRegistry, options) {
|
|
120
|
-
this.variableRegistry = variableRegistry;
|
|
121
|
-
this.options = options;
|
|
122
|
-
this.resolved = new Map();
|
|
123
|
-
}
|
|
124
|
-
get(name) {
|
|
125
|
-
return this.resolved.get(name);
|
|
126
|
-
}
|
|
127
|
-
async resolve(name) {
|
|
128
|
-
if (this.resolved.has(name)) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
try {
|
|
132
|
-
let variableName = name;
|
|
133
|
-
let argument;
|
|
134
|
-
const parts = name.split(':', 2);
|
|
135
|
-
if (parts.length > 1) {
|
|
136
|
-
variableName = parts[0];
|
|
137
|
-
argument = parts[1];
|
|
138
|
-
}
|
|
139
|
-
const variable = this.variableRegistry.getVariable(variableName);
|
|
140
|
-
const resolved = await (variable === null || variable === void 0 ? void 0 : variable.resolve(this.options.context, argument, this.options.configurationSection, this.options.commandIdVariables, this.options.configuration));
|
|
141
|
-
if (typeof resolved === 'bigint' ||
|
|
142
|
-
typeof resolved === 'boolean' ||
|
|
143
|
-
typeof resolved === 'number' ||
|
|
144
|
-
typeof resolved === 'string') {
|
|
145
|
-
this.resolved.set(name, `${resolved}`);
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
this.resolved.set(name, undefined);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
catch (e) {
|
|
152
|
-
if ((0, core_1.isCancelled)(e)) {
|
|
153
|
-
throw e;
|
|
154
|
-
}
|
|
155
|
-
this.resolved.set(name, undefined);
|
|
156
|
-
console.error(`Failed to resolve '${name}' variable:`, e);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
VariableResolverService.Context = Context;
|
|
161
|
-
})(VariableResolverService = exports.VariableResolverService || (exports.VariableResolverService = {}));
|
|
162
|
-
exports.VariableResolverService = VariableResolverService;
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2018 Red Hat, Inc. and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
var VariableResolverService_1;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.VariableResolverService = void 0;
|
|
20
|
+
const tslib_1 = require("tslib");
|
|
21
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
22
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
23
|
+
const variable_1 = require("./variable");
|
|
24
|
+
const core_1 = require("@theia/core");
|
|
25
|
+
/**
|
|
26
|
+
* The variable resolver service should be used to resolve variables in strings.
|
|
27
|
+
*/
|
|
28
|
+
let VariableResolverService = VariableResolverService_1 = class VariableResolverService {
|
|
29
|
+
/**
|
|
30
|
+
* Resolve the variables in the given string array.
|
|
31
|
+
* @param value The array of data to resolve variables in.
|
|
32
|
+
* @param options Options of the variable resolution.
|
|
33
|
+
* @returns Promise to array with variables resolved. Never rejects.
|
|
34
|
+
*
|
|
35
|
+
* @deprecated since 1.28.0 use {@link resolve} instead.
|
|
36
|
+
*/
|
|
37
|
+
resolveArray(value, options = {}) {
|
|
38
|
+
return this.resolve(value, options);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Resolve the variables for all strings found in the object and nested objects.
|
|
42
|
+
* @param value Data to resolve variables in.
|
|
43
|
+
* @param options Options of the variable resolution
|
|
44
|
+
* @returns Promise to object with variables resolved. Returns `undefined` if a variable resolution was cancelled.
|
|
45
|
+
*/
|
|
46
|
+
async resolve(value, options = {}) {
|
|
47
|
+
const context = new VariableResolverService_1.Context(this.variableRegistry, options);
|
|
48
|
+
try {
|
|
49
|
+
return await this.doResolve(value, context);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if ((0, core_1.isCancelled)(error)) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async doResolve(value, context) {
|
|
59
|
+
// eslint-disable-next-line no-null/no-null
|
|
60
|
+
if (value === undefined || value === null) {
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
if (typeof value === 'string') {
|
|
64
|
+
return this.doResolveString(value, context);
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(value)) {
|
|
67
|
+
return this.doResolveArray(value, context);
|
|
68
|
+
}
|
|
69
|
+
if (typeof value === 'object') {
|
|
70
|
+
return this.doResolveObject(value, context);
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
async doResolveObject(obj, context) {
|
|
75
|
+
const result = {};
|
|
76
|
+
for (const name of Object.keys(obj)) {
|
|
77
|
+
const value = obj[name];
|
|
78
|
+
const resolved = await this.doResolve(value, context);
|
|
79
|
+
result[name] = resolved;
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
async doResolveArray(values, context) {
|
|
84
|
+
const result = [];
|
|
85
|
+
for (const value of values) {
|
|
86
|
+
const resolved = await this.doResolve(value, context);
|
|
87
|
+
result.push(resolved);
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
async doResolveString(value, context) {
|
|
92
|
+
await this.resolveVariables(value, context);
|
|
93
|
+
return value.replace(VariableResolverService_1.VAR_REGEXP, (match, varName) => {
|
|
94
|
+
const varValue = context.get(varName);
|
|
95
|
+
return varValue !== undefined ? varValue : match;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
async resolveVariables(value, context) {
|
|
99
|
+
const variableRegExp = new RegExp(VariableResolverService_1.VAR_REGEXP);
|
|
100
|
+
let match;
|
|
101
|
+
// eslint-disable-next-line no-null/no-null
|
|
102
|
+
while ((match = variableRegExp.exec(value)) !== null) {
|
|
103
|
+
const variableName = match[1];
|
|
104
|
+
await context.resolve(variableName);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
VariableResolverService.VAR_REGEXP = /\$\{(.*?)\}/g;
|
|
109
|
+
(0, tslib_1.__decorate)([
|
|
110
|
+
(0, inversify_1.inject)(variable_1.VariableRegistry),
|
|
111
|
+
(0, tslib_1.__metadata)("design:type", variable_1.VariableRegistry)
|
|
112
|
+
], VariableResolverService.prototype, "variableRegistry", void 0);
|
|
113
|
+
VariableResolverService = VariableResolverService_1 = (0, tslib_1.__decorate)([
|
|
114
|
+
(0, inversify_1.injectable)()
|
|
115
|
+
], VariableResolverService);
|
|
116
|
+
exports.VariableResolverService = VariableResolverService;
|
|
117
|
+
(function (VariableResolverService) {
|
|
118
|
+
class Context {
|
|
119
|
+
constructor(variableRegistry, options) {
|
|
120
|
+
this.variableRegistry = variableRegistry;
|
|
121
|
+
this.options = options;
|
|
122
|
+
this.resolved = new Map();
|
|
123
|
+
}
|
|
124
|
+
get(name) {
|
|
125
|
+
return this.resolved.get(name);
|
|
126
|
+
}
|
|
127
|
+
async resolve(name) {
|
|
128
|
+
if (this.resolved.has(name)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
let variableName = name;
|
|
133
|
+
let argument;
|
|
134
|
+
const parts = name.split(':', 2);
|
|
135
|
+
if (parts.length > 1) {
|
|
136
|
+
variableName = parts[0];
|
|
137
|
+
argument = parts[1];
|
|
138
|
+
}
|
|
139
|
+
const variable = this.variableRegistry.getVariable(variableName);
|
|
140
|
+
const resolved = await (variable === null || variable === void 0 ? void 0 : variable.resolve(this.options.context, argument, this.options.configurationSection, this.options.commandIdVariables, this.options.configuration));
|
|
141
|
+
if (typeof resolved === 'bigint' ||
|
|
142
|
+
typeof resolved === 'boolean' ||
|
|
143
|
+
typeof resolved === 'number' ||
|
|
144
|
+
typeof resolved === 'string') {
|
|
145
|
+
this.resolved.set(name, `${resolved}`);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
this.resolved.set(name, undefined);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
if ((0, core_1.isCancelled)(e)) {
|
|
153
|
+
throw e;
|
|
154
|
+
}
|
|
155
|
+
this.resolved.set(name, undefined);
|
|
156
|
+
console.error(`Failed to resolve '${name}' variable:`, e);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
VariableResolverService.Context = Context;
|
|
161
|
+
})(VariableResolverService = exports.VariableResolverService || (exports.VariableResolverService = {}));
|
|
162
|
+
exports.VariableResolverService = VariableResolverService;
|
|
163
163
|
//# sourceMappingURL=variable-resolver-service.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=variable-resolver-service.spec.d.ts.map
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2018 Red Hat, Inc. and others.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
const chai = require("chai");
|
|
19
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
20
|
-
const common_1 = require("@theia/core/lib/common");
|
|
21
|
-
const variable_1 = require("./variable");
|
|
22
|
-
const variable_resolver_service_1 = require("./variable-resolver-service");
|
|
23
|
-
const expect = chai.expect;
|
|
24
|
-
before(() => {
|
|
25
|
-
chai.config.showDiff = true;
|
|
26
|
-
chai.config.includeStack = true;
|
|
27
|
-
});
|
|
28
|
-
describe('variable-resolver-service', () => {
|
|
29
|
-
let testContainer;
|
|
30
|
-
let variableRegistry;
|
|
31
|
-
let variableResolverService;
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
testContainer = new inversify_1.Container();
|
|
34
|
-
testContainer.bind(variable_1.VariableRegistry).toSelf().inSingletonScope();
|
|
35
|
-
testContainer.bind(variable_resolver_service_1.VariableResolverService).toSelf().inSingletonScope();
|
|
36
|
-
variableRegistry = testContainer.get(variable_1.VariableRegistry);
|
|
37
|
-
variableRegistry.registerVariable({
|
|
38
|
-
name: 'file',
|
|
39
|
-
description: 'current file',
|
|
40
|
-
resolve: () => Promise.resolve('package.json')
|
|
41
|
-
});
|
|
42
|
-
variableRegistry.registerVariable({
|
|
43
|
-
name: 'lineNumber',
|
|
44
|
-
description: 'current line number',
|
|
45
|
-
resolve: () => Promise.resolve('6')
|
|
46
|
-
});
|
|
47
|
-
variableResolverService = testContainer.get(variable_resolver_service_1.VariableResolverService);
|
|
48
|
-
});
|
|
49
|
-
it('should resolve known variables in a text', async () => {
|
|
50
|
-
const resolved = await variableResolverService.resolve('file: ${file}; line: ${lineNumber}');
|
|
51
|
-
expect(resolved).is.equal('file: package.json; line: 6');
|
|
52
|
-
});
|
|
53
|
-
it('should resolve known variables in a string array', async () => {
|
|
54
|
-
const resolved = await variableResolverService.resolveArray(['file: ${file}', 'line: ${lineNumber}']);
|
|
55
|
-
expect(resolved.length).to.be.equal(2);
|
|
56
|
-
expect(resolved).to.contain('file: package.json');
|
|
57
|
-
expect(resolved).to.contain('line: 6');
|
|
58
|
-
});
|
|
59
|
-
it('should skip unknown variables', async () => {
|
|
60
|
-
const resolved = await variableResolverService.resolve('workspace: ${workspaceRoot}; file: ${file}; line: ${lineNumber}');
|
|
61
|
-
expect(resolved).is.equal('workspace: ${workspaceRoot}; file: package.json; line: 6');
|
|
62
|
-
});
|
|
63
|
-
it('should return undefined when a variable throws with `cancelled()` while resolving', async () => {
|
|
64
|
-
variableRegistry.registerVariable({
|
|
65
|
-
name: 'command',
|
|
66
|
-
resolve: (contextUri, commandId) => {
|
|
67
|
-
if (commandId === 'testCommand') {
|
|
68
|
-
throw (0, common_1.cancelled)();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
const resolved = await variableResolverService.resolve('workspace: ${command:testCommand}; file: ${file}; line: ${lineNumber}');
|
|
73
|
-
expect(resolved).equal(undefined);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2018 Red Hat, Inc. and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const chai = require("chai");
|
|
19
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
20
|
+
const common_1 = require("@theia/core/lib/common");
|
|
21
|
+
const variable_1 = require("./variable");
|
|
22
|
+
const variable_resolver_service_1 = require("./variable-resolver-service");
|
|
23
|
+
const expect = chai.expect;
|
|
24
|
+
before(() => {
|
|
25
|
+
chai.config.showDiff = true;
|
|
26
|
+
chai.config.includeStack = true;
|
|
27
|
+
});
|
|
28
|
+
describe('variable-resolver-service', () => {
|
|
29
|
+
let testContainer;
|
|
30
|
+
let variableRegistry;
|
|
31
|
+
let variableResolverService;
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
testContainer = new inversify_1.Container();
|
|
34
|
+
testContainer.bind(variable_1.VariableRegistry).toSelf().inSingletonScope();
|
|
35
|
+
testContainer.bind(variable_resolver_service_1.VariableResolverService).toSelf().inSingletonScope();
|
|
36
|
+
variableRegistry = testContainer.get(variable_1.VariableRegistry);
|
|
37
|
+
variableRegistry.registerVariable({
|
|
38
|
+
name: 'file',
|
|
39
|
+
description: 'current file',
|
|
40
|
+
resolve: () => Promise.resolve('package.json')
|
|
41
|
+
});
|
|
42
|
+
variableRegistry.registerVariable({
|
|
43
|
+
name: 'lineNumber',
|
|
44
|
+
description: 'current line number',
|
|
45
|
+
resolve: () => Promise.resolve('6')
|
|
46
|
+
});
|
|
47
|
+
variableResolverService = testContainer.get(variable_resolver_service_1.VariableResolverService);
|
|
48
|
+
});
|
|
49
|
+
it('should resolve known variables in a text', async () => {
|
|
50
|
+
const resolved = await variableResolverService.resolve('file: ${file}; line: ${lineNumber}');
|
|
51
|
+
expect(resolved).is.equal('file: package.json; line: 6');
|
|
52
|
+
});
|
|
53
|
+
it('should resolve known variables in a string array', async () => {
|
|
54
|
+
const resolved = await variableResolverService.resolveArray(['file: ${file}', 'line: ${lineNumber}']);
|
|
55
|
+
expect(resolved.length).to.be.equal(2);
|
|
56
|
+
expect(resolved).to.contain('file: package.json');
|
|
57
|
+
expect(resolved).to.contain('line: 6');
|
|
58
|
+
});
|
|
59
|
+
it('should skip unknown variables', async () => {
|
|
60
|
+
const resolved = await variableResolverService.resolve('workspace: ${workspaceRoot}; file: ${file}; line: ${lineNumber}');
|
|
61
|
+
expect(resolved).is.equal('workspace: ${workspaceRoot}; file: package.json; line: 6');
|
|
62
|
+
});
|
|
63
|
+
it('should return undefined when a variable throws with `cancelled()` while resolving', async () => {
|
|
64
|
+
variableRegistry.registerVariable({
|
|
65
|
+
name: 'command',
|
|
66
|
+
resolve: (contextUri, commandId) => {
|
|
67
|
+
if (commandId === 'testCommand') {
|
|
68
|
+
throw (0, common_1.cancelled)();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const resolved = await variableResolverService.resolve('workspace: ${command:testCommand}; file: ${file}; line: ${lineNumber}');
|
|
73
|
+
expect(resolved).equal(undefined);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
76
|
//# sourceMappingURL=variable-resolver-service.spec.js.map
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { Disposable, DisposableCollection, MaybePromise } from '@theia/core';
|
|
2
|
-
import URI from '@theia/core/lib/common/uri';
|
|
3
|
-
import { CommandIdVariables } from '../common/variable-types';
|
|
4
|
-
/**
|
|
5
|
-
* Variable can be used inside of strings using ${variableName} syntax.
|
|
6
|
-
*/
|
|
7
|
-
export interface Variable {
|
|
8
|
-
/**
|
|
9
|
-
* A unique name of this variable.
|
|
10
|
-
*/
|
|
11
|
-
readonly name: string;
|
|
12
|
-
/**
|
|
13
|
-
* A human-readable description of this variable.
|
|
14
|
-
*/
|
|
15
|
-
readonly description?: string;
|
|
16
|
-
/**
|
|
17
|
-
* Resolve to a string value of this variable or
|
|
18
|
-
* `undefined` if variable cannot be resolved.
|
|
19
|
-
* Never reject.
|
|
20
|
-
*/
|
|
21
|
-
resolve(context?: URI, argument?: string, configurationSection?: string, commandIdVariables?: CommandIdVariables, configuration?: unknown): MaybePromise<any>;
|
|
22
|
-
}
|
|
23
|
-
export declare const VariableContribution: unique symbol;
|
|
24
|
-
/**
|
|
25
|
-
* The variable contribution should be implemented to register custom variables.
|
|
26
|
-
*/
|
|
27
|
-
export interface VariableContribution {
|
|
28
|
-
registerVariables(variables: VariableRegistry): void;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* The variable registry manages variables.
|
|
32
|
-
*/
|
|
33
|
-
export declare class VariableRegistry implements Disposable {
|
|
34
|
-
protected readonly variables: Map<string, Variable>;
|
|
35
|
-
protected readonly toDispose: DisposableCollection;
|
|
36
|
-
dispose(): void;
|
|
37
|
-
/**
|
|
38
|
-
* Register the given variable.
|
|
39
|
-
* Do nothing if a variable is already registered for the given variable name.
|
|
40
|
-
*/
|
|
41
|
-
registerVariable(variable: Variable): Disposable;
|
|
42
|
-
/**
|
|
43
|
-
* Return all registered variables.
|
|
44
|
-
*/
|
|
45
|
-
getVariables(): Variable[];
|
|
46
|
-
/**
|
|
47
|
-
* Get a variable for the given name or `undefined` if none.
|
|
48
|
-
*/
|
|
49
|
-
getVariable(name: string): Variable | undefined;
|
|
50
|
-
/**
|
|
51
|
-
* Register an array of variables.
|
|
52
|
-
* Do nothing if a variable is already registered for the given variable name.
|
|
53
|
-
*/
|
|
54
|
-
registerVariables(variables: Variable[]): Disposable[];
|
|
55
|
-
}
|
|
1
|
+
import { Disposable, DisposableCollection, MaybePromise } from '@theia/core';
|
|
2
|
+
import URI from '@theia/core/lib/common/uri';
|
|
3
|
+
import { CommandIdVariables } from '../common/variable-types';
|
|
4
|
+
/**
|
|
5
|
+
* Variable can be used inside of strings using ${variableName} syntax.
|
|
6
|
+
*/
|
|
7
|
+
export interface Variable {
|
|
8
|
+
/**
|
|
9
|
+
* A unique name of this variable.
|
|
10
|
+
*/
|
|
11
|
+
readonly name: string;
|
|
12
|
+
/**
|
|
13
|
+
* A human-readable description of this variable.
|
|
14
|
+
*/
|
|
15
|
+
readonly description?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Resolve to a string value of this variable or
|
|
18
|
+
* `undefined` if variable cannot be resolved.
|
|
19
|
+
* Never reject.
|
|
20
|
+
*/
|
|
21
|
+
resolve(context?: URI, argument?: string, configurationSection?: string, commandIdVariables?: CommandIdVariables, configuration?: unknown): MaybePromise<any>;
|
|
22
|
+
}
|
|
23
|
+
export declare const VariableContribution: unique symbol;
|
|
24
|
+
/**
|
|
25
|
+
* The variable contribution should be implemented to register custom variables.
|
|
26
|
+
*/
|
|
27
|
+
export interface VariableContribution {
|
|
28
|
+
registerVariables(variables: VariableRegistry): void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The variable registry manages variables.
|
|
32
|
+
*/
|
|
33
|
+
export declare class VariableRegistry implements Disposable {
|
|
34
|
+
protected readonly variables: Map<string, Variable>;
|
|
35
|
+
protected readonly toDispose: DisposableCollection;
|
|
36
|
+
dispose(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Register the given variable.
|
|
39
|
+
* Do nothing if a variable is already registered for the given variable name.
|
|
40
|
+
*/
|
|
41
|
+
registerVariable(variable: Variable): Disposable;
|
|
42
|
+
/**
|
|
43
|
+
* Return all registered variables.
|
|
44
|
+
*/
|
|
45
|
+
getVariables(): Variable[];
|
|
46
|
+
/**
|
|
47
|
+
* Get a variable for the given name or `undefined` if none.
|
|
48
|
+
*/
|
|
49
|
+
getVariable(name: string): Variable | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Register an array of variables.
|
|
52
|
+
* Do nothing if a variable is already registered for the given variable name.
|
|
53
|
+
*/
|
|
54
|
+
registerVariables(variables: Variable[]): Disposable[];
|
|
55
|
+
}
|
|
56
56
|
//# sourceMappingURL=variable.d.ts.map
|