diff --git a/packages/plugin-ext/src/common/plugin-api-rpc.ts b/packages/plugin-ext/src/common/plugin-api-rpc.ts index abdf50bd740cf..172949bc3c10f 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc.ts @@ -1794,6 +1794,7 @@ export const MAIN_RPC_CONTEXT = { }; export interface TasksExt { + $initLoadedTasks(executions: TaskExecutionDto[]): Promise; $provideTasks(handle: number): Promise; $resolveTask(handle: number, task: TaskDto, token?: CancellationToken): Promise; $onDidStartTask(execution: TaskExecutionDto, terminalId: number): void; diff --git a/packages/plugin-ext/src/main/browser/tasks-main.ts b/packages/plugin-ext/src/main/browser/tasks-main.ts index 3f01afbc92ed2..34482b4cd94fb 100644 --- a/packages/plugin-ext/src/main/browser/tasks-main.ts +++ b/packages/plugin-ext/src/main/browser/tasks-main.ts @@ -97,6 +97,13 @@ export class TasksMainImpl implements TasksMain, Disposable { this.proxy.$onDidEndTaskProcess(event.code, event.taskId); } })); + + // Inform proxy about running tasks form previous session + this.$taskExecutions().then(executions => { + if (executions.length > 0) { + this.proxy.$initLoadedTasks(executions); + } + }); } dispose(): void { diff --git a/packages/plugin-ext/src/plugin/tasks/tasks.ts b/packages/plugin-ext/src/plugin/tasks/tasks.ts index b2d74ac735cfd..7d6487c33df87 100644 --- a/packages/plugin-ext/src/plugin/tasks/tasks.ts +++ b/packages/plugin-ext/src/plugin/tasks/tasks.ts @@ -24,7 +24,7 @@ import { import * as theia from '@theia/plugin'; import * as converter from '../type-converters'; import { CustomExecution, Disposable } from '../types-impl'; -import { RPCProtocol, ConnectionClosedError } from '../../common/rpc-protocol'; +import { RPCProtocol } from '../../common/rpc-protocol'; import { TaskProviderAdapter } from './task-provider'; import { Emitter, Event } from '@theia/core/lib/common/event'; import { TerminalServiceExtImpl } from '../terminal-ext'; @@ -49,15 +49,8 @@ export class TasksExtImpl implements TasksExt { private readonly onDidExecuteTaskProcess: Emitter = new Emitter(); private readonly onDidTerminateTaskProcess: Emitter = new Emitter(); - private disposed = false; - constructor(rpc: RPCProtocol, readonly terminalExt: TerminalServiceExtImpl) { this.proxy = rpc.getProxy(PLUGIN_RPC_CONTEXT.TASKS_MAIN); - this.fetchTaskExecutions(); - } - - dispose(): void { - this.disposed = true; } get taskExecutions(): ReadonlyArray { @@ -216,16 +209,9 @@ export class TasksExtImpl implements TasksExt { }); } - private async fetchTaskExecutions(): Promise { - try { - const taskExecutions = await this.proxy.$taskExecutions(); - taskExecutions.forEach(execution => this.getTaskExecution(execution)); - } catch (error) { - if (this.disposed && ConnectionClosedError.is(error)) { - return; - } - console.error(`Can not fetch running tasks: ${error}`); - } + // Initial `this.executions` map with the running tasks from the previous session + async $initLoadedTasks(taskExecutions: TaskExecutionDto[]): Promise { + taskExecutions.forEach(execution => this.getTaskExecution(execution)); } private getTaskExecution(execution: TaskExecutionDto): theia.TaskExecution {