Input variables in tasks (#63910)

Fixes #4758
This commit is contained in:
Alex Ross
2018-12-03 09:24:59 +01:00
committed by GitHub
parent 253a4f6d17
commit f9703e9ad6
13 changed files with 653 additions and 151 deletions

View File

@@ -10,7 +10,7 @@ import { generateUuid } from 'vs/base/common/uuid';
import * as Objects from 'vs/base/common/objects';
import * as Types from 'vs/base/common/types';
import * as Platform from 'vs/base/common/platform';
import { IStringDictionary } from 'vs/base/common/collections';
import { IStringDictionary, forEach } from 'vs/base/common/collections';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
@@ -33,6 +33,7 @@ import {
ProcessExecutionDTO, ShellExecutionDTO, ShellExecutionOptionsDTO, TaskDTO, TaskSourceDTO, TaskHandleDTO, TaskFilterDTO, TaskProcessStartedDTO, TaskProcessEndedDTO, TaskSystemInfoDTO,
RunOptionsDTO
} from 'vs/workbench/api/shared/tasks';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
namespace TaskExecutionDTO {
export function from(value: TaskExecution): TaskExecutionDTO {
@@ -381,7 +382,8 @@ export class MainThreadTask implements MainThreadTaskShape {
constructor(
extHostContext: IExtHostContext,
@ITaskService private readonly _taskService: ITaskService,
@IWorkspaceContextService private readonly _workspaceContextServer: IWorkspaceContextService
@IWorkspaceContextService private readonly _workspaceContextServer: IWorkspaceContextService,
@IConfigurationResolverService private readonly _configurationResolverService: IConfigurationResolverService
) {
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostTask);
this._providers = new Map();
@@ -460,7 +462,9 @@ export class MainThreadTask implements MainThreadTaskShape {
if (TaskHandleDTO.is(value)) {
let workspaceFolder = this._workspaceContextServer.getWorkspaceFolder(URI.revive(value.workspaceFolder));
this._taskService.getTask(workspaceFolder, value.id, true).then((task: Task) => {
this._taskService.run(task);
this._taskService.run(task).then(undefined, reason => {
// eat the error, it has already been surfaced to the user and we don't care about it here
});
let result: TaskExecutionDTO = {
id: value.id,
task: TaskDTO.from(task)
@@ -471,7 +475,9 @@ export class MainThreadTask implements MainThreadTaskShape {
});
} else {
let task = TaskDTO.to(value, this._workspaceContextServer, true);
this._taskService.run(task);
this._taskService.run(task).then(undefined, reason => {
// eat the error, it has already been surfaced to the user and we don't care about it here
});
let result: TaskExecutionDTO = {
id: task._id,
task: TaskDTO.from(task)
@@ -524,15 +530,32 @@ export class MainThreadTask implements MainThreadTaskShape {
let vars: string[] = [];
toResolve.variables.forEach(item => vars.push(item));
return Promise.resolve(this._proxy.$resolveVariables(workspaceFolder.uri, { process: toResolve.process, variables: vars })).then(values => {
let result = {
process: undefined as string,
variables: new Map<string, string>()
};
Object.keys(values.variables).forEach(key => result.variables.set(key, values.variables[key]));
if (Types.isString(values.process)) {
result.process = values.process;
}
return result;
const partiallyResolvedVars = new Array<string>();
forEach(values.variables, (entry) => {
partiallyResolvedVars.push(entry.value);
});
return new Promise((resolve, reject) => {
this._configurationResolverService.resolveWithInteraction(workspaceFolder, partiallyResolvedVars, 'tasks').then(resolvedVars => {
let result = {
process: undefined as string,
variables: new Map<string, string>()
};
for (let i = 0; i < partiallyResolvedVars.length; i++) {
const variableName = vars[i].substring(2, vars[i].length - 1);
if (values.variables[vars[i]] === vars[i]) {
result.variables.set(variableName, resolvedVars.get(variableName));
} else {
result.variables.set(variableName, partiallyResolvedVars[i]);
}
}
if (Types.isString(values.process)) {
result.process = values.process;
}
resolve(result);
}, reason => {
reject(reason);
});
});
});
}
});