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

Add support for TaskGroup.id and isDefault. #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,7 @@ export interface CommandProperties {
};
}

export type TaskGroupKind = 'build' | 'test' | 'rebuild' | 'clean';
export interface TaskDto {
type: string;
taskType?: 'shell' | 'process' | 'customExecution'; // the task execution type
Expand All @@ -1454,7 +1455,10 @@ 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;
group?: {
kind: TaskGroupKind;
isDefault: boolean;
}
detail?: string;
presentation?: TaskPresentationOptionsDTO;
runOptions?: RunOptionsDTO;
Expand Down
22 changes: 13 additions & 9 deletions packages/plugin-ext/src/main/browser/tasks-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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 '@theia/core/shared/inversify';
import { TaskInfo, TaskExitedEvent, TaskConfiguration, TaskCustomization, TaskOutputPresentation, RevealKind, PanelKind } from '@theia/task/lib/common/task-protocol';
import { TaskInfo, TaskExitedEvent, TaskConfiguration, TaskOutputPresentation, RevealKind, PanelKind } 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 @@ -207,8 +207,11 @@ export class TasksMainImpl implements TasksMain, Disposable {
if (presentation) {
partialConfig.presentation = this.convertTaskPresentation(presentation);
}
if (group === 'build' || group === 'test') {
partialConfig.group = group;
if (group) {
partialConfig.group = {
kind: group.kind,
isDefault: group.isDefault
};
}
return {
...common,
Expand All @@ -225,12 +228,13 @@ export class TasksMainImpl implements TasksMain, Disposable {
if (presentation) {
partialDto.presentation = this.convertTaskPresentation(presentation);
}
if (group) {
if (TaskCustomization.isBuildTask(task)) {
partialDto.group = 'build';
} else if (TaskCustomization.isTestTask(task)) {
partialDto.group = 'test';
}
if (group === 'build' || group === 'test') {
partialDto.group = {
kind: group,
isDefault: false
};
} else if (typeof group === 'object') {
partialDto.group = group;
}
return {
...common,
Expand Down
9 changes: 5 additions & 4 deletions packages/plugin-ext/src/plugin/type-converters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import * as model from '../common/plugin-api-rpc-model';
import { MarkdownString } from './markdown-string';
import { MarkdownString as MarkdownStringInterface } from '@theia/core/lib/common/markdown-rendering';
import { TaskDto } from '../common/plugin-api-rpc';
import { TaskGroup } from './types-impl';

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

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

const shellTaskDto: TaskDto = {
type: shellType,
Expand All @@ -202,7 +200,10 @@ describe('Type converters:', () => {
reveal: 3,
focus: true
},
group: groupDto,
group: {
kind: 'build',
isDefault: false
},
runOptions: {
reevaluateOnRerun: false
}
Expand Down
22 changes: 10 additions & 12 deletions packages/plugin-ext/src/plugin/type-converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import { MarkdownString as MarkdownStringDTO } from '@theia/core/lib/common/mark

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 @@ -846,11 +844,11 @@ export function fromTask(task: theia.Task): TaskDto | undefined {
taskDto.presentation = task.presentationOptions;
}

const group = task.group;
if (group === types.TaskGroup.Build) {
taskDto.group = BUILD_GROUP;
} else if (group === types.TaskGroup.Test) {
taskDto.group = TEST_GROUP;
if (task.group) {
taskDto.group = {
kind: <rpc.TaskGroupKind>task.group.id,
isDefault: !!task.group.isDefault
};
}

const taskDefinition = task.definition;
Expand Down Expand Up @@ -936,11 +934,11 @@ export function toTask(taskDto: TaskDto): theia.Task {
}

if (group) {
if (group === BUILD_GROUP) {
result.group = types.TaskGroup.Build;
} else if (group === TEST_GROUP) {
result.group = types.TaskGroup.Test;
}
result.group = new types.TaskGroup(
group.kind,
group.kind,
group.isDefault
);
}

if (presentation) {
Expand Down
18 changes: 6 additions & 12 deletions packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,6 @@ export class CustomExecution {

@es5ClassCompat
export class TaskGroup {
private groupId: string;

public static Clean: TaskGroup = new TaskGroup('clean', 'Clean');
public static Build: TaskGroup = new TaskGroup('build', 'Build');
Expand All @@ -2030,19 +2029,13 @@ export class TaskGroup {
}
}

constructor(id: string, label: string) {
if (typeof id !== 'string') {
throw illegalArgument('id');
}
if (typeof label !== 'string') {
throw illegalArgument('name');
}
this.groupId = id;
constructor(id: 'clean' | 'build' | 'rebuild' | 'test', label: string);
constructor(id: 'clean' | 'build' | 'rebuild' | 'test', label: string, isDefault?: boolean | undefined);
constructor(readonly id: 'clean' | 'build' | 'rebuild' | 'test', label: string, isDefault?: boolean | undefined) {
this.isDefault = !!isDefault;
}

get id(): string {
return this.groupId;
}
readonly isDefault: boolean;
}

export enum TaskScope {
Expand Down Expand Up @@ -2127,6 +2120,7 @@ export class Task {
}
this.isTaskBackground = false;
this.presentationOptions = Object.create(null);
this.taskRunOptions = Object.create(null);
}

get definition(): theia.TaskDefinition {
Expand Down
11 changes: 11 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11513,6 +11513,17 @@ export module '@theia/plugin' {
/** The test all task group */
static Test: TaskGroup;

/**
* Whether the task that is part of this group is the default for the group.
* This property cannot be set through API, and is controlled by a user's task configurations.
*/
readonly isDefault: boolean | undefined;

/**
* The ID of the task group. Is one of TaskGroup.Clean.id, TaskGroup.Build.id, TaskGroup.Rebuild.id, or TaskGroup.Test.id.
*/
readonly id: string;

private constructor(id: string, label: string);
}

Expand Down
14 changes: 9 additions & 5 deletions packages/task/src/common/task-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export namespace TaskOutputPresentation {

export interface TaskCustomization {
type: string;
group?: 'build' | 'test' | 'none' | { kind: 'build' | 'test', isDefault: true };
group?: 'build' | 'test' | 'rebuild' | 'clean' | 'none' | { kind: 'build' | 'test' | 'rebuild' | 'clean', isDefault: boolean };
problemMatcher?: string | ProblemMatcherContribution | (string | ProblemMatcherContribution)[];
presentation?: TaskOutputPresentation;
detail?: string;
Expand All @@ -136,19 +136,23 @@ export interface TaskCustomization {
}
export namespace TaskCustomization {
export function isBuildTask(task: TaskCustomization): boolean {
return task.group === 'build' || !!task.group && typeof task.group === 'object' && task.group.kind === 'build';
return task.group === 'build' || typeof task.group === 'object' && task.group.kind === 'build';
}

export function isDefaultBuildTask(task: TaskCustomization): boolean {
return !!task.group && typeof task.group === 'object' && task.group.kind === 'build' && task.group.isDefault;
return isDefaultTask(task) && isBuildTask(task);
}

export function isDefaultTask(task: TaskCustomization): boolean {
return typeof task.group === 'object' && task.group.isDefault;
}

export function isTestTask(task: TaskCustomization): boolean {
return task.group === 'test' || !!task.group && typeof task.group === 'object' && task.group.kind === 'test';
return task.group === 'test' || typeof task.group === 'object' && task.group.kind === 'test';
}

export function isDefaultTestTask(task: TaskCustomization): boolean {
return !!task.group && typeof task.group === 'object' && task.group.kind === 'test' && task.group.isDefault;
return isDefaultTask(task) && isTestTask(task);
}
}

Expand Down