Move task definition variable resolving to be early

Part of #81007
This commit is contained in:
Alex Ross 2020-08-20 13:33:28 +02:00
parent 88b7db2815
commit 73d583f759
3 changed files with 28 additions and 8 deletions

View file

@ -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<string> = {};
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) {

View file

@ -81,12 +81,12 @@ class InstanceManager {
class VariableResolver {
constructor(public workspaceFolder: IWorkspaceFolder | undefined, public taskSystemInfo: TaskSystemInfo | undefined, private _values: Map<string, string>, private _service: IConfigurationResolverService | undefined) {
constructor(public workspaceFolder: IWorkspaceFolder | undefined, public taskSystemInfo: TaskSystemInfo | undefined, public readonly values: Map<string, string>, 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<string>, 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<string>, command: CommandConfiguration, task: CustomTask | ContributedTask): void {

View file

@ -1067,6 +1067,7 @@ export interface TaskEvent {
exitCode?: number;
terminalId?: number;
__task?: Task;
resolvedVariables?: Map<string, string>;
}
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<string, string>): 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<string, string>): 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) {