Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take into account that TaskResolver can return undefined #1

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions packages/plugin-ext/src/main/browser/tasks-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ export class TasksMainImpl implements TasksMain, Disposable {

async $executeTask(taskDto: TaskDto): Promise<TaskExecutionDto | undefined> {
const taskConfig = this.toTaskConfiguration(taskDto);
if (!taskConfig) {
return undefined;
}
const taskInfo = await this.taskService.runTask(taskConfig);
if (taskInfo) {
return {
Expand Down Expand Up @@ -185,9 +188,9 @@ export class TasksMainImpl implements TasksMain, Disposable {
return {
provideTasks: () =>
this.proxy.$provideTasks(handle).then(v =>
v!.map(taskDto =>
this.toTaskConfiguration(taskDto)
)
v!
.map(taskDto => this.toTaskConfiguration(taskDto))
.filter(taskConfig => taskConfig !== undefined) as TaskConfiguration[]
)
};
}
Expand All @@ -196,12 +199,15 @@ export class TasksMainImpl implements TasksMain, Disposable {
return {
resolveTask: taskConfig =>
this.proxy.$resolveTask(handle, this.fromTaskConfiguration(taskConfig)).then(v =>
this.toTaskConfiguration(v!)
this.toTaskConfiguration(v)
)
};
}

protected toTaskConfiguration(taskDto: TaskDto): TaskConfiguration {
protected toTaskConfiguration(taskDto?: TaskDto): TaskConfiguration | undefined {
if (!taskDto) {
return undefined;
}
const { group, presentation, scope, source, ...common } = taskDto;
const partialConfig: Partial<TaskConfiguration> = {};
if (presentation) {
Expand Down
7 changes: 5 additions & 2 deletions packages/task/src/browser/task-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@ export interface TaskContribution {
export interface TaskResolver {
/**
* Resolves a `TaskConfiguration` before sending it for execution to the `TaskServer` (Backend).
*
* Note that a valid default implementation for the `resolveTask` method is to return `undefined`.
*
* @param taskConfig the configuration that should be resolved.
*
* @returns a promise of the resolved `TaskConfiguration`.
* @returns a promise of the resolved `TaskConfiguration` or `undefined`.
*/

resolveTask(taskConfig: TaskConfiguration): Promise<TaskConfiguration>;
resolveTask(taskConfig: TaskConfiguration): Promise<TaskConfiguration | undefined>;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/task/src/browser/task-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,10 @@ export class TaskService implements TaskConfigurationClient {
this.addRecentTasks(task);
try {
const resolver = await this.taskResolverRegistry.getTaskResolver(task.type);
const resolvedTask = resolver ? await resolver.resolveTask(task) : task;
const resolvedTask = resolver && await resolver.resolveTask(task) || task;
const executionResolver = this.taskResolverRegistry.getExecutionResolver(resolvedTask.taskType || resolvedTask.type);
overridePropertiesFunction(resolvedTask);
const taskToRun = executionResolver ? await executionResolver.resolveTask(resolvedTask) : resolvedTask;
const taskToRun = executionResolver && await executionResolver.resolveTask(resolvedTask) || resolvedTask;

await this.removeProblemMarkers(option);
return this.runResolvedTask(taskToRun, option);
Expand Down