Skip to content

Commit

Permalink
Support tasks presentation received from plugins
Browse files Browse the repository at this point in the history
Support tasks presentation options received from plugins

This expands the functionality introduced in pull request eclipse-theia#6814

The following presentation options are now available for use by
plugins:

presentationOptions.reveal
presentationOptions.focus
presentationOptions.echo
presentationOptions.showReuseMessage
presentationOptions.panel
presentationOptions.clear

Signed-off-by: Alvaro Sanchez-Leon <alvaro.sanchez-leon@ericsson.com>
  • Loading branch information
alvsan09 committed Mar 29, 2021
1 parent 3420ef6 commit bb67b6b
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 10 deletions.
9 changes: 9 additions & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1319,10 +1319,19 @@ export interface TaskDto {
problemMatcher?: any;
group?: string;
detail?: string;
presentation?: TaskPresentationOptionsDTO;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
}

export interface TaskPresentationOptionsDTO {
reveal?: number;
focus?: boolean;
echo?: boolean;
panel?: number;
showReuseMessage?: boolean;
}

export interface TaskExecutionDto {
id: number;
task: TaskDto;
Expand Down
48 changes: 44 additions & 4 deletions packages/plugin-ext/src/main/browser/tasks-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,40 @@ import {
MAIN_RPC_CONTEXT,
TaskExecutionDto,
TasksExt,
TaskDto
TaskDto,
TaskPresentationOptionsDTO
} from '../../common/plugin-api-rpc';
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 } from '@theia/task/lib/common/task-protocol';
import { TaskInfo, TaskExitedEvent, TaskConfiguration, TaskCustomization, 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';

const revealKindMap = new Map<number | RevealKind, RevealKind | number>(
[
[1, RevealKind.Always],
[2, RevealKind.Silent],
[3, RevealKind.Never],
[RevealKind.Always, 1],
[RevealKind.Silent, 2],
[RevealKind.Never, 3]
]
);

const panelKindMap = new Map<number | PanelKind, PanelKind | number>(
[
[1, PanelKind.Shared],
[2, PanelKind.Dedicated],
[3, PanelKind.New],
[PanelKind.Shared, 1],
[PanelKind.Dedicated, 2],
[PanelKind.New, 3]
]
);

export class TasksMainImpl implements TasksMain, Disposable {
private readonly proxy: TasksExt;
private readonly taskProviderRegistry: TaskProviderRegistry;
Expand Down Expand Up @@ -175,19 +198,21 @@ export class TasksMainImpl implements TasksMain, Disposable {
}

protected toTaskConfiguration(taskDto: TaskDto): TaskConfiguration {
const { group, ...taskConfiguration } = taskDto;
const { group, presentation, ...taskConfiguration } = taskDto;
if (group === 'build' || group === 'test') {
taskConfiguration.group = group;
}

this.convertTaskPresentation(taskConfiguration, presentation);

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

protected fromTaskConfiguration(task: TaskConfiguration): TaskDto {
const { group, ...taskDto } = task;
const { group, presentation, ...taskDto } = task;
if (group) {
if (TaskCustomization.isBuildTask(task)) {
taskDto.group = 'build';
Expand All @@ -196,10 +221,25 @@ export class TasksMainImpl implements TasksMain, Disposable {
}
}

this.convertTaskPresentation(taskDto, presentation);

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

private convertTaskPresentation(task: TaskConfiguration | TaskDto,
presentationFrom: TaskOutputPresentation | TaskPresentationOptionsDTO | undefined): void {
if (presentationFrom) {
const { reveal, panel, ...presentationTo } = presentationFrom;
if (reveal) {
Object.assign(presentationTo, { reveal: revealKindMap.get(reveal) });
}
if (panel) {
Object.assign(presentationTo, { panel: panelKindMap.get(panel) });
}
Object.assign(task, { presentation: presentationTo });
}
}
}
8 changes: 8 additions & 0 deletions packages/plugin-ext/src/plugin/type-converters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ describe('Type converters:', () => {
args,
options: { cwd },
additionalProperty,
presentation: {
reveal: 3,
focus: true
},
group: groupDto
};

Expand All @@ -215,6 +219,10 @@ describe('Type converters:', () => {
type: shellType,
additionalProperty
},
presentationOptions: {
reveal: types.TaskRevealKind.Never,
focus: true
},
group,
execution: {
command,
Expand Down
11 changes: 10 additions & 1 deletion packages/plugin-ext/src/plugin/type-converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ export function fromTask(task: theia.Task): TaskDto | undefined {
const taskDto = {} as TaskDto;
taskDto.label = task.name;
taskDto.source = task.source;

if ((task as types.Task).hasProblemMatchers) {
taskDto.problemMatcher = task.problemMatchers;
}
Expand All @@ -720,6 +721,10 @@ export function fromTask(task: theia.Task): TaskDto | undefined {
taskDto.scope = task.scope;
}

if (task.presentationOptions) {
taskDto.presentation = task.presentationOptions;
}

const group = task.group;
if (group === TaskGroup.Build) {
taskDto.group = BUILD_GROUP;
Expand Down Expand Up @@ -761,7 +766,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, group, ...properties } = taskDto;
const { type, label, source, scope, problemMatcher, detail, command, args, options, windows, group, presentation, ...properties } = taskDto;
const result = {} as theia.Task;
result.name = label;
result.source = source;
Expand Down Expand Up @@ -803,6 +808,10 @@ export function toTask(taskDto: TaskDto): theia.Task {
}
}

if (presentation) {
result.presentationOptions = presentation;
}

if (!properties) {
return result;
}
Expand Down
11 changes: 6 additions & 5 deletions packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@ export class Task {
private isTaskBackground: boolean;
private taskSource: string;
private taskGroup: TaskGroup | undefined;
private taskPresentationOptions: theia.TaskPresentationOptions | undefined;
private taskPresentationOptions: theia.TaskPresentationOptions;
constructor(
taskDefinition: theia.TaskDefinition,
scope: theia.WorkspaceFolder | theia.TaskScope.Global | theia.TaskScope.Workspace,
Expand Down Expand Up @@ -1774,6 +1774,7 @@ export class Task {
this.hasTaskProblemMatchers = false;
}
this.isTaskBackground = false;
this.presentationOptions = Object.create(null);
}

get definition(): theia.TaskDefinition {
Expand Down Expand Up @@ -1873,13 +1874,13 @@ export class Task {
this.taskGroup = value;
}

get presentationOptions(): theia.TaskPresentationOptions | undefined {
get presentationOptions(): theia.TaskPresentationOptions {
return this.taskPresentationOptions;
}

set presentationOptions(value: theia.TaskPresentationOptions | undefined) {
if (value === null) {
value = undefined;
set presentationOptions(value: theia.TaskPresentationOptions) {
if (value === null || value === undefined) {
value = Object.create(null);
}
this.taskPresentationOptions = value;
}
Expand Down

0 comments on commit bb67b6b

Please sign in to comment.