Skip to content

Commit

Permalink
fix presentation.reveal & focus for detected tasks
Browse files Browse the repository at this point in the history
- default values of the taskConfig.presentation object are not taken into consideration when detected tasks are started. This pull request fixes the bug.
- fixes #7547

Signed-off-by: Liang Huang <[email protected]>
  • Loading branch information
elaihau committed Apr 14, 2020
1 parent c5d3708 commit c078fb8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## v1.1.0

- [task] fixed presentation.reveal & focus for detected tasks [#7548](https://github.com/eclipse-theia/theia/pull/7548)

Breaking changes:

- [core] Removed the `core.find` and `core.replace` commands as they did not work without the `@theia/monaco` extension, or an opened Monaco editor. Use the Monaco-specific `actions.find` and `editor.action.startFindReplaceAction` commands instead. [#7474](https://github.com/eclipse-theia/theia/issues/7474)
Expand Down
14 changes: 12 additions & 2 deletions packages/task/src/browser/provided-task-configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { inject, injectable } from 'inversify';
import { TaskProviderRegistry } from './task-contribution';
import { TaskDefinitionRegistry } from './task-definition-registry';
import { TaskConfiguration, TaskCustomization } from '../common';
import { TaskConfiguration, TaskCustomization, TaskOutputPresentation } from '../common';
import URI from '@theia/core/lib/common/uri';

@injectable()
Expand All @@ -40,7 +40,17 @@ export class ProvidedTaskConfigurations {
async getTasks(): Promise<TaskConfiguration[]> {
const providers = await this.taskProviderRegistry.getProviders();
const providedTasks: TaskConfiguration[] = (await Promise.all(providers.map(p => p.provideTasks())))
.reduce((acc, taskArray) => acc.concat(taskArray), []);
.reduce((acc, taskArray) => acc.concat(taskArray), [])
.map(providedTask => {
const originalPresentation = providedTask.presentation || {};
return {
...providedTask,
presentation: {
...TaskOutputPresentation.getDefault(),
...originalPresentation
}
};
});
this.cacheTasks(providedTasks);
return providedTasks;
}
Expand Down
13 changes: 7 additions & 6 deletions packages/task/src/browser/task-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ import {
TaskIdentifier,
DependsOrder,
RevealKind,
ApplyToKind
ApplyToKind,
TaskOutputPresentation
} from '../common';
import { TaskWatcher } from '../common/task-watcher';
import { ProvidedTaskConfigurations } from './provided-task-configurations';
Expand Down Expand Up @@ -701,10 +702,10 @@ export class TaskService implements TaskConfigurationClient {
const terminalId = matchedRunningTaskInfo.terminalId;
if (terminalId) {
const terminal = this.terminalService.getByTerminalId(terminalId);
if (terminal && task.presentation) {
if (task.presentation.focus) { // assign focus to the terminal if presentation.focus is true
if (terminal) {
if (TaskOutputPresentation.shouldSetFocusToTerminal(task)) { // assign focus to the terminal if presentation.focus is true
this.terminalService.open(terminal, { mode: 'activate' });
} else if (task.presentation.reveal === RevealKind.Always) { // show the terminal but not assign focus
} else if (TaskOutputPresentation.shouldAlwaysRevealTerminal(task)) { // show the terminal but not assign focus
this.terminalService.open(terminal, { mode: 'reveal' });
}
}
Expand Down Expand Up @@ -991,8 +992,8 @@ export class TaskService implements TaskConfigurationClient {
this.messageService.error('Task is already running in terminal');
return this.terminalService.open(terminalWidget, { mode: 'activate' });
}
if (taskInfo.config.presentation && taskInfo.config.presentation.reveal === RevealKind.Always) {
if (taskInfo.config.presentation.focus) { // assign focus to the terminal if presentation.focus is true
if (TaskOutputPresentation.shouldAlwaysRevealTerminal(taskInfo.config)) {
if (TaskOutputPresentation.shouldSetFocusToTerminal(taskInfo.config)) { // assign focus to the terminal if presentation.focus is true
widgetOpenMode = 'activate';
} else { // show the terminal but not assign focus
widgetOpenMode = 'reveal';
Expand Down
14 changes: 11 additions & 3 deletions packages/task/src/common/task-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@ export interface TaskOutputPresentation {
[name: string]: any;
}
export namespace TaskOutputPresentation {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function fromJson(task: any): TaskOutputPresentation {
let outputPresentation = {
export function getDefault(): TaskOutputPresentation {
return {
reveal: RevealKind.Always,
focus: false,
panel: PanelKind.Shared,
showReuseMessage: true,
clear: false
};
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function fromJson(task: any): TaskOutputPresentation {
let outputPresentation = getDefault();
if (task && task.presentation) {
if (task.presentation.reveal) {
let reveal = RevealKind.Always;
Expand Down Expand Up @@ -87,6 +91,10 @@ export namespace TaskOutputPresentation {
return outputPresentation;
}

export function shouldAlwaysRevealTerminal(task: TaskCustomization): boolean {
return !task.presentation || task.presentation.reveal === undefined || task.presentation.reveal === RevealKind.Always;
}

export function shouldSetFocusToTerminal(task: TaskCustomization): boolean {
return !!task.presentation && !!task.presentation.focus;
}
Expand Down

0 comments on commit c078fb8

Please sign in to comment.