Skip to content

Commit ac8b3ac

Browse files
Copilotmeganrogge
andauthored
Fix hasErrors property for compound task problem matcher events (microsoft#250784)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: meganrogge <[email protected]> Co-authored-by: meganrogge <[email protected]>
1 parent f9631e7 commit ac8b3ac

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

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

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
184184

185185
private _activeTasks: IStringDictionary<IActiveTerminalData>;
186186
private _busyTasks: IStringDictionary<Task>;
187+
private _taskErrors: IStringDictionary<boolean>; // Tracks which tasks had errors from problem matchers
188+
private _taskDependencies: IStringDictionary<string[]>; // Tracks which tasks depend on which other tasks
187189
private _terminals: IStringDictionary<ITerminalData>;
188190
private _idleTaskTerminals: LinkedMap<string, string>;
189191
private _sameTaskTerminals: IStringDictionary<string>;
@@ -243,6 +245,8 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
243245

244246
this._activeTasks = Object.create(null);
245247
this._busyTasks = Object.create(null);
248+
this._taskErrors = Object.create(null);
249+
this._taskDependencies = Object.create(null);
246250
this._terminals = Object.create(null);
247251
this._idleTaskTerminals = new LinkedMap<string, string>();
248252
this._sameTaskTerminals = Object.create(null);
@@ -528,6 +532,16 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
528532
const dependencyTask = await resolver.resolve(dependency.uri, dependency.task);
529533
if (dependencyTask) {
530534
this._adoptConfigurationForDependencyTask(dependencyTask, task);
535+
536+
// Track the dependency relationship
537+
const taskMapKey = task.getMapKey();
538+
const dependencyMapKey = dependencyTask.getMapKey();
539+
if (!this._taskDependencies[taskMapKey]) {
540+
this._taskDependencies[taskMapKey] = [];
541+
}
542+
if (!this._taskDependencies[taskMapKey].includes(dependencyMapKey)) {
543+
this._taskDependencies[taskMapKey].push(dependencyMapKey);
544+
}
531545
let taskResult;
532546
const commonKey = dependencyTask.getCommonTaskId();
533547
if (nextLiveDependencies.has(commonKey)) {
@@ -600,6 +614,33 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
600614
});
601615
}
602616

617+
private _taskHasErrors(task: Task): boolean {
618+
const taskMapKey = task.getMapKey();
619+
620+
// Check if this task itself had errors
621+
if (this._taskErrors[taskMapKey]) {
622+
return true;
623+
}
624+
625+
// Check if any tracked dependencies had errors
626+
const dependencies = this._taskDependencies[taskMapKey];
627+
if (dependencies) {
628+
for (const dependencyMapKey of dependencies) {
629+
if (this._taskErrors[dependencyMapKey]) {
630+
return true;
631+
}
632+
}
633+
}
634+
635+
return false;
636+
}
637+
638+
private _cleanupTaskTracking(task: Task): void {
639+
const taskMapKey = task.getMapKey();
640+
delete this._taskErrors[taskMapKey];
641+
delete this._taskDependencies[taskMapKey];
642+
}
643+
603644
private _adoptConfigurationForDependencyTask(dependencyTask: Task, task: Task): void {
604645
if (dependencyTask.configurationProperties.icon) {
605646
dependencyTask.configurationProperties.icon.id ||= task.configurationProperties.icon?.id;
@@ -852,6 +893,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
852893
if (eventCounter === 0) {
853894
if ((watchingProblemMatcher.numberOfMatches > 0) && watchingProblemMatcher.maxMarkerSeverity &&
854895
(watchingProblemMatcher.maxMarkerSeverity >= MarkerSeverity.Error)) {
896+
this._taskErrors[task.getMapKey()] = true;
855897
this._fireTaskEvent(TaskEvent.general(TaskEventKind.ProblemMatcherFoundErrors, task, terminal?.instanceId));
856898
const reveal = task.command.presentation!.reveal;
857899
const revealProblems = task.command.presentation!.revealProblems;
@@ -862,7 +904,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
862904
this._terminalGroupService.showPanel(false);
863905
}
864906
} else {
865-
this._fireTaskEvent(TaskEvent.general(TaskEventKind.ProblemMatcherEnded, task, terminal?.instanceId));
907+
this._fireTaskEvent(TaskEvent.problemMatcherEnded(task, this._taskHasErrors(task), terminal?.instanceId));
866908
}
867909
}
868910
}
@@ -1000,9 +1042,10 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
10001042
this._fireTaskEvent(TaskEvent.general(TaskEventKind.ProblemMatcherStarted, task, terminal?.instanceId));
10011043
} else if (event.kind === ProblemCollectorEventKind.BackgroundProcessingEnds) {
10021044
if (startStopProblemMatcher.numberOfMatches && startStopProblemMatcher.maxMarkerSeverity && startStopProblemMatcher.maxMarkerSeverity >= MarkerSeverity.Error) {
1045+
this._taskErrors[task.getMapKey()] = true;
10031046
this._fireTaskEvent(TaskEvent.general(TaskEventKind.ProblemMatcherFoundErrors, task, terminal?.instanceId));
10041047
} else {
1005-
this._fireTaskEvent(TaskEvent.general(TaskEventKind.ProblemMatcherEnded, task, terminal?.instanceId));
1048+
this._fireTaskEvent(TaskEvent.problemMatcherEnded(task, this._taskHasErrors(task), terminal?.instanceId));
10061049
}
10071050
}
10081051
}));
@@ -1069,11 +1112,13 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
10691112
}
10701113
this._fireTaskEvent(TaskEvent.general(TaskEventKind.Inactive, task, terminal?.instanceId));
10711114
if (startStopProblemMatcher.numberOfMatches && startStopProblemMatcher.maxMarkerSeverity && startStopProblemMatcher.maxMarkerSeverity >= MarkerSeverity.Error) {
1115+
this._taskErrors[task.getMapKey()] = true;
10721116
this._fireTaskEvent(TaskEvent.general(TaskEventKind.ProblemMatcherFoundErrors, task, terminal?.instanceId));
10731117
} else {
1074-
this._fireTaskEvent(TaskEvent.general(TaskEventKind.ProblemMatcherEnded, task, terminal?.instanceId));
1118+
this._fireTaskEvent(TaskEvent.problemMatcherEnded(task, this._taskHasErrors(task), terminal?.instanceId));
10751119
}
10761120
this._fireTaskEvent(TaskEvent.general(TaskEventKind.End, task, terminal?.instanceId));
1121+
this._cleanupTaskTracking(task);
10771122
resolve({ exitCode: exitCode ?? undefined });
10781123
});
10791124
});

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ export interface ITaskProblemMatcherEndedEvent extends ITaskCommon {
12031203
}
12041204

12051205
export interface ITaskGeneralEvent extends ITaskCommon {
1206-
kind: TaskEventKind.AcquiredInput | TaskEventKind.DependsOnStarted | TaskEventKind.Active | TaskEventKind.Inactive | TaskEventKind.End | TaskEventKind.ProblemMatcherEnded | TaskEventKind.ProblemMatcherStarted | TaskEventKind.ProblemMatcherFoundErrors;
1206+
kind: TaskEventKind.AcquiredInput | TaskEventKind.DependsOnStarted | TaskEventKind.Active | TaskEventKind.Inactive | TaskEventKind.End | TaskEventKind.ProblemMatcherStarted | TaskEventKind.ProblemMatcherFoundErrors;
12071207
terminalId: number | undefined;
12081208
}
12091209

@@ -1270,14 +1270,22 @@ export namespace TaskEvent {
12701270
};
12711271
}
12721272

1273-
export function general(kind: TaskEventKind.AcquiredInput | TaskEventKind.DependsOnStarted | TaskEventKind.Active | TaskEventKind.Inactive | TaskEventKind.End | TaskEventKind.ProblemMatcherEnded | TaskEventKind.ProblemMatcherStarted | TaskEventKind.ProblemMatcherFoundErrors, task: Task, terminalId?: number): ITaskGeneralEvent {
1273+
export function general(kind: TaskEventKind.AcquiredInput | TaskEventKind.DependsOnStarted | TaskEventKind.Active | TaskEventKind.Inactive | TaskEventKind.End | TaskEventKind.ProblemMatcherStarted | TaskEventKind.ProblemMatcherFoundErrors, task: Task, terminalId?: number): ITaskGeneralEvent {
12741274
return {
12751275
...common(task),
12761276
kind,
12771277
terminalId,
12781278
};
12791279
}
12801280

1281+
export function problemMatcherEnded(task: Task, hasErrors: boolean, terminalId?: number): ITaskProblemMatcherEndedEvent {
1282+
return {
1283+
...common(task),
1284+
kind: TaskEventKind.ProblemMatcherEnded,
1285+
hasErrors,
1286+
};
1287+
}
1288+
12811289
export function changed(): ITaskChangedEvent {
12821290
return { kind: TaskEventKind.Changed };
12831291
}

0 commit comments

Comments
 (0)