Skip to content

Commit 73d583f

Browse files
committed
Move task definition variable resolving to be early
Part of microsoft#81007
1 parent 88b7db2 commit 73d583f

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

src/vs/workbench/api/browser/mainThreadTask.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,11 @@ export class MainThreadTask implements MainThreadTaskShape {
419419
if (event.kind === TaskEventKind.Start) {
420420
const execution = TaskExecutionDTO.from(task.getTaskExecution());
421421
let resolvedDefinition: TaskDefinitionDTO | undefined;
422-
if (execution.task && execution.task.execution && CustomExecutionDTO.is(execution.task.execution)) {
423-
resolvedDefinition = await this._configurationResolverService.resolveWithInteractionReplace(task.getWorkspaceFolder(),
424-
execution.task.definition, 'tasks');
422+
if (execution.task && execution.task.execution && CustomExecutionDTO.is(execution.task.execution) && event.resolvedVariables) {
423+
const dictionary: IStringDictionary<string> = {};
424+
Array.from(event.resolvedVariables.entries()).forEach(entry => dictionary[entry[0]] = entry[1]);
425+
resolvedDefinition = await this._configurationResolverService.resolveAny(task.getWorkspaceFolder(),
426+
execution.task.definition, dictionary);
425427
}
426428
this._proxy.$onDidStartTask(execution, event.terminalId!, resolvedDefinition);
427429
} else if (event.kind === TaskEventKind.ProcessStarted) {

src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ class InstanceManager {
8181

8282
class VariableResolver {
8383

84-
constructor(public workspaceFolder: IWorkspaceFolder | undefined, public taskSystemInfo: TaskSystemInfo | undefined, private _values: Map<string, string>, private _service: IConfigurationResolverService | undefined) {
84+
constructor(public workspaceFolder: IWorkspaceFolder | undefined, public taskSystemInfo: TaskSystemInfo | undefined, public readonly values: Map<string, string>, private _service: IConfigurationResolverService | undefined) {
8585
}
8686
resolve(value: string): string {
8787
return value.replace(/\$\{(.*?)\}/g, (match: string, variable: string) => {
8888
// Strip out the ${} because the map contains them variables without those characters.
89-
let result = this._values.get(match.substring(2, match.length - 1));
89+
let result = this.values.get(match.substring(2, match.length - 1));
9090
if ((result !== undefined) && (result !== null)) {
9191
return result;
9292
}
@@ -840,7 +840,7 @@ export class TerminalTaskSystem implements ITaskSystem {
840840
}, (_error) => {
841841
// The process never got ready. Need to think how to handle this.
842842
});
843-
this._onDidStateChange.fire(TaskEvent.create(TaskEventKind.Start, task, terminal.id));
843+
this._onDidStateChange.fire(TaskEvent.create(TaskEventKind.Start, task, terminal.id, resolver.values));
844844
const mapKey = task.getMapKey();
845845
this.busyTasks[mapKey] = task;
846846
this._onDidStateChange.fire(TaskEvent.create(TaskEventKind.Active, task));
@@ -1331,6 +1331,22 @@ export class TerminalTaskSystem implements ITaskSystem {
13311331
this.collectCommandVariables(variables, task.command, task);
13321332
}
13331333
this.collectMatcherVariables(variables, task.configurationProperties.problemMatchers);
1334+
1335+
if (task.command.runtime === RuntimeType.CustomExecution && CustomTask.is(task)) {
1336+
this.collectDefinitionVariables(variables, task._source.config.element);
1337+
}
1338+
}
1339+
1340+
private collectDefinitionVariables(variables: Set<string>, definition: any): void {
1341+
for (const key in definition) {
1342+
if (Types.isString(definition[key])) {
1343+
this.collectVariables(variables, definition[key]);
1344+
} else if (Types.isArray(definition[key])) {
1345+
definition[key].forEach((element: any) => this.collectDefinitionVariables(variables, element));
1346+
} else if (Types.isObject(definition[key])) {
1347+
this.collectDefinitionVariables(variables, definition[key]);
1348+
}
1349+
}
13341350
}
13351351

13361352
private collectCommandVariables(variables: Set<string>, command: CommandConfiguration, task: CustomTask | ContributedTask): void {

src/vs/workbench/contrib/tasks/common/tasks.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,7 @@ export interface TaskEvent {
10671067
exitCode?: number;
10681068
terminalId?: number;
10691069
__task?: Task;
1070+
resolvedVariables?: Map<string, string>;
10701071
}
10711072

10721073
export const enum TaskRunSource {
@@ -1078,10 +1079,10 @@ export const enum TaskRunSource {
10781079

10791080
export namespace TaskEvent {
10801081
export function create(kind: TaskEventKind.ProcessStarted | TaskEventKind.ProcessEnded, task: Task, processIdOrExitCode?: number): TaskEvent;
1081-
export function create(kind: TaskEventKind.Start, task: Task, terminalId?: number): TaskEvent;
1082+
export function create(kind: TaskEventKind.Start, task: Task, terminalId?: number, resolvedVariables?: Map<string, string>): TaskEvent;
10821083
export function create(kind: TaskEventKind.DependsOnStarted | TaskEventKind.Start | TaskEventKind.Active | TaskEventKind.Inactive | TaskEventKind.Terminated | TaskEventKind.End, task: Task): TaskEvent;
10831084
export function create(kind: TaskEventKind.Changed): TaskEvent;
1084-
export function create(kind: TaskEventKind, task?: Task, processIdOrExitCodeOrTerminalId?: number): TaskEvent {
1085+
export function create(kind: TaskEventKind, task?: Task, processIdOrExitCodeOrTerminalId?: number, resolvedVariables?: Map<string, string>): TaskEvent {
10851086
if (task) {
10861087
let result: TaskEvent = {
10871088
kind: kind,
@@ -1096,6 +1097,7 @@ export namespace TaskEvent {
10961097
};
10971098
if (kind === TaskEventKind.Start) {
10981099
result.terminalId = processIdOrExitCodeOrTerminalId;
1100+
result.resolvedVariables = resolvedVariables;
10991101
} else if (kind === TaskEventKind.ProcessStarted) {
11001102
result.processId = processIdOrExitCodeOrTerminalId;
11011103
} else if (kind === TaskEventKind.ProcessEnded) {

0 commit comments

Comments
 (0)