@theia/variable-resolver 1.77.0-next.0 → 1.77.0-next.101
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/browser/common-variable-contribution.d.ts +1 -1
- package/lib/browser/common-variable-contribution.d.ts.map +1 -1
- package/lib/browser/common-variable-contribution.js +46 -44
- package/lib/browser/common-variable-contribution.js.map +1 -1
- package/lib/browser/common-variable-contribution.spec.d.ts +2 -0
- package/lib/browser/common-variable-contribution.spec.d.ts.map +1 -0
- package/lib/browser/common-variable-contribution.spec.js +133 -0
- package/lib/browser/common-variable-contribution.spec.js.map +1 -0
- package/lib/browser/index.d.ts +3 -3
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +3 -6
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/variable-input-schema.js +1 -4
- package/lib/browser/variable-input-schema.js.map +1 -1
- package/lib/browser/variable-input.js +1 -2
- package/lib/browser/variable-quick-open-service.d.ts +2 -2
- package/lib/browser/variable-quick-open-service.d.ts.map +1 -1
- package/lib/browser/variable-quick-open-service.js +17 -24
- package/lib/browser/variable-quick-open-service.js.map +1 -1
- package/lib/browser/variable-resolver-frontend-contribution.d.ts +2 -2
- package/lib/browser/variable-resolver-frontend-contribution.d.ts.map +1 -1
- package/lib/browser/variable-resolver-frontend-contribution.js +14 -19
- package/lib/browser/variable-resolver-frontend-contribution.js.map +1 -1
- package/lib/browser/variable-resolver-frontend-contribution.spec.d.ts +1 -1
- package/lib/browser/variable-resolver-frontend-contribution.spec.d.ts.map +1 -1
- package/lib/browser/variable-resolver-frontend-contribution.spec.js +23 -27
- package/lib/browser/variable-resolver-frontend-contribution.spec.js.map +1 -1
- package/lib/browser/variable-resolver-frontend-module.js +18 -20
- package/lib/browser/variable-resolver-frontend-module.js.map +1 -1
- package/lib/browser/variable-resolver-service.d.ts +2 -2
- package/lib/browser/variable-resolver-service.d.ts.map +1 -1
- package/lib/browser/variable-resolver-service.js +12 -16
- package/lib/browser/variable-resolver-service.js.map +1 -1
- package/lib/browser/variable-resolver-service.spec.js +14 -16
- package/lib/browser/variable-resolver-service.spec.js.map +1 -1
- package/lib/browser/variable.d.ts +1 -1
- package/lib/browser/variable.d.ts.map +1 -1
- package/lib/browser/variable.js +12 -16
- package/lib/browser/variable.js.map +1 -1
- package/lib/browser/variable.spec.js +10 -12
- package/lib/browser/variable.spec.js.map +1 -1
- package/lib/common/variable-types.js +1 -2
- package/lib/common/variable-types.js.map +1 -1
- package/package.json +12 -3
- package/src/browser/common-variable-contribution.spec.ts +157 -0
- package/src/browser/common-variable-contribution.ts +17 -6
- package/src/browser/index.ts +3 -3
- package/src/browser/variable-quick-open-service.ts +2 -2
- package/src/browser/variable-resolver-frontend-contribution.spec.ts +3 -3
- package/src/browser/variable-resolver-frontend-contribution.ts +2 -2
- package/src/browser/variable-resolver-frontend-module.ts +5 -5
- package/src/browser/variable-resolver-service.spec.ts +2 -2
- package/src/browser/variable-resolver-service.ts +2 -2
- package/src/browser/variable.spec.ts +1 -1
- package/src/browser/variable.ts +1 -1
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 Md. Mehedi Hasan.
|
|
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 { ResourceContextKey } from '@theia/core/lib/browser/resource-context-key';
|
|
22
|
+
import { ApplicationServer } from '@theia/core/lib/common/application-protocol';
|
|
23
|
+
import { CommandService } from '@theia/core/lib/common/command';
|
|
24
|
+
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
|
|
25
|
+
import { isCancelled } from '@theia/core/lib/common/cancellation';
|
|
26
|
+
import { ILogger } from '@theia/core/lib/common/logger';
|
|
27
|
+
import { PreferenceService } from '@theia/core/lib/common/preferences/preference-service';
|
|
28
|
+
import { QuickInputService } from '@theia/core/lib/common/quick-pick-service';
|
|
29
|
+
import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
|
|
30
|
+
import { Container } from '@theia/core/shared/inversify';
|
|
31
|
+
import { expect } from 'chai';
|
|
32
|
+
import * as sinon from 'sinon';
|
|
33
|
+
import URI from '@theia/core/lib/common/uri';
|
|
34
|
+
import { CommonVariableContribution } from './common-variable-contribution.js';
|
|
35
|
+
import { VariableInput } from './variable-input.js';
|
|
36
|
+
import { VariableRegistry } from './variable.js';
|
|
37
|
+
|
|
38
|
+
disableJSDOM();
|
|
39
|
+
|
|
40
|
+
describe('CommonVariableContribution', () => {
|
|
41
|
+
|
|
42
|
+
before(() => {
|
|
43
|
+
disableJSDOM = enableJSDOM();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
after(() => {
|
|
47
|
+
disableJSDOM();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const workspace = new URI('file:///workspace');
|
|
51
|
+
const promptInput: VariableInput = {
|
|
52
|
+
id: 'task-argument',
|
|
53
|
+
type: 'promptString',
|
|
54
|
+
description: 'Enter a task argument',
|
|
55
|
+
default: 'default-value'
|
|
56
|
+
};
|
|
57
|
+
const pickInput: VariableInput = {
|
|
58
|
+
id: 'task-argument-choice',
|
|
59
|
+
type: 'pickString',
|
|
60
|
+
description: 'Choose a task argument',
|
|
61
|
+
options: ['first', 'second'],
|
|
62
|
+
default: 'second'
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
let variables: VariableRegistry;
|
|
66
|
+
let input: sinon.SinonStub;
|
|
67
|
+
let showQuickPick: sinon.SinonStub;
|
|
68
|
+
|
|
69
|
+
beforeEach(async () => {
|
|
70
|
+
const container = new Container();
|
|
71
|
+
container.bind(ILogger).to(MockLogger);
|
|
72
|
+
input = sinon.stub().resolves('task-argument');
|
|
73
|
+
showQuickPick = sinon.stub();
|
|
74
|
+
const inputs = [promptInput, pickInput];
|
|
75
|
+
|
|
76
|
+
container.bind<Partial<EnvVariablesServer>>(EnvVariablesServer).toConstantValue({
|
|
77
|
+
getExecPath: async () => ''
|
|
78
|
+
});
|
|
79
|
+
container.bind<Partial<CommandService>>(CommandService).toConstantValue({});
|
|
80
|
+
container.bind<Partial<PreferenceService>>(PreferenceService).toConstantValue({
|
|
81
|
+
get: sinon.stub().returns({ inputs })
|
|
82
|
+
});
|
|
83
|
+
container.bind<Partial<ResourceContextKey>>(ResourceContextKey).toConstantValue({
|
|
84
|
+
get: () => workspace.toString()
|
|
85
|
+
});
|
|
86
|
+
container.bind<Partial<QuickInputService>>(QuickInputService).toConstantValue({
|
|
87
|
+
input,
|
|
88
|
+
showQuickPick
|
|
89
|
+
});
|
|
90
|
+
container.bind<Partial<ApplicationServer>>(ApplicationServer).toConstantValue({});
|
|
91
|
+
container.bind(VariableRegistry).toSelf();
|
|
92
|
+
container.bind(CommonVariableContribution).toSelf();
|
|
93
|
+
|
|
94
|
+
variables = container.get(VariableRegistry);
|
|
95
|
+
await container.get(CommonVariableContribution).registerVariables(variables);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('keeps promptString inputs open when focus is lost', async () => {
|
|
99
|
+
const resolved = await variables.getVariable('input')?.resolve(workspace, 'task-argument', 'tasks');
|
|
100
|
+
|
|
101
|
+
expect(resolved).to.equal('task-argument');
|
|
102
|
+
sinon.assert.calledOnceWithExactly(input, {
|
|
103
|
+
prompt: 'Enter a task argument',
|
|
104
|
+
value: 'default-value',
|
|
105
|
+
ignoreFocusLost: true
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('accepts an empty promptString value', async () => {
|
|
110
|
+
input.resolves('');
|
|
111
|
+
|
|
112
|
+
const resolved = await variables.getVariable('input')?.resolve(workspace, 'task-argument', 'tasks');
|
|
113
|
+
|
|
114
|
+
expect(resolved).to.equal('');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('cancels promptString inputs when input returns undefined', async () => {
|
|
118
|
+
input.resolves(undefined);
|
|
119
|
+
|
|
120
|
+
let error: Error | undefined;
|
|
121
|
+
try {
|
|
122
|
+
await variables.getVariable('input')?.resolve(workspace, 'task-argument', 'tasks');
|
|
123
|
+
} catch (e) {
|
|
124
|
+
error = e as Error;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
expect(isCancelled(error)).to.equal(true);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('keeps pickString inputs open when focus is lost', async () => {
|
|
131
|
+
showQuickPick.resolves({ label: 'first', value: 'first' });
|
|
132
|
+
|
|
133
|
+
const resolved = await variables.getVariable('input')?.resolve(workspace, 'task-argument-choice', 'tasks');
|
|
134
|
+
|
|
135
|
+
expect(resolved).to.equal('first');
|
|
136
|
+
sinon.assert.calledOnceWithExactly(showQuickPick, [
|
|
137
|
+
{ label: 'second', value: 'second', description: 'Default' },
|
|
138
|
+
{ label: 'first', value: 'first' }
|
|
139
|
+
], {
|
|
140
|
+
placeholder: 'Choose a task argument',
|
|
141
|
+
ignoreFocusOut: true
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('cancels pickString inputs when no item is selected', async () => {
|
|
146
|
+
showQuickPick.resolves(undefined);
|
|
147
|
+
|
|
148
|
+
let error: Error | undefined;
|
|
149
|
+
try {
|
|
150
|
+
await variables.getVariable('input')?.resolve(workspace, 'task-argument-choice', 'tasks');
|
|
151
|
+
} catch (e) {
|
|
152
|
+
error = e as Error;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
expect(isCancelled(error)).to.equal(true);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
17
|
import { injectable, inject, optional } from '@theia/core/shared/inversify';
|
|
18
|
-
import { VariableContribution, VariableRegistry } from './variable';
|
|
18
|
+
import { VariableContribution, VariableRegistry } from './variable.js';
|
|
19
19
|
import { ApplicationServer } from '@theia/core/lib/common/application-protocol';
|
|
20
20
|
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
|
|
21
21
|
import { CommandService } from '@theia/core/lib/common/command';
|
|
22
22
|
import { OS } from '@theia/core/lib/common/os';
|
|
23
23
|
import { PreferenceService } from '@theia/core/lib/common/preferences/preference-service';
|
|
24
24
|
import { ResourceContextKey } from '@theia/core/lib/browser/resource-context-key';
|
|
25
|
-
import { VariableInput } from './variable-input';
|
|
25
|
+
import { VariableInput } from './variable-input.js';
|
|
26
26
|
import { QuickInputService, QuickPickValue } from '@theia/core/lib/browser';
|
|
27
27
|
import { MaybeArray, RecursivePartial } from '@theia/core/lib/common/types';
|
|
28
28
|
import { cancelled } from '@theia/core/lib/common/cancellation';
|
|
@@ -108,10 +108,15 @@ export class CommonVariableContribution implements VariableContribution {
|
|
|
108
108
|
if (typeof input.description !== 'string') {
|
|
109
109
|
return undefined;
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
const value = await this.quickInputService?.input({
|
|
112
112
|
prompt: input.description,
|
|
113
|
-
value: input.default
|
|
113
|
+
value: input.default,
|
|
114
|
+
ignoreFocusLost: true
|
|
114
115
|
});
|
|
116
|
+
if (value === undefined) {
|
|
117
|
+
throw cancelled();
|
|
118
|
+
}
|
|
119
|
+
return value;
|
|
115
120
|
}
|
|
116
121
|
if (input.type === 'pickString') {
|
|
117
122
|
if (typeof input.description !== 'string' || !Array.isArray(input.options)) {
|
|
@@ -135,8 +140,14 @@ export class CommonVariableContribution implements VariableContribution {
|
|
|
135
140
|
});
|
|
136
141
|
}
|
|
137
142
|
}
|
|
138
|
-
const selectedPick = await this.quickInputService?.showQuickPick(elements, {
|
|
139
|
-
|
|
143
|
+
const selectedPick = await this.quickInputService?.showQuickPick(elements, {
|
|
144
|
+
placeholder: input.description,
|
|
145
|
+
ignoreFocusOut: true
|
|
146
|
+
});
|
|
147
|
+
if (!selectedPick) {
|
|
148
|
+
throw cancelled();
|
|
149
|
+
}
|
|
150
|
+
return selectedPick.value;
|
|
140
151
|
}
|
|
141
152
|
if (input.type === 'command') {
|
|
142
153
|
if (typeof input.command !== 'string') {
|
package/src/browser/index.ts
CHANGED
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
|
-
export * from './variable';
|
|
18
|
-
export * from './variable-quick-open-service';
|
|
19
|
-
export * from './variable-resolver-service';
|
|
17
|
+
export * from './variable.js';
|
|
18
|
+
export * from './variable-quick-open-service.js';
|
|
19
|
+
export * from './variable-resolver-service.js';
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
import { inject, injectable, optional } from '@theia/core/shared/inversify';
|
|
18
18
|
import { MessageService } from '@theia/core/lib/common/message-service';
|
|
19
|
-
import { VariableRegistry, Variable } from './variable';
|
|
20
|
-
import { VariableResolverService } from './variable-resolver-service';
|
|
19
|
+
import { VariableRegistry, Variable } from './variable.js';
|
|
20
|
+
import { VariableResolverService } from './variable-resolver-service.js';
|
|
21
21
|
import { QuickPickItem, QuickInputService } from '@theia/core/lib/browser';
|
|
22
22
|
|
|
23
23
|
@injectable()
|
|
@@ -25,9 +25,9 @@ import * as chai from 'chai';
|
|
|
25
25
|
import { Container, ContainerModule } from '@theia/core/shared/inversify';
|
|
26
26
|
import { ILogger, bindContributionProvider } from '@theia/core/lib/common';
|
|
27
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';
|
|
28
|
+
import { VariableContribution, VariableRegistry } from './variable.js';
|
|
29
|
+
import { VariableQuickOpenService } from './variable-quick-open-service.js';
|
|
30
|
+
import { VariableResolverFrontendContribution } from './variable-resolver-frontend-contribution.js';
|
|
31
31
|
|
|
32
32
|
disableJSDOM();
|
|
33
33
|
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
import { injectable, inject, named } from '@theia/core/shared/inversify';
|
|
18
18
|
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
|
19
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';
|
|
20
|
+
import { VariableContribution, VariableRegistry } from './variable.js';
|
|
21
|
+
import { VariableQuickOpenService } from './variable-quick-open-service.js';
|
|
22
22
|
|
|
23
23
|
export const LIST_VARIABLES: Command = Command.toLocalizedCommand({
|
|
24
24
|
id: 'variable.list',
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
18
18
|
import { bindRootContributionProvider, CommandContribution } from '@theia/core';
|
|
19
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';
|
|
20
|
+
import { VariableRegistry, VariableContribution } from './variable.js';
|
|
21
|
+
import { VariableQuickOpenService } from './variable-quick-open-service.js';
|
|
22
|
+
import { VariableResolverFrontendContribution } from './variable-resolver-frontend-contribution.js';
|
|
23
|
+
import { VariableResolverService } from './variable-resolver-service.js';
|
|
24
|
+
import { CommonVariableContribution } from './common-variable-contribution.js';
|
|
25
25
|
|
|
26
26
|
export default new ContainerModule(bind => {
|
|
27
27
|
bind(VariableRegistry).toSelf().inSingletonScope();
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
import * as chai from 'chai';
|
|
18
18
|
import { Container } from '@theia/core/shared/inversify';
|
|
19
19
|
import { cancelled } from '@theia/core/lib/common';
|
|
20
|
-
import { VariableRegistry } from './variable';
|
|
21
|
-
import { VariableResolverService } from './variable-resolver-service';
|
|
20
|
+
import { VariableRegistry } from './variable.js';
|
|
21
|
+
import { VariableResolverService } from './variable-resolver-service.js';
|
|
22
22
|
import { ILogger } from '@theia/core';
|
|
23
23
|
import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
|
|
24
24
|
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
18
18
|
|
|
19
19
|
import { injectable, inject } from '@theia/core/shared/inversify';
|
|
20
|
-
import { VariableRegistry } from './variable';
|
|
20
|
+
import { VariableRegistry } from './variable.js';
|
|
21
21
|
import URI from '@theia/core/lib/common/uri';
|
|
22
|
-
import { CommandIdVariables } from '../common/variable-types';
|
|
22
|
+
import { CommandIdVariables } from '../common/variable-types.js';
|
|
23
23
|
import { isCancelled } from '@theia/core';
|
|
24
24
|
|
|
25
25
|
export interface VariableResolveOptions {
|
|
@@ -18,7 +18,7 @@ import * as chai from 'chai';
|
|
|
18
18
|
import { Container, ContainerModule } from '@theia/core/shared/inversify';
|
|
19
19
|
import { ILogger, Disposable } from '@theia/core/lib/common';
|
|
20
20
|
import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
|
|
21
|
-
import { Variable, VariableRegistry } from './variable';
|
|
21
|
+
import { Variable, VariableRegistry } from './variable.js';
|
|
22
22
|
|
|
23
23
|
const expect = chai.expect;
|
|
24
24
|
let variableRegistry: VariableRegistry;
|
package/src/browser/variable.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import { injectable, inject, named } from '@theia/core/shared/inversify';
|
|
18
18
|
import { Disposable, DisposableCollection, MaybePromise, ILogger } from '@theia/core';
|
|
19
19
|
import URI from '@theia/core/lib/common/uri';
|
|
20
|
-
import { CommandIdVariables } from '../common/variable-types';
|
|
20
|
+
import { CommandIdVariables } from '../common/variable-types.js';
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Variable can be used inside of strings using ${variableName} syntax.
|