Skip to content

Commit 40bda94

Browse files
committed
Custom executions get lost during fetchTasks
Fixes microsoft#100577
1 parent 447603c commit 40bda94

3 files changed

Lines changed: 56 additions & 7 deletions

File tree

extensions/vscode-api-tests/src/singlefolder-tests/workspace.tasks.test.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as assert from 'assert';
7-
import { window, tasks, Disposable, TaskDefinition, Task, EventEmitter, CustomExecution, Pseudoterminal, TaskScope, commands, Task2, env, UIKind, ShellExecution, TaskExecution, Terminal } from 'vscode';
7+
import { window, tasks, Disposable, TaskDefinition, Task, EventEmitter, CustomExecution, Pseudoterminal, TaskScope, commands, Task2, env, UIKind, ShellExecution, TaskExecution, Terminal, Event } from 'vscode';
88

99
// Disable tasks tests:
1010
// - Web https://github.com/microsoft/vscode/issues/90528
@@ -220,5 +220,54 @@ import { window, tasks, Disposable, TaskDefinition, Task, EventEmitter, CustomEx
220220
taskExecution = await tasks.executeTask(task);
221221
});
222222
});
223+
224+
// https://github.com/microsoft/vscode/issues/100577
225+
test('A CustomExecution task can be fetched and executed', () => {
226+
return new Promise(async (resolve, reject) => {
227+
class CustomTerminal implements Pseudoterminal {
228+
private readonly writeEmitter = new EventEmitter<string>();
229+
public readonly onDidWrite: Event<string> = this.writeEmitter.event;
230+
public async close(): Promise<void> { }
231+
public open(): void {
232+
this.close();
233+
resolve();
234+
}
235+
}
236+
237+
function buildTask(): Task {
238+
const task = new Task(
239+
{
240+
type: 'customTesting',
241+
},
242+
TaskScope.Workspace,
243+
'Test Task',
244+
'customTesting',
245+
new CustomExecution(
246+
async (): Promise<Pseudoterminal> => {
247+
return new CustomTerminal();
248+
}
249+
)
250+
);
251+
return task;
252+
}
253+
254+
disposables.push(tasks.registerTaskProvider('customTesting', {
255+
provideTasks: () => {
256+
return [buildTask()];
257+
},
258+
resolveTask(_task: Task): undefined {
259+
return undefined;
260+
}
261+
}));
262+
263+
const task = await tasks.fetchTasks({ type: 'customTesting' });
264+
265+
if (task && task.length > 0) {
266+
await tasks.executeTask(task[0]);
267+
} else {
268+
reject('fetched task can\'t be undefined');
269+
}
270+
});
271+
});
223272
});
224273
});

src/vs/workbench/api/browser/mainThreadTask.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ namespace TaskDTO {
328328
result.detail = task.configurationProperties.detail;
329329
}
330330
if (!ConfiguringTask.is(task) && task.command) {
331-
if (task.command.runtime === RuntimeType.Process) {
332-
result.execution = ProcessExecutionDTO.from(task.command);
333-
} else if (task.command.runtime === RuntimeType.Shell) {
334-
result.execution = ShellExecutionDTO.from(task.command);
331+
switch (task.command.runtime) {
332+
case RuntimeType.Process: result.execution = ProcessExecutionDTO.from(task.command); break;
333+
case RuntimeType.Shell: result.execution = ShellExecutionDTO.from(task.command); break;
334+
case RuntimeType.CustomExecution: result.execution = CustomExecutionDTO.from(task.command); break;
335335
}
336336
}
337337
if (task.configurationProperties.problemMatchers) {

src/vs/workbench/api/node/extHostTask.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class ExtHostTask extends ExtHostTaskBase {
5959
throw new Error('Task from execution DTO is undefined');
6060
}
6161
const execution = await this.getTaskExecution(executionDTO, task);
62-
this._proxy.$executeTask(executionDTO.task).catch(error => { throw new Error(error); });
62+
this._proxy.$executeTask(executionDTO.task).catch(() => { /* The error here isn't actionable. */ });
6363
return execution;
6464
} else {
6565
const dto = TaskDTO.from(task, extension);
@@ -75,7 +75,7 @@ export class ExtHostTask extends ExtHostTaskBase {
7575
}
7676
// Always get the task execution first to prevent timing issues when retrieving it later
7777
const execution = await this.getTaskExecution(await this._proxy.$getTaskExecution(dto), task);
78-
this._proxy.$executeTask(dto).catch(error => { throw new Error(error); });
78+
this._proxy.$executeTask(dto).catch(() => { /* The error here isn't actionable. */ });
7979
return execution;
8080
}
8181
}

0 commit comments

Comments
 (0)