Merge pull request #193486 from microsoft/merogge/task-reconnection

fire `onDidReconnectToTasks` when there are no task terminals to reconnect to so tasks run on `folderOpen`
This commit is contained in:
Megan Rogge
2023-09-19 12:44:52 -07:00
committed by GitHub
3 changed files with 12 additions and 10 deletions

View File

@@ -231,6 +231,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
public onDidChangeTaskSystemInfo: Event<void> = this._onDidChangeTaskSystemInfo.event;
private _onDidReconnectToTasks: Emitter<void> = new Emitter();
public onDidReconnectToTasks: Event<void> = this._onDidReconnectToTasks.event;
public get isReconnected(): boolean { return this._tasksReconnected; }
constructor(
@IConfigurationService private readonly _configurationService: IConfigurationService,
@@ -349,6 +350,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
this._attemptTaskReconnection();
} else {
this._tasksReconnected = true;
this._onDidReconnectToTasks.fire();
}
});
}

View File

@@ -28,19 +28,18 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
@IWorkspaceTrustManagementService private readonly _workspaceTrustManagementService: IWorkspaceTrustManagementService,
@ILogService private readonly _logService: ILogService) {
super();
this._taskService.onDidReconnectToTasks((() => {
if (this._workspaceTrustManagementService.isWorkspaceTrusted()) {
if (this._taskService.isReconnected) {
this._tryRunTasks();
} else {
this._register(Event.once(this._taskService.onDidReconnectToTasks)(async () => await this._tryRunTasks()));
}
}));
this._register(this._workspaceTrustManagementService.onDidChangeTrust(async trusted => {
if (trusted) {
await this._tryRunTasks();
}
}));
this._register(this._workspaceTrustManagementService.onDidChangeTrust(async () => await this._tryRunTasks()));
}
private async _tryRunTasks() {
if (!this._workspaceTrustManagementService.isWorkspaceTrusted()) {
return;
}
if (this._hasRunTasks || this._configurationService.getValue(ALLOW_AUTOMATIC_TASKS) === 'off') {
return;
}

View File

@@ -64,6 +64,7 @@ export interface IWorkspaceFolderTaskResult extends IWorkspaceTaskResult {
export interface ITaskService {
readonly _serviceBrand: undefined;
onDidStateChange: Event<ITaskEvent>;
isReconnected: boolean;
onDidReconnectToTasks: Event<void>;
supportsMultipleTaskExecutions: boolean;