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

use task map key #157810

Merged
merged 1 commit into from Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 9 additions & 15 deletions src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts
Expand Up @@ -55,8 +55,7 @@ import {
KeyedTaskIdentifier as KeyedTaskIdentifier, TaskDefinition, RuntimeType,
USER_TASKS_GROUP_KEY,
TaskSettingId,
TasksSchemaProperties,
TaskEventKind
TasksSchemaProperties
} from 'vs/workbench/contrib/tasks/common/tasks';
import { ITaskService, ITaskProvider, IProblemMatcherRunOptions, ICustomizationProperties, ITaskFilter, IWorkspaceFolderTaskResult, CustomExecutionSupportedContext, ShellExecutionSupportedContext, ProcessExecutionSupportedContext, TaskCommandsRegistered } from 'vs/workbench/contrib/tasks/common/taskService';
import { getTemplates as getTaskTemplates } from 'vs/workbench/contrib/tasks/common/taskTemplates';
Expand Down Expand Up @@ -87,7 +86,8 @@ import { IWorkspaceTrustManagementService, IWorkspaceTrustRequestService } from
import { VirtualWorkspaceContext } from 'vs/workbench/common/contextkeys';
import { Schemas } from 'vs/base/common/network';
import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite';
import { ILifecycleService, ShutdownReason, StartupKind } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { ILifecycleService, ShutdownReason } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { TerminalExitReason } from 'vs/platform/terminal/common/terminal';

const QUICKOPEN_HISTORY_LIMIT_CONFIG = 'task.quickOpen.history';
const PROBLEM_MATCHER_NEVER_CONFIG = 'task.problemMatchers.neverPrompt';
Expand Down Expand Up @@ -327,10 +327,9 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
this._willRestart = e.reason !== ShutdownReason.RELOAD;
});
this._register(this.onDidStateChange(e => {
if (this._willRestart) {
const key = e.__task?.getRecentlyUsedKey();
if (e.kind === TaskEventKind.End && key) {
this.removePersistentTask(key);
if (this._willRestart || e.exitReason === TerminalExitReason.User) {
if (e.taskId) {
this.removePersistentTask(e.taskId);
}
}
}));
Expand Down Expand Up @@ -369,12 +368,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
this._tasksReconnected = true;
return;
}
if (this._lifecycleService.startupKind !== StartupKind.ReloadedWindow) {
this._persistentTasks?.clear();
this._storageService.remove(AbstractTaskService.PersistentTasks_Key, StorageScope.WORKSPACE);
await this._storageService.flush();
return;
}

for (const task of tasks) {
if (ConfiguringTask.is(task)) {
const resolved = await this.tryResolveTask(task);
Expand Down Expand Up @@ -1096,7 +1090,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
if (!task.configurationProperties.problemMatchers || !this._tasksReconnected) {
return;
}
let key = task.getRecentlyUsedKey();
let key = task.getMapKey();
if (!InMemoryTask.is(task) && key) {
const customizations = this._createCustomizableTask(task);
if (ContributedTask.is(task) && customizations) {
Expand All @@ -1107,7 +1101,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
tasks: [customizations]
}, TaskRunSource.System, custom, customized, TaskConfig.TaskConfigSource.TasksJson, true);
for (const configuration in customized) {
key = customized[configuration].getRecentlyUsedKey()!;
key = customized[configuration].getMapKey()!;
}
}
this._getTasksFromStorage('persistent').set(key, JSON.stringify(customizations));
Expand Down
11 changes: 7 additions & 4 deletions src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts
Expand Up @@ -467,7 +467,9 @@ 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 });
});
const onExit = terminal.onExit(() => {
const task = activeTerminal.task;
try {
Expand Down Expand Up @@ -1280,7 +1282,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
for (let i = 0; i < this._reconnectedTerminals.length; i++) {
const terminal = this._reconnectedTerminals[i];
const taskForTerminal = terminal.shellLaunchConfig.attachPersistentProcess?.reconnectionProperties?.data as IReconnectionTaskData;
if (taskForTerminal.lastTask === task.getRecentlyUsedKey()) {
if (taskForTerminal.lastTask === task.getMapKey()) {
this._reconnectedTerminals.splice(i, 1);
return terminal;
}
Expand All @@ -1294,6 +1296,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
if ('command' in task && task.command.presentation) {
reconnectedTerminal.waitOnExit = getWaitOnExitValue(task.command.presentation, task.configurationProperties);
}
reconnectedTerminal.onDisposed((terminal) => this._fireTaskEvent({ kind: TaskEventKind.Terminated, exitReason: terminal.exitReason, taskId: task.getMapKey() }));
return reconnectedTerminal;
}
if (group) {
Expand All @@ -1314,6 +1317,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
// Either no group is used, no terminal with the group exists or splitting an existing terminal failed.
const createdTerminal = await this._terminalService.createTerminal({ location: TerminalLocation.Panel, config: launchConfigs });
this._logService.trace('Created a new task terminal');
createdTerminal.onDisposed((terminal) => this._fireTaskEvent({ kind: TaskEventKind.Terminated, exitReason: terminal.exitReason, taskId: task.getMapKey() }));
return createdTerminal;
}

Expand All @@ -1332,7 +1336,6 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
}
const terminalData = { lastTask: task.lastTask, group: task.group, terminal };
this._terminals[terminal.instanceId] = terminalData;
terminal.onDisposed(() => this._deleteTaskAndTerminal(terminal, terminalData));
}
this._hasReconnected = true;
}
Expand Down Expand Up @@ -1437,7 +1440,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {

this._terminalCreationQueue = this._terminalCreationQueue.then(() => this._doCreateTerminal(task, group, launchConfigs!));
const terminal: ITerminalInstance = (await this._terminalCreationQueue)!;
terminal.shellLaunchConfig.reconnectionProperties = { ownerId: ReconnectionType, data: { lastTask: task.getRecentlyUsedKey(), group, label: task._label, id: task._id } };
terminal.shellLaunchConfig.reconnectionProperties = { ownerId: ReconnectionType, data: { lastTask: taskKey, group, label: task._label, id: task._id } };
const terminalKey = terminal.instanceId.toString();
const terminalData = { terminal: terminal, lastTask: taskKey, group };
terminal.onDisposed(() => this._deleteTaskAndTerminal(terminal, terminalData));
Expand Down
6 changes: 4 additions & 2 deletions src/vs/workbench/contrib/tasks/common/tasks.ts
Expand Up @@ -16,6 +16,7 @@ import { RawContextKey, ContextKeyExpression } from 'vs/platform/contextkey/comm
import { TaskDefinitionRegistry } from 'vs/workbench/contrib/tasks/common/taskDefinitionRegistry';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { TerminalExitReason } from 'vs/platform/terminal/common/terminal';



Expand Down Expand Up @@ -1126,6 +1127,7 @@ export interface ITaskEvent {
terminalId?: number;
__task?: Task;
resolvedVariables?: Map<string, string>;
exitReason?: TerminalExitReason;
}

export const enum TaskRunSource {
Expand All @@ -1139,9 +1141,9 @@ 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.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): 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.Changed): ITaskEvent;
export function create(kind: TaskEventKind, task?: Task, processIdOrExitCodeOrTerminalId?: number, resolvedVariables?: Map<string, string>): ITaskEvent {
export function create(kind: TaskEventKind, task?: Task, processIdOrExitCodeOrTerminalId?: number, resolvedVariables?: Map<string, string>, exitReason?: TerminalExitReason): ITaskEvent {
if (task) {
const result: ITaskEvent = {
kind: kind,
Expand Down