Skip to content

Commit 12017ab

Browse files
committedDec 2, 2022
Add support for TaskGroup.id and isDefault. Fixes eclipse-theia#11519
Adds support for id and isDefault and includes a small drive-by fix in the Task implementation where the taskRunOptions object was not properly initialized. Contributed on behalf of ST Microelectronics Signed-off-by: Thomas Mäder <[email protected]>
1 parent e1f52db commit 12017ab

File tree

7 files changed

+58
-41
lines changed

7 files changed

+58
-41
lines changed
 

‎packages/plugin-ext/src/common/plugin-api-rpc.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,7 @@ export interface CommandProperties {
14441444
};
14451445
}
14461446

1447+
export type TaskGroupKind = 'build' | 'test' | 'rebuild' | 'clean'
14471448
export interface TaskDto {
14481449
type: string;
14491450
taskType?: 'shell' | 'process' | 'customExecution'; // the task execution type
@@ -1454,7 +1455,10 @@ export interface TaskDto {
14541455
// Provide a more specific type when necessary (see ProblemMatcherContribution)
14551456
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14561457
problemMatcher?: any;
1457-
group?: string;
1458+
group?: {
1459+
kind: TaskGroupKind;
1460+
isDefault: boolean;
1461+
}
14581462
detail?: string;
14591463
presentation?: TaskPresentationOptionsDTO;
14601464
runOptions?: RunOptionsDTO;

‎packages/plugin-ext/src/main/browser/tasks-main.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { RPCProtocol } from '../../common/rpc-protocol';
2626
import { Disposable, DisposableCollection } from '@theia/core/lib/common';
2727
import { TaskProviderRegistry, TaskResolverRegistry, TaskProvider, TaskResolver } from '@theia/task/lib/browser/task-contribution';
2828
import { interfaces } from '@theia/core/shared/inversify';
29-
import { TaskInfo, TaskExitedEvent, TaskConfiguration, TaskCustomization, TaskOutputPresentation, RevealKind, PanelKind } from '@theia/task/lib/common/task-protocol';
29+
import { TaskInfo, TaskExitedEvent, TaskConfiguration, TaskOutputPresentation, RevealKind, PanelKind } from '@theia/task/lib/common/task-protocol';
3030
import { TaskWatcher } from '@theia/task/lib/common/task-watcher';
3131
import { TaskService } from '@theia/task/lib/browser/task-service';
3232
import { TaskDefinitionRegistry } from '@theia/task/lib/browser';
@@ -207,8 +207,11 @@ export class TasksMainImpl implements TasksMain, Disposable {
207207
if (presentation) {
208208
partialConfig.presentation = this.convertTaskPresentation(presentation);
209209
}
210-
if (group === 'build' || group === 'test') {
211-
partialConfig.group = group;
210+
if (group) {
211+
partialConfig.group = {
212+
kind: group.kind,
213+
isDefault: group.isDefault
214+
};
212215
}
213216
return {
214217
...common,
@@ -225,12 +228,13 @@ export class TasksMainImpl implements TasksMain, Disposable {
225228
if (presentation) {
226229
partialDto.presentation = this.convertTaskPresentation(presentation);
227230
}
228-
if (group) {
229-
if (TaskCustomization.isBuildTask(task)) {
230-
partialDto.group = 'build';
231-
} else if (TaskCustomization.isTestTask(task)) {
232-
partialDto.group = 'test';
233-
}
231+
if (group === 'build' || group === 'test') {
232+
partialDto.group = {
233+
kind: group,
234+
isDefault: false
235+
};
236+
} else if (typeof group === 'object') {
237+
partialDto.group = group;
234238
}
235239
return {
236240
...common,

‎packages/plugin-ext/src/plugin/type-converters.spec.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ describe('Type converters:', () => {
185185
const args = ['run', 'build'];
186186
const cwd = '/projects/theia';
187187
const additionalProperty = 'some property';
188-
const groupDto = 'build';
189188
const group = TaskGroup.Build;
190189

191190
const shellTaskDto: TaskDto = {
@@ -202,7 +201,10 @@ describe('Type converters:', () => {
202201
reveal: 3,
203202
focus: true
204203
},
205-
group: groupDto,
204+
group: {
205+
kind: 'build',
206+
isDefault: false
207+
},
206208
runOptions: {
207209
reevaluateOnRerun: false
208210
}

‎packages/plugin-ext/src/plugin/type-converters.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ import { MarkdownString as MarkdownStringDTO } from '@theia/core/lib/common/mark
3131

3232
const SIDE_GROUP = -2;
3333
const ACTIVE_GROUP = -1;
34-
const BUILD_GROUP = 'build';
35-
const TEST_GROUP = 'test';
3634

3735
export function toViewColumn(ep?: EditorPosition): theia.ViewColumn | undefined {
3836
if (typeof ep !== 'number') {
@@ -846,11 +844,11 @@ export function fromTask(task: theia.Task): TaskDto | undefined {
846844
taskDto.presentation = task.presentationOptions;
847845
}
848846

849-
const group = task.group;
850-
if (group === types.TaskGroup.Build) {
851-
taskDto.group = BUILD_GROUP;
852-
} else if (group === types.TaskGroup.Test) {
853-
taskDto.group = TEST_GROUP;
847+
if (task.group) {
848+
taskDto.group = {
849+
kind: <rpc.TaskGroupKind>task.group.id,
850+
isDefault: !!task.group.isDefault
851+
};
854852
}
855853

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

938936
if (group) {
939-
if (group === BUILD_GROUP) {
940-
result.group = types.TaskGroup.Build;
941-
} else if (group === TEST_GROUP) {
942-
result.group = types.TaskGroup.Test;
943-
}
937+
result.group = new types.TaskGroup(
938+
group.kind,
939+
group.kind,
940+
group.isDefault
941+
);
944942
}
945943

946944
if (presentation) {

‎packages/plugin-ext/src/plugin/types-impl.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,6 @@ export class CustomExecution {
20082008

20092009
@es5ClassCompat
20102010
export class TaskGroup {
2011-
private groupId: string;
20122011

20132012
public static Clean: TaskGroup = new TaskGroup('clean', 'Clean');
20142013
public static Build: TaskGroup = new TaskGroup('build', 'Build');
@@ -2030,19 +2029,13 @@ export class TaskGroup {
20302029
}
20312030
}
20322031

2033-
constructor(id: string, label: string) {
2034-
if (typeof id !== 'string') {
2035-
throw illegalArgument('id');
2036-
}
2037-
if (typeof label !== 'string') {
2038-
throw illegalArgument('name');
2039-
}
2040-
this.groupId = id;
2032+
constructor(id: 'clean' | 'build' | 'rebuild' | 'test', label: string);
2033+
constructor(id: 'clean' | 'build' | 'rebuild' | 'test', label: string, isDefault?: boolean | undefined);
2034+
constructor(readonly id: 'clean' | 'build' | 'rebuild' | 'test', label: string, isDefault?: boolean | undefined) {
2035+
this.isDefault = !!isDefault;
20412036
}
20422037

2043-
get id(): string {
2044-
return this.groupId;
2045-
}
2038+
readonly isDefault: boolean;
20462039
}
20472040

20482041
export enum TaskScope {
@@ -2127,6 +2120,7 @@ export class Task {
21272120
}
21282121
this.isTaskBackground = false;
21292122
this.presentationOptions = Object.create(null);
2123+
this.taskRunOptions = Object.create(null);
21302124
}
21312125

21322126
get definition(): theia.TaskDefinition {

‎packages/plugin/src/theia.d.ts

+11
Original file line numberDiff line numberDiff line change
@@ -11513,6 +11513,17 @@ export module '@theia/plugin' {
1151311513
/** The test all task group */
1151411514
static Test: TaskGroup;
1151511515

11516+
/**
11517+
* Whether the task that is part of this group is the default for the group.
11518+
* This property cannot be set through API, and is controlled by a user's task configurations.
11519+
*/
11520+
readonly isDefault: boolean | undefined;
11521+
11522+
/**
11523+
* The ID of the task group. Is one of TaskGroup.Clean.id, TaskGroup.Build.id, TaskGroup.Rebuild.id, or TaskGroup.Test.id.
11524+
*/
11525+
readonly id: string;
11526+
1151611527
private constructor(id: string, label: string);
1151711528
}
1151811529

‎packages/task/src/common/task-protocol.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export namespace TaskOutputPresentation {
115115

116116
export interface TaskCustomization {
117117
type: string;
118-
group?: 'build' | 'test' | 'none' | { kind: 'build' | 'test', isDefault: true };
118+
group?: 'build' | 'test' | 'rebuild' | 'clean' | 'none' | { kind: 'build' | 'test' | 'rebuild' | 'clean', isDefault: boolean };
119119
problemMatcher?: string | ProblemMatcherContribution | (string | ProblemMatcherContribution)[];
120120
presentation?: TaskOutputPresentation;
121121
detail?: string;
@@ -136,19 +136,23 @@ export interface TaskCustomization {
136136
}
137137
export namespace TaskCustomization {
138138
export function isBuildTask(task: TaskCustomization): boolean {
139-
return task.group === 'build' || !!task.group && typeof task.group === 'object' && task.group.kind === 'build';
139+
return task.group === 'build' || typeof task.group === 'object' && task.group.kind === 'build';
140140
}
141141

142142
export function isDefaultBuildTask(task: TaskCustomization): boolean {
143-
return !!task.group && typeof task.group === 'object' && task.group.kind === 'build' && task.group.isDefault;
143+
return isDefaultTask(task) && isBuildTask(task);
144+
}
145+
146+
export function isDefaultTask(task: TaskCustomization): boolean {
147+
return typeof task.group === 'object' && task.group.isDefault;
144148
}
145149

146150
export function isTestTask(task: TaskCustomization): boolean {
147-
return task.group === 'test' || !!task.group && typeof task.group === 'object' && task.group.kind === 'test';
151+
return task.group === 'test' || typeof task.group === 'object' && task.group.kind === 'test';
148152
}
149153

150154
export function isDefaultTestTask(task: TaskCustomization): boolean {
151-
return !!task.group && typeof task.group === 'object' && task.group.kind === 'test' && task.group.isDefault;
155+
return isDefaultTask(task) && isTestTask(task);
152156
}
153157
}
154158

0 commit comments

Comments
 (0)