Skip to content

Commit

Permalink
support input variables for tasks
Browse files Browse the repository at this point in the history
- add support to input variables which have the syntax: ${input:variableID}, where the variableID refers to entries in the inputs section of `tasks.json`.
- resolves #5836

Signed-off-by: Liang Huang <liang.huang@ericsson.com>
  • Loading branch information
Liang Huang authored and elaihau committed Oct 6, 2019
1 parent 35e5e78 commit 0f7fc56
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/task/src/browser/process/process-task-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export class ProcessTaskResolver implements TaskResolver {
throw new Error('Unsupported task configuration type.');
}
const context = new URI(this.taskDefinitionRegistry.getDefinition(taskConfig) ? taskConfig.scope : taskConfig._source).withScheme('file');
const variableResolverOptions = { context };
const variableResolverOptions = {
context, configurationSection: 'tasks'
};
const processTaskConfig = taskConfig as ProcessTaskConfiguration;
const result: ProcessTaskConfiguration = {
...processTaskConfig,
Expand Down
5 changes: 4 additions & 1 deletion packages/task/src/browser/task-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ export class TaskService implements TaskConfigurationClient {
if (resolvedMatcher) {
const scope = task._scope || task._source;
if (resolvedMatcher.filePrefix && scope) {
const options = { context: new URI(scope).withScheme('file') };
const options = {
context: new URI(scope).withScheme('file'),
configurationSection: 'tasks'
};
const resolvedPrefix = await this.variableResolverService.resolve(resolvedMatcher.filePrefix, options);
Object.assign(resolvedMatcher, { filePrefix: resolvedPrefix });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class CommonVariableContribution implements VariableContribution {
const inputs = !!configuration && 'inputs' in configuration ? configuration.inputs : undefined;
const input = Array.isArray(inputs) && inputs.find(item => !!item && item.id === variable);
if (!input) {
return undefined;
throw new Error(`Undefined input variable "${variable}" encountered. Remove or define "${variable}" to continue.`);
}
if (input.type === 'promptString') {
if (typeof input.description !== 'string') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export namespace VariableResolverService {
} catch (e) {
console.error(`Failed to resolved '${name}' variable`, e);
this.resolved.set(name, undefined);
throw e;
}
}

Expand Down

0 comments on commit 0f7fc56

Please sign in to comment.