Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tasks status incorrect #163393 #163952

Merged
merged 7 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/vs/workbench/contrib/tasks/browser/taskTerminalStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const INFO_TASK_STATUS: ITerminalStatus = { id: TASK_TERMINAL_STATUS_ID, icon: C
const INFO_INACTIVE_TASK_STATUS: ITerminalStatus = { id: TASK_TERMINAL_STATUS_ID, icon: Codicon.info, severity: Severity.Info, tooltip: nls.localize('taskTerminalStatus.infosInactive', "Task has infos and is waiting...") };

export class TaskTerminalStatus extends Disposable {
private terminalMap: Map<string, ITerminalData> = new Map();
private terminalMap: Map<number, ITerminalData> = new Map();
private _marker: IMarker | undefined;
constructor(@ITaskService taskService: ITaskService, @IAudioCueService private readonly _audioCueService: IAudioCueService) {
super();
Expand Down Expand Up @@ -67,15 +67,15 @@ export class TaskTerminalStatus extends Disposable {
this._marker?.dispose();
this._marker = undefined;
});
this.terminalMap.set(task._id, { terminal, task, status, problemMatcher, taskRunEnded: false });

this.terminalMap.set(terminal.instanceId, { terminal, task, status, problemMatcher, taskRunEnded: false });
}

private terminalFromEvent(event: ITaskEvent): ITerminalData | undefined {
if (!event.__task) {
if (!event.terminalId) {
return undefined;
}

return this.terminalMap.get(event.__task._id);
return this.terminalMap.get(event.terminalId);
}

private eventEnd(event: ITaskEvent) {
Expand Down Expand Up @@ -130,7 +130,7 @@ export class TaskTerminalStatus extends Disposable {
}
if (!terminalData.disposeListener) {
terminalData.disposeListener = terminalData.terminal.onDisposed(() => {
this.terminalMap.delete(event.__task?._id!);
this.terminalMap.delete(event.terminalId!);
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
terminalData.disposeListener?.dispose();
});
}
Expand Down
30 changes: 15 additions & 15 deletions src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,13 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
return new Promise<ITaskTerminateResponse>((resolve, reject) => {
const terminal = activeTerminal.terminal;
terminal.onDisposed(terminal => {
this._fireTaskEvent({ kind: TaskEventKind.Terminated, __task: task, exitReason: terminal.exitReason });
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Terminated, task, terminal.instanceId, terminal.exitReason));
});
const onExit = terminal.onExit(() => {
const task = activeTerminal.task;
try {
onExit.dispose();
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Terminated, task));
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Terminated, task, terminal.instanceId, terminal.exitReason));
} catch (error) {
// Do nothing.
}
Expand All @@ -501,7 +501,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
const task = terminalData.task;
try {
onExit.dispose();
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Terminated, task));
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Terminated, task, terminal.instanceId));
} catch (error) {
// Do nothing.
}
Expand Down Expand Up @@ -850,13 +850,13 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
if (event.kind === ProblemCollectorEventKind.BackgroundProcessingBegins) {
eventCounter++;
this._busyTasks[mapKey] = task;
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Active, task));
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Active, task, terminal?.instanceId));
} else if (event.kind === ProblemCollectorEventKind.BackgroundProcessingEnds) {
eventCounter--;
if (this._busyTasks[mapKey]) {
delete this._busyTasks[mapKey];
}
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Inactive, task));
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Inactive, task, terminal?.instanceId));
if (eventCounter === 0) {
if ((watchingProblemMatcher.numberOfMatches > 0) && watchingProblemMatcher.maxMarkerSeverity &&
(watchingProblemMatcher.maxMarkerSeverity >= MarkerSeverity.Error)) {
Expand Down Expand Up @@ -887,7 +887,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
let processStartedSignaled = false;
terminal.processReady.then(() => {
if (!processStartedSignaled) {
this._fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessStarted, task, terminal!.processId!));
this._fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessStarted, task, terminal!.instanceId!, terminal!.processId!));
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
processStartedSignaled = true;
}
}, (_error) => {
Expand Down Expand Up @@ -940,13 +940,13 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
watchingProblemMatcher.done();
watchingProblemMatcher.dispose();
if (!processStartedSignaled) {
this._fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessStarted, task, terminal!.processId!));
this._fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessStarted, task, terminal!.instanceId!, terminal!.processId!));
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
processStartedSignaled = true;
}
this._fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessEnded, task, exitCode ?? undefined));
this._fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessEnded, task, terminal!.instanceId!, exitCode ?? undefined));
meganrogge marked this conversation as resolved.
Show resolved Hide resolved

for (let i = 0; i < eventCounter; i++) {
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Inactive, task));
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Inactive, task, terminal!.instanceId!));
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
}
eventCounter = 0;
this._fireTaskEvent(TaskEvent.create(TaskEventKind.End, task));
Expand Down Expand Up @@ -982,7 +982,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
let processStartedSignaled = false;
terminal.processReady.then(() => {
if (!processStartedSignaled) {
this._fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessStarted, task, terminal!.processId!));
this._fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessStarted, task, terminal!.instanceId!));
mustard-mh marked this conversation as resolved.
Show resolved Hide resolved
processStartedSignaled = true;
}
}, (_error) => {
Expand All @@ -991,7 +991,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Start, task, terminal.instanceId, resolver.values));
const mapKey = task.getMapKey();
this._busyTasks[mapKey] = task;
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Active, task));
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Active, task, terminal.instanceId));
const problemMatchers = await this._resolveMatchers(resolver, task.configurationProperties.problemMatchers);
const startStopProblemMatcher = new StartStopProblemCollector(problemMatchers, this._markerService, this._modelService, ProblemHandlingStrategy.Clean, this._fileService);
this._terminalStatusManager.addTerminal(task, terminal, startStopProblemMatcher);
Expand Down Expand Up @@ -1038,16 +1038,16 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
startStopProblemMatcher.dispose();
}, 100);
if (!processStartedSignaled && terminal) {
this._fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessStarted, task, terminal.processId!));
this._fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessStarted, task, terminal.instanceId!));
mustard-mh marked this conversation as resolved.
Show resolved Hide resolved
processStartedSignaled = true;
}

this._fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessEnded, task, exitCode ?? undefined));
this._fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessEnded, task, terminal?.instanceId, exitCode ?? undefined));
if (this._busyTasks[mapKey]) {
delete this._busyTasks[mapKey];
}
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Inactive, task));
this._fireTaskEvent(TaskEvent.create(TaskEventKind.End, task));
this._fireTaskEvent(TaskEvent.create(TaskEventKind.Inactive, task, terminal?.instanceId));
this._fireTaskEvent(TaskEvent.create(TaskEventKind.End, task, terminal?.instanceId));
resolve({ exitCode: exitCode ?? undefined });
});
});
Expand Down
15 changes: 7 additions & 8 deletions src/vs/workbench/contrib/tasks/common/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1139,11 +1139,11 @@ export const enum TaskRunSource {
}

export namespace TaskEvent {
export function create(kind: TaskEventKind.ProcessStarted | TaskEventKind.ProcessEnded, task: Task, processIdOrExitCode?: number): ITaskEvent;
export function create(kind: TaskEventKind.ProcessStarted | TaskEventKind.ProcessEnded, task: Task, terminalId?: number, processIdOrExitCode?: number): ITaskEvent;
export function create(kind: TaskEventKind.Start, task: Task, terminalId?: number, resolvedVariables?: Map<string, string>): ITaskEvent;
export function create(kind: TaskEventKind.AcquiredInput | TaskEventKind.DependsOnStarted | TaskEventKind.Start | TaskEventKind.Active | TaskEventKind.Inactive | TaskEventKind.Terminated | TaskEventKind.End, task: Task, exitReason?: TerminalExitReason): ITaskEvent;
export function create(kind: TaskEventKind.AcquiredInput | TaskEventKind.DependsOnStarted | TaskEventKind.Start | TaskEventKind.Active | TaskEventKind.Inactive | TaskEventKind.Terminated | TaskEventKind.End, task: Task, terminalId?: number, exitReason?: TerminalExitReason): ITaskEvent;
export function create(kind: TaskEventKind.Changed): ITaskEvent;
export function create(kind: TaskEventKind, task?: Task, processIdOrExitCodeOrTerminalId?: number, resolvedVariables?: Map<string, string>, exitReason?: TerminalExitReason): ITaskEvent {
export function create(kind: TaskEventKind, task?: Task, terminalId?: number, resolvedVariablesORProcessIdOrExitCodeOrExitReason?: number | Map<string, string> | TerminalExitReason): ITaskEvent {
if (task) {
const result: ITaskEvent = {
kind: kind,
Expand All @@ -1153,16 +1153,15 @@ export namespace TaskEvent {
group: task.configurationProperties.group,
processId: undefined as number | undefined,
exitCode: undefined as number | undefined,
terminalId: undefined as number | undefined,
terminalId: terminalId,
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
__task: task
};
if (kind === TaskEventKind.Start) {
result.terminalId = processIdOrExitCodeOrTerminalId;
result.resolvedVariables = resolvedVariables;
result.resolvedVariables = resolvedVariablesORProcessIdOrExitCodeOrExitReason as Map<string, string>;
} else if (kind === TaskEventKind.ProcessStarted) {
result.processId = processIdOrExitCodeOrTerminalId;
result.processId = resolvedVariablesORProcessIdOrExitCodeOrExitReason as number;
} else if (kind === TaskEventKind.ProcessEnded) {
result.exitCode = processIdOrExitCodeOrTerminalId;
result.exitCode = resolvedVariablesORProcessIdOrExitCodeOrExitReason as number;
}
return Object.freeze(result);
} else {
Expand Down