Custom executions get lost during fetchTasks

Fixes #100577
This commit is contained in:
Alex Ross 2020-06-22 18:36:19 +02:00
parent 447603c7dc
commit 40bda94ebc
3 changed files with 56 additions and 7 deletions

View file

@ -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<string>();
public readonly onDidWrite: Event<string> = this.writeEmitter.event;
public async close(): Promise<void> { }
public open(): void {
this.close();
resolve();
}
}
function buildTask(): Task {
const task = new Task(
{
type: 'customTesting',
},
TaskScope.Workspace,
'Test Task',
'customTesting',
new CustomExecution(
async (): Promise<Pseudoterminal> => {
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');
}
});
});
});
});

View file

@ -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) {

View file

@ -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;
}
}