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

Give more flexibility for tasks related sub classes #7765

Merged
merged 1 commit into from
May 12, 2020
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Breaking changes:

- [scm] support file tree mode in Source Control view. Classes that extend ScmWidget will likely require changes [#7505](https://github.com/eclipse-theia/theia/pull/7505)
- [task] removed `taskId` from `TaskTerminalWidgetOpenerOptions` [#7765](https://github.com/eclipse-theia/theia/pull/7765)

## v1.1.0

Expand Down
11 changes: 5 additions & 6 deletions packages/task/src/browser/task-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export class TaskService implements TaskConfigurationClient {
});
}

private getTaskIdentifier(taskConfig: TaskConfiguration): string {
protected getTaskIdentifier(taskConfig: TaskConfiguration): string {
const taskName = this.taskNameResolver.resolve(taskConfig);
const sourceStrUri = this.taskSourceResolver.resolve(taskConfig);
return `${taskName} (${this.labelProvider.getName(new URI(sourceStrUri))})`;
Expand Down Expand Up @@ -896,7 +896,7 @@ export class TaskService implements TaskConfigurationClient {
return customizationObject;
}

private async removeProblemMarkers(option?: RunTaskOption): Promise<void> {
protected async removeProblemMarkers(option?: RunTaskOption): Promise<void> {
if (option && option.customization) {
const matchersFromOption = option.customization.problemMatcher || [];
for (const matcher of matchersFromOption) {
Expand All @@ -910,7 +910,7 @@ export class TaskService implements TaskConfigurationClient {
}
}

private async getResolvedTask(task: TaskConfiguration): Promise<TaskConfiguration | undefined> {
protected async getResolvedTask(task: TaskConfiguration): Promise<TaskConfiguration | undefined> {
let resolver = undefined;
let resolvedTask: TaskConfiguration;
try {
Expand All @@ -930,7 +930,7 @@ export class TaskService implements TaskConfigurationClient {
* @param resolvedTask the resolved task
* @param option options to run the resolved task
*/
private async runResolvedTask(resolvedTask: TaskConfiguration, option?: RunTaskOption): Promise<TaskInfo | undefined> {
protected async runResolvedTask(resolvedTask: TaskConfiguration, option?: RunTaskOption): Promise<TaskInfo | undefined> {
const source = resolvedTask._source;
const taskLabel = resolvedTask.label;
try {
Expand All @@ -955,7 +955,7 @@ export class TaskService implements TaskConfigurationClient {
}
}

private getCustomizeProblemMatcherItems(): QuickPickItem<QuickPickProblemMatcherItem>[] {
protected getCustomizeProblemMatcherItems(): QuickPickItem<QuickPickProblemMatcherItem>[] {
const items: QuickPickItem<QuickPickProblemMatcherItem>[] = [];
items.push({
label: 'Continue without scanning the task output',
Expand Down Expand Up @@ -1035,7 +1035,6 @@ export class TaskService implements TaskConfigurationClient {
: `Task: #${taskId}`,
destroyTermOnClose: true
}, {
taskId,
widgetOptions: { area: 'bottom' },
mode: widgetOpenMode,
taskInfo
Expand Down
32 changes: 19 additions & 13 deletions packages/task/src/browser/task-terminal-widget-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ export namespace TaskTerminalWidget {
}

export interface TaskTerminalWidgetOpenerOptions extends WidgetOpenerOptions {
taskId: number;
taskConfig?: TaskConfiguration;
taskInfo?: TaskInfo;
}
export namespace TaskTerminalWidgetOpenerOptions {
export function isDedicatedTerminal(options: TaskTerminalWidgetOpenerOptions): boolean {
const taskConfig = options.taskInfo ? options.taskInfo.config : undefined;
const taskConfig = options.taskInfo ? options.taskInfo.config : options.taskConfig;
return !!taskConfig && !!taskConfig.presentation && taskConfig.presentation.panel === PanelKind.Dedicated;
}

export function isNewTerminal(options: TaskTerminalWidgetOpenerOptions): boolean {
const taskConfig = options.taskInfo ? options.taskInfo.config : undefined;
const taskConfig = options.taskInfo ? options.taskInfo.config : options.taskConfig;
return !!taskConfig && !!taskConfig.presentation && taskConfig.presentation.panel === PanelKind.New;
}

export function isSharedTerminal(options: TaskTerminalWidgetOpenerOptions): boolean {
const taskConfig = options.taskInfo ? options.taskInfo.config : undefined;
const taskConfig = options.taskInfo ? options.taskInfo.config : options.taskConfig;
return !!taskConfig && (taskConfig.presentation === undefined || taskConfig.presentation.panel === undefined || taskConfig.presentation.panel === PanelKind.Shared);
}

export function echoExecutedCommand(options: TaskTerminalWidgetOpenerOptions): boolean {
const taskConfig = options.taskInfo ? options.taskInfo.config : undefined;
const taskConfig = options.taskInfo ? options.taskInfo.config : options.taskConfig;
return !!taskConfig && (taskConfig.presentation === undefined || taskConfig.presentation.echo === undefined || taskConfig.presentation.echo);
}
}
Expand Down Expand Up @@ -126,9 +126,15 @@ export class TaskTerminalWidgetManager {
});
}

async newTaskTerminal(factoryOptions: TerminalWidgetFactoryOptions): Promise<TerminalWidget> {
return this.terminalService.newTerminal({ ...factoryOptions, kind: 'task' });
}

async open(factoryOptions: TerminalWidgetFactoryOptions, openerOptions: TaskTerminalWidgetOpenerOptions): Promise<TerminalWidget> {
const taskInfo = openerOptions.taskInfo;
const taskConfig = taskInfo ? taskInfo.config : openerOptions.taskConfig;
const dedicated = TaskTerminalWidgetOpenerOptions.isDedicatedTerminal(openerOptions);
if (dedicated && (!openerOptions.taskInfo || !openerOptions.taskInfo.config)) {
if (dedicated && !taskConfig) {
throw new Error('"taskConfig" must be included as part of the "option.taskInfo" if "isDedicated" is true');
}

Expand All @@ -140,13 +146,12 @@ export class TaskTerminalWidgetManager {
if (factoryOptions.title) {
widget.setTitle(factoryOptions.title);
}
const taskConfig = openerOptions.taskInfo ? openerOptions.taskInfo.config : undefined;
if (taskConfig && TaskOutputPresentation.shouldClearTerminalBeforeRun(taskConfig)) {
widget.clearOutput();
}
}
this.terminalService.open(widget, openerOptions);
const taskInfo = openerOptions.taskInfo;

if (TaskTerminalWidgetOpenerOptions.echoExecutedCommand(openerOptions) &&
taskInfo && ProcessTaskInfo.is(taskInfo) && taskInfo.command && taskInfo.command.length > 0
) {
Expand All @@ -159,14 +164,15 @@ export class TaskTerminalWidgetManager {
factoryOptions: TerminalWidgetFactoryOptions, openerOptions: TaskTerminalWidgetOpenerOptions
): Promise<{ isNew: boolean, widget: TerminalWidget }> {
let reusableTerminalWidget: TerminalWidget | undefined;
const taskConfig = openerOptions.taskInfo ? openerOptions.taskInfo.config : openerOptions.taskConfig;
if (TaskTerminalWidgetOpenerOptions.isDedicatedTerminal(openerOptions)) {
for (const widget of this.getTaskTerminalWidgets()) {
// to run a task whose `taskPresentation === 'dedicated'`, the terminal to be reused must be
// 1) dedicated, 2) idle, 3) the one that ran the same task
if (widget.dedicated &&
!widget.busy &&
widget.taskConfig && openerOptions.taskInfo &&
this.taskDefinitionRegistry.compareTasks(openerOptions.taskInfo.taskConfig, widget.taskConfig)) {
widget.taskConfig && taskConfig &&
this.taskDefinitionRegistry.compareTasks(taskConfig, widget.taskConfig)) {

reusableTerminalWidget = widget;
break;
Expand All @@ -190,17 +196,17 @@ export class TaskTerminalWidgetManager {

// we are unable to find a terminal widget to run the task, or `taskPresentation === 'new'`
if (!reusableTerminalWidget) {
const widget = await this.terminalService.newTerminal({ ...factoryOptions, kind: 'task' });
const widget = await this.newTaskTerminal(factoryOptions);
return { isNew: true, widget };
}
return { isNew: false, widget: reusableTerminalWidget };
}

private getTaskTerminalWidgets(): TaskTerminalWidget[] {
protected getTaskTerminalWidgets(): TaskTerminalWidget[] {
return this.terminalService.all.filter(TaskTerminalWidget.is);
}

private notifyTaskFinished(terminal: TaskTerminalWidget, showReuseMessage: boolean): void {
protected notifyTaskFinished(terminal: TaskTerminalWidget, showReuseMessage: boolean): void {
terminal.busy = false;
terminal.scrollToBottom();
if (showReuseMessage) {
Expand Down