Merge pull request #187322 from microsoft/merogge/fix-task-reconnection

This commit is contained in:
Megan Rogge
2023-07-10 12:25:41 -07:00
committed by GitHub
@@ -47,7 +47,7 @@ import { ITextFileService } from 'vs/workbench/services/textfile/common/textfile
import { ITerminalGroupService, ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal';
import { ITerminalProfileResolverService } from 'vs/workbench/contrib/terminal/common/terminal';
import { ConfiguringTask, ContributedTask, CustomTask, ExecutionEngine, InMemoryTask, ITaskEvent, ITaskIdentifier, ITaskSet, JsonSchemaVersion, KeyedTaskIdentifier, RuntimeType, Task, TaskDefinition, TaskEventKind, TaskGroup, TaskRunSource, TaskSettingId, TaskSorter, TaskSourceKind, TasksSchemaProperties, TASK_RUNNING_STATE, USER_TASKS_GROUP_KEY } from 'vs/workbench/contrib/tasks/common/tasks';
import { ConfiguringTask, ContributedTask, CustomTask, ExecutionEngine, InMemoryTask, ITaskEvent, ITaskIdentifier, ITaskSet, JsonSchemaVersion, KeyedTaskIdentifier, RuntimeType, Task, TASK_RUNNING_STATE, TaskDefinition, TaskEventKind, TaskGroup, TaskRunSource, TaskSettingId, TaskSorter, TaskSourceKind, TasksSchemaProperties, USER_TASKS_GROUP_KEY } from 'vs/workbench/contrib/tasks/common/tasks';
import { CustomExecutionSupportedContext, ICustomizationProperties, IProblemMatcherRunOptions, ITaskFilter, ITaskProvider, ITaskService, IWorkspaceFolderTaskResult, ProcessExecutionSupportedContext, ServerlessWebContext, ShellExecutionSupportedContext, TaskCommandsRegistered, TaskExecutionSupportedContext } from 'vs/workbench/contrib/tasks/common/taskService';
import { ITaskExecuteResult, ITaskResolver, ITaskSummary, ITaskSystem, ITaskSystemInfo, ITaskTerminateResponse, TaskError, TaskErrors, TaskExecuteKind } from 'vs/workbench/contrib/tasks/common/taskSystem';
import { getTemplates as getTaskTemplates } from 'vs/workbench/contrib/tasks/common/taskTemplates';
@@ -60,15 +60,18 @@ import { IQuickInputService, IQuickPick, IQuickPickItem, IQuickPickSeparator, Qu
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { TaskDefinitionRegistry } from 'vs/workbench/contrib/tasks/common/taskDefinitionRegistry';
import { raceTimeout } from 'vs/base/common/async';
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
import { once } from 'vs/base/common/functional';
import { toFormattedString } from 'vs/base/common/jsonFormatter';
import { Schemas } from 'vs/base/common/network';
import { ThemeIcon } from 'vs/base/common/themables';
import { IResolvedTextEditorModel, ITextModelService } from 'vs/editor/common/services/resolverService';
import { TextEditorSelectionRevealType } from 'vs/platform/editor/common/editor';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
import { TerminalExitReason } from 'vs/platform/terminal/common/terminal';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { ThemeIcon } from 'vs/base/common/themables';
import { IWorkspaceTrustManagementService, IWorkspaceTrustRequestService } from 'vs/platform/workspace/common/workspaceTrust';
import { VirtualWorkspaceContext } from 'vs/workbench/common/contextkeys';
import { EditorResourceAccessor, SaveReason } from 'vs/workbench/common/editor';
@@ -79,10 +82,7 @@ import { ILifecycleService, ShutdownReason, StartupKind } from 'vs/workbench/ser
import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite';
import { IPathService } from 'vs/workbench/services/path/common/pathService';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { TerminalExitReason } from 'vs/platform/terminal/common/terminal';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { raceTimeout } from 'vs/base/common/async';
const QUICKOPEN_HISTORY_LIMIT_CONFIG = 'task.quickOpen.history';
const PROBLEM_MATCHER_NEVER_CONFIG = 'task.problemMatchers.neverPrompt';
@@ -223,8 +223,10 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
protected _outputChannel: IOutputChannel;
protected readonly _onDidStateChange: Emitter<ITaskEvent>;
private _waitForSupportedExecutions: Promise<void>;
private _waitForOneSupportedExecution: Promise<void>;
private _waitForAllSupportedExecutions: Promise<void>;
private _onDidRegisterSupportedExecutions: Emitter<void> = new Emitter();
private _onDidRegisterAllSupportedExecutions: Emitter<void> = new Emitter();
private _onDidChangeTaskSystemInfo: Emitter<void> = new Emitter();
private _willRestart: boolean = false;
public onDidChangeTaskSystemInfo: Event<void> = this._onDidChangeTaskSystemInfo.event;
@@ -333,9 +335,12 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
this._setPersistentTask(e.__task);
}
}));
this._waitForSupportedExecutions = new Promise(resolve => {
this._waitForOneSupportedExecution = new Promise(resolve => {
once(this._onDidRegisterSupportedExecutions.event)(() => resolve());
});
this._waitForAllSupportedExecutions = new Promise(resolve => {
once(this._onDidRegisterAllSupportedExecutions.event)(() => resolve());
});
if (this._terminalService.getReconnectedTerminals('Task')?.length) {
this._attemptTaskReconnection();
} else {
@@ -365,6 +370,9 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
// update tasks so an incomplete list isn't returned when getWorkspaceTasks is called
this._workspaceTasksPromise = undefined;
this._onDidRegisterSupportedExecutions.fire();
if (custom && shell && process) {
this._onDidRegisterAllSupportedExecutions.fire();
}
}
private _attemptTaskReconnection(): void {
@@ -2201,7 +2209,12 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
if (!(await this._trust())) {
return new Map();
}
await this._waitForSupportedExecutions;
await this._waitForOneSupportedExecution;
if (runSource === TaskRunSource.Reconnect) {
await raceTimeout(this._waitForAllSupportedExecutions, 2000, () => {
this._logService.warn('Timed out waiting for all supported executions for task reconnection');
});
}
await this._whenTaskSystemReady;
if (this._workspaceTasksPromise) {
return this._workspaceTasksPromise;
@@ -2878,7 +2891,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
/**
*
* @param tasks - The tasks which need to be filtered
* @param taskGlobsInList - This tells splitPerGroupType to filter out globbed tasks (into defaults)
* @param tasksInList - This tells splitPerGroupType to filter out globbed tasks (into defaults)
* @returns
*/
private _getDefaultTasks(tasks: Task[], taskGlobsInList: boolean = false): Task[] {