Skip to content

Commit

Permalink
Fix incomplete data in generated tasks.json
Browse files Browse the repository at this point in the history
* Added missing 'group' property to the TaskDto interface
* Added group when converting between TaskDto and TaskConfiguration
* Added group when converting between TaskDto and Task
* Removes clearing of problem matchers (error) to pass the received
ones from a given extension.
* Align TaskCustomization.group with task schema (i.e. remove 'none'
when 'isDefault').

#8950

Signed-off-by: Alvaro Sanchez-Leon <alvaro.sanchez-leon@ericsson.com>
  • Loading branch information
alvsan09 committed Jan 21, 2021
1 parent 47be972 commit 084be22
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,7 @@ export interface TaskDto {
// Provide a more specific type when necessary (see ProblemMatcherContribution)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
problemMatcher?: any;
group?: string;
detail?: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
Expand Down
28 changes: 21 additions & 7 deletions packages/plugin-ext/src/main/browser/tasks-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { RPCProtocol } from '../../common/rpc-protocol';
import { Disposable, DisposableCollection } from '@theia/core/lib/common';
import { TaskProviderRegistry, TaskResolverRegistry, TaskProvider, TaskResolver } from '@theia/task/lib/browser/task-contribution';
import { interfaces } from 'inversify';
import { TaskInfo, TaskExitedEvent, TaskConfiguration } from '@theia/task/lib/common/task-protocol';
import { TaskInfo, TaskExitedEvent, TaskConfiguration, TaskCustomization } from '@theia/task/lib/common/task-protocol';
import { TaskWatcher } from '@theia/task/lib/common/task-watcher';
import { TaskService } from '@theia/task/lib/browser/task-service';
import { TaskDefinitionRegistry } from '@theia/task/lib/browser';
Expand Down Expand Up @@ -175,16 +175,30 @@ export class TasksMainImpl implements TasksMain, Disposable {
}

protected toTaskConfiguration(taskDto: TaskDto): TaskConfiguration {
return Object.assign(taskDto, {
_source: taskDto.source,
_scope: taskDto.scope
const { group, ...taskConfiguration } = taskDto;
if (group === 'build' || group === 'test') {
taskConfiguration.group = group;
}

return Object.assign(taskConfiguration, {
_source: taskConfiguration.source,
_scope: taskConfiguration.scope
});
}

protected fromTaskConfiguration(task: TaskConfiguration): TaskDto {
return Object.assign(task, {
source: task._source,
scope: task._scope
const { group, ...taskDto } = task;
if (group) {
if (TaskCustomization.isBuildTask(task)) {
taskDto.group = 'build';
} else if (TaskCustomization.isTestTask(task)) {
taskDto.group = 'test';
}
}

return Object.assign(taskDto, {
source: taskDto._source,
scope: taskDto._scope
});
}

Expand Down
7 changes: 6 additions & 1 deletion packages/plugin-ext/src/plugin/type-converters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as types from './types-impl';
import * as model from '../common/plugin-api-rpc-model';
import { MarkdownString, isMarkdownString } from './markdown-string';
import { TaskDto } from '../common/plugin-api-rpc';
import { TaskGroup } from './types-impl';

describe('Type converters:', () => {

Expand Down Expand Up @@ -181,6 +182,8 @@ describe('Type converters:', () => {
const args = ['run', 'build'];
const cwd = '/projects/theia';
const additionalProperty = 'some property';
const groupDto = 'build';
const group = TaskGroup.Build;

const shellTaskDto: TaskDto = {
type: shellType,
Expand All @@ -190,7 +193,8 @@ describe('Type converters:', () => {
command,
args,
options: { cwd },
additionalProperty
additionalProperty,
group: groupDto
};

const shellTaskDtoWithCommandLine: TaskDto = {
Expand All @@ -211,6 +215,7 @@ describe('Type converters:', () => {
type: shellType,
additionalProperty
},
group,
execution: {
command,
args,
Expand Down
22 changes: 21 additions & 1 deletion packages/plugin-ext/src/plugin/type-converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ import { isMarkdownString, MarkdownString } from './markdown-string';
import { Item } from './quick-open';
import * as types from './types-impl';
import { UriComponents } from '../common/uri-components';
import { TaskGroup } from './types-impl';

const SIDE_GROUP = -2;
const ACTIVE_GROUP = -1;
const BUILD_GROUP = 'build';
const TEST_GROUP = 'test';

export function toViewColumn(ep?: EditorPosition): theia.ViewColumn | undefined {
if (typeof ep !== 'number') {
Expand Down Expand Up @@ -717,6 +720,15 @@ export function fromTask(task: theia.Task): TaskDto | undefined {
taskDto.scope = task.scope;
}

const group = task.group;
if (group) {
if (group === TaskGroup.Build) {
taskDto.group = BUILD_GROUP;
} else if (group === TaskGroup.Test) {
taskDto.group = TEST_GROUP;
}
}

const taskDefinition = task.definition;
if (!taskDefinition) {
return taskDto;
Expand Down Expand Up @@ -751,7 +763,7 @@ export function toTask(taskDto: TaskDto): theia.Task {
throw new Error('Task should be provided for converting');
}

const { type, label, source, scope, problemMatcher, detail, command, args, options, windows, ...properties } = taskDto;
const { type, label, source, scope, problemMatcher, detail, command, args, options, windows, group, ...properties } = taskDto;
const result = {} as theia.Task;
result.name = label;
result.source = source;
Expand Down Expand Up @@ -785,6 +797,14 @@ export function toTask(taskDto: TaskDto): theia.Task {
result.execution = getShellExecution(taskDto);
}

if (group) {
if (group === BUILD_GROUP) {
result.group = TaskGroup.Build;
} else if (group === TEST_GROUP) {
result.group = TaskGroup.Test;
}
}

if (!properties) {
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/task/src/browser/task-configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export class TaskConfigurations implements Disposable {

const configuredAndCustomizedTasks = await this.getTasks(token);
if (!configuredAndCustomizedTasks.some(t => this.taskDefinitionRegistry.compareTasks(t, task))) {
await this.saveTask(scope, { ...task, problemMatcher: [] });
await this.saveTask(scope, task);
}

try {
Expand Down
2 changes: 1 addition & 1 deletion packages/task/src/common/task-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export namespace TaskOutputPresentation {

export interface TaskCustomization {
type: string;
group?: 'build' | 'test' | 'none' | { kind: 'build' | 'test' | 'none', isDefault: true };
group?: 'build' | 'test' | 'none' | { kind: 'build' | 'test', isDefault: true };
problemMatcher?: string | ProblemMatcherContribution | (string | ProblemMatcherContribution)[];
presentation?: TaskOutputPresentation;
detail?: string;
Expand Down

0 comments on commit 084be22

Please sign in to comment.