diff --git a/src/vs/workbench/api/browser/mainThreadTask.ts b/src/vs/workbench/api/browser/mainThreadTask.ts index d94b7f3dfcb..6b25a273488 100644 --- a/src/vs/workbench/api/browser/mainThreadTask.ts +++ b/src/vs/workbench/api/browser/mainThreadTask.ts @@ -419,9 +419,11 @@ export class MainThreadTask implements MainThreadTaskShape { if (event.kind === TaskEventKind.Start) { const execution = TaskExecutionDTO.from(task.getTaskExecution()); let resolvedDefinition: TaskDefinitionDTO | undefined; - if (execution.task && execution.task.execution && CustomExecutionDTO.is(execution.task.execution)) { - resolvedDefinition = await this._configurationResolverService.resolveWithInteractionReplace(task.getWorkspaceFolder(), - execution.task.definition, 'tasks'); + if (execution.task && execution.task.execution && CustomExecutionDTO.is(execution.task.execution) && event.resolvedVariables) { + const dictionary: IStringDictionary = {}; + Array.from(event.resolvedVariables.entries()).forEach(entry => dictionary[entry[0]] = entry[1]); + resolvedDefinition = await this._configurationResolverService.resolveAny(task.getWorkspaceFolder(), + execution.task.definition, dictionary); } this._proxy.$onDidStartTask(execution, event.terminalId!, resolvedDefinition); } else if (event.kind === TaskEventKind.ProcessStarted) { diff --git a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts index f6993a12c3c..e35865f75fc 100644 --- a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts +++ b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts @@ -81,12 +81,12 @@ class InstanceManager { class VariableResolver { - constructor(public workspaceFolder: IWorkspaceFolder | undefined, public taskSystemInfo: TaskSystemInfo | undefined, private _values: Map, private _service: IConfigurationResolverService | undefined) { + constructor(public workspaceFolder: IWorkspaceFolder | undefined, public taskSystemInfo: TaskSystemInfo | undefined, public readonly values: Map, private _service: IConfigurationResolverService | undefined) { } resolve(value: string): string { return value.replace(/\$\{(.*?)\}/g, (match: string, variable: string) => { // Strip out the ${} because the map contains them variables without those characters. - let result = this._values.get(match.substring(2, match.length - 1)); + let result = this.values.get(match.substring(2, match.length - 1)); if ((result !== undefined) && (result !== null)) { return result; } @@ -840,7 +840,7 @@ export class TerminalTaskSystem implements ITaskSystem { }, (_error) => { // The process never got ready. Need to think how to handle this. }); - this._onDidStateChange.fire(TaskEvent.create(TaskEventKind.Start, task, terminal.id)); + this._onDidStateChange.fire(TaskEvent.create(TaskEventKind.Start, task, terminal.id, resolver.values)); const mapKey = task.getMapKey(); this.busyTasks[mapKey] = task; this._onDidStateChange.fire(TaskEvent.create(TaskEventKind.Active, task)); @@ -1331,6 +1331,22 @@ export class TerminalTaskSystem implements ITaskSystem { this.collectCommandVariables(variables, task.command, task); } this.collectMatcherVariables(variables, task.configurationProperties.problemMatchers); + + if (task.command.runtime === RuntimeType.CustomExecution && CustomTask.is(task)) { + this.collectDefinitionVariables(variables, task._source.config.element); + } + } + + private collectDefinitionVariables(variables: Set, definition: any): void { + for (const key in definition) { + if (Types.isString(definition[key])) { + this.collectVariables(variables, definition[key]); + } else if (Types.isArray(definition[key])) { + definition[key].forEach((element: any) => this.collectDefinitionVariables(variables, element)); + } else if (Types.isObject(definition[key])) { + this.collectDefinitionVariables(variables, definition[key]); + } + } } private collectCommandVariables(variables: Set, command: CommandConfiguration, task: CustomTask | ContributedTask): void { diff --git a/src/vs/workbench/contrib/tasks/common/tasks.ts b/src/vs/workbench/contrib/tasks/common/tasks.ts index 7ec7668a9f6..a88910f481f 100644 --- a/src/vs/workbench/contrib/tasks/common/tasks.ts +++ b/src/vs/workbench/contrib/tasks/common/tasks.ts @@ -1067,6 +1067,7 @@ export interface TaskEvent { exitCode?: number; terminalId?: number; __task?: Task; + resolvedVariables?: Map; } export const enum TaskRunSource { @@ -1078,10 +1079,10 @@ export const enum TaskRunSource { export namespace TaskEvent { export function create(kind: TaskEventKind.ProcessStarted | TaskEventKind.ProcessEnded, task: Task, processIdOrExitCode?: number): TaskEvent; - export function create(kind: TaskEventKind.Start, task: Task, terminalId?: number): TaskEvent; + export function create(kind: TaskEventKind.Start, task: Task, terminalId?: number, resolvedVariables?: Map): TaskEvent; export function create(kind: TaskEventKind.DependsOnStarted | TaskEventKind.Start | TaskEventKind.Active | TaskEventKind.Inactive | TaskEventKind.Terminated | TaskEventKind.End, task: Task): TaskEvent; export function create(kind: TaskEventKind.Changed): TaskEvent; - export function create(kind: TaskEventKind, task?: Task, processIdOrExitCodeOrTerminalId?: number): TaskEvent { + export function create(kind: TaskEventKind, task?: Task, processIdOrExitCodeOrTerminalId?: number, resolvedVariables?: Map): TaskEvent { if (task) { let result: TaskEvent = { kind: kind, @@ -1096,6 +1097,7 @@ export namespace TaskEvent { }; if (kind === TaskEventKind.Start) { result.terminalId = processIdOrExitCodeOrTerminalId; + result.resolvedVariables = resolvedVariables; } else if (kind === TaskEventKind.ProcessStarted) { result.processId = processIdOrExitCodeOrTerminalId; } else if (kind === TaskEventKind.ProcessEnded) {