diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/workspace.tasks.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/workspace.tasks.test.ts index 0bd491abd0b..4ec107c23be 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/workspace.tasks.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/workspace.tasks.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; -import { window, tasks, Disposable, TaskDefinition, Task, EventEmitter, CustomExecution, Pseudoterminal, TaskScope, commands, Task2, env, UIKind, ShellExecution, TaskExecution, Terminal } from 'vscode'; +import { window, tasks, Disposable, TaskDefinition, Task, EventEmitter, CustomExecution, Pseudoterminal, TaskScope, commands, Task2, env, UIKind, ShellExecution, TaskExecution, Terminal, Event } from 'vscode'; // Disable tasks tests: // - Web https://github.com/microsoft/vscode/issues/90528 @@ -220,5 +220,54 @@ import { window, tasks, Disposable, TaskDefinition, Task, EventEmitter, CustomEx taskExecution = await tasks.executeTask(task); }); }); + + // https://github.com/microsoft/vscode/issues/100577 + test('A CustomExecution task can be fetched and executed', () => { + return new Promise(async (resolve, reject) => { + class CustomTerminal implements Pseudoterminal { + private readonly writeEmitter = new EventEmitter(); + public readonly onDidWrite: Event = this.writeEmitter.event; + public async close(): Promise { } + public open(): void { + this.close(); + resolve(); + } + } + + function buildTask(): Task { + const task = new Task( + { + type: 'customTesting', + }, + TaskScope.Workspace, + 'Test Task', + 'customTesting', + new CustomExecution( + async (): Promise => { + return new CustomTerminal(); + } + ) + ); + return task; + } + + disposables.push(tasks.registerTaskProvider('customTesting', { + provideTasks: () => { + return [buildTask()]; + }, + resolveTask(_task: Task): undefined { + return undefined; + } + })); + + const task = await tasks.fetchTasks({ type: 'customTesting' }); + + if (task && task.length > 0) { + await tasks.executeTask(task[0]); + } else { + reject('fetched task can\'t be undefined'); + } + }); + }); }); }); diff --git a/src/vs/workbench/api/browser/mainThreadTask.ts b/src/vs/workbench/api/browser/mainThreadTask.ts index 8b37ab49c14..a51b71d9fb2 100644 --- a/src/vs/workbench/api/browser/mainThreadTask.ts +++ b/src/vs/workbench/api/browser/mainThreadTask.ts @@ -328,10 +328,10 @@ namespace TaskDTO { result.detail = task.configurationProperties.detail; } if (!ConfiguringTask.is(task) && task.command) { - if (task.command.runtime === RuntimeType.Process) { - result.execution = ProcessExecutionDTO.from(task.command); - } else if (task.command.runtime === RuntimeType.Shell) { - result.execution = ShellExecutionDTO.from(task.command); + switch (task.command.runtime) { + case RuntimeType.Process: result.execution = ProcessExecutionDTO.from(task.command); break; + case RuntimeType.Shell: result.execution = ShellExecutionDTO.from(task.command); break; + case RuntimeType.CustomExecution: result.execution = CustomExecutionDTO.from(task.command); break; } } if (task.configurationProperties.problemMatchers) { diff --git a/src/vs/workbench/api/node/extHostTask.ts b/src/vs/workbench/api/node/extHostTask.ts index b785156b037..37776af324e 100644 --- a/src/vs/workbench/api/node/extHostTask.ts +++ b/src/vs/workbench/api/node/extHostTask.ts @@ -59,7 +59,7 @@ export class ExtHostTask extends ExtHostTaskBase { throw new Error('Task from execution DTO is undefined'); } const execution = await this.getTaskExecution(executionDTO, task); - this._proxy.$executeTask(executionDTO.task).catch(error => { throw new Error(error); }); + this._proxy.$executeTask(executionDTO.task).catch(() => { /* The error here isn't actionable. */ }); return execution; } else { const dto = TaskDTO.from(task, extension); @@ -75,7 +75,7 @@ export class ExtHostTask extends ExtHostTaskBase { } // Always get the task execution first to prevent timing issues when retrieving it later const execution = await this.getTaskExecution(await this._proxy.$getTaskExecution(dto), task); - this._proxy.$executeTask(dto).catch(error => { throw new Error(error); }); + this._proxy.$executeTask(dto).catch(() => { /* The error here isn't actionable. */ }); return execution; } }