Skip to content

Commit

Permalink
Add the display of configured tasks when executing 'configure tasks...'
Browse files Browse the repository at this point in the history
Fixed #5468

Added `configured` tasks when executing the command and menu item for `configure tasks...`.
Previously, only `provided` tasks were displayed which is inconsistent with vscode, and our
own implementation present in the command `run task...` which permits configuring all tasks using the `configure` icon. In order to be consistent, and align with vscode and our own
implementations, `configured` tasks should also be added to the menu.

Triggering the `configure` for any given task opens the `task.json`.

- fixed the deprecated import statements
- fixed the deprecated unused injection.

Signed-off-by: Vincent Fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Aug 7, 2019
1 parent d47d42e commit 7ab3104
Showing 1 changed file with 49 additions and 26 deletions.
75 changes: 49 additions & 26 deletions packages/task/src/browser/quick-open-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@
********************************************************************************/

import { inject, injectable } from 'inversify';
import {
QuickOpenService, QuickOpenModel, QuickOpenItem,
QuickOpenGroupItem, QuickOpenMode, QuickOpenHandler, QuickOpenOptions, QuickOpenActionProvider, QuickOpenGroupItemOptions
} from '@theia/core/lib/browser/quick-open/';
import { TaskService } from './task-service';
import { ContributedTaskConfiguration, TaskInfo, TaskConfiguration } from '../common/task-protocol';
import { TaskConfigurations } from './task-configurations';
import { TaskDefinitionRegistry } from './task-definition-registry';
import URI from '@theia/core/lib/common/uri';
import { TaskActionProvider } from './task-action-provider';
import { LabelProvider } from '@theia/core/lib/browser';
import { LabelProvider, QuickOpenHandler, QuickOpenService, QuickOpenOptions } from '@theia/core/lib/browser';
import { WorkspaceService } from '@theia/workspace/lib/browser';
import { TerminalService } from '@theia/terminal/lib/browser/base/terminal-service';
import { QuickOpenModel, QuickOpenItem, QuickOpenActionProvider, QuickOpenMode, QuickOpenGroupItem, QuickOpenGroupItemOptions } from '@theia/core/lib/common/quick-open-model';

@injectable()
export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
Expand All @@ -54,15 +50,14 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
@inject(WorkspaceService)
protected readonly workspaceService: WorkspaceService;

/**
* @deprecated To be removed in 0.5.0
*/
@inject(TaskConfigurations)
protected readonly taskConfigurations: TaskConfigurations;

@inject(TaskDefinitionRegistry)
protected readonly taskDefinitionRegistry: TaskDefinitionRegistry;

/**
* Flag which determines if a multi-root workspace is present or not.
*/
protected isMulti: boolean = false;

/** Initialize this quick open model with the tasks. */
async init(): Promise<void> {
const recentTasks = this.taskService.recentTasks;
Expand All @@ -71,19 +66,19 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {

const { filteredRecentTasks, filteredConfiguredTasks, filteredProvidedTasks } = this.getFilteredTasks(recentTasks, configuredTasks, providedTasks);
const stat = this.workspaceService.workspace;
const isMulti = stat ? !stat.isDirectory : false;
this.isMulti = stat ? !stat.isDirectory : false;
this.items = [];
this.items.push(
...filteredRecentTasks.map((task, index) => {
const item = new TaskRunQuickOpenItem(task, this.taskService, isMulti, {
const item = new TaskRunQuickOpenItem(task, this.taskService, this.isMulti, {
groupLabel: index === 0 ? 'recently used tasks' : undefined,
showBorder: false
});
item['taskDefinitionRegistry'] = this.taskDefinitionRegistry;
return item;
}),
...filteredConfiguredTasks.map((task, index) => {
const item = new TaskRunQuickOpenItem(task, this.taskService, isMulti, {
const item = new TaskRunQuickOpenItem(task, this.taskService, this.isMulti, {
groupLabel: index === 0 ? 'configured tasks' : undefined,
showBorder: (
filteredRecentTasks.length <= 0
Expand All @@ -95,7 +90,7 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
return item;
}),
...filteredProvidedTasks.map((task, index) => {
const item = new TaskRunQuickOpenItem(task, this.taskService, isMulti, {
const item = new TaskRunQuickOpenItem(task, this.taskService, this.isMulti, {
groupLabel: index === 0 ? 'detected tasks' : undefined,
showBorder: (
filteredRecentTasks.length <= 0 && filteredConfiguredTasks.length <= 0
Expand Down Expand Up @@ -173,22 +168,34 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
this.items = [];
this.actionProvider = undefined;

const configuredTasks = await this.taskService.getConfiguredTasks();
const providedTasks = await this.taskService.getProvidedTasks();
if (!providedTasks.length) {

if (!configuredTasks.length && !providedTasks.length) {
this.items.push(new QuickOpenItem({
label: 'No tasks found',
run: (_mode: QuickOpenMode): boolean => false
}));
}

providedTasks.forEach(task => {
this.items.push(new TaskConfigureQuickOpenItem(task, this.taskService, this.labelProvider));
});
const { filteredConfiguredTasks, filteredProvidedTasks } = this.getFilteredTasks([], configuredTasks, providedTasks);
this.items.push(
...filteredConfiguredTasks.map((task, index) => {
const item = new TaskConfigureQuickOpenItem(task, this.taskService, this.labelProvider, this.workspaceService, this.isMulti);
item['taskDefinitionRegistry'] = this.taskDefinitionRegistry;
return item;
}),
...filteredProvidedTasks.map((task, index) => {
const item = new TaskConfigureQuickOpenItem(task, this.taskService, this.labelProvider, this.workspaceService, this.isMulti);
item['taskDefinitionRegistry'] = this.taskDefinitionRegistry;
return item;
}),
);

this.quickOpenService.open(this, {
placeholder: 'Select a task to configure',
fuzzyMatchLabel: true,
fuzzySort: true
fuzzySort: false
});
}

Expand Down Expand Up @@ -312,23 +319,39 @@ export class TaskAttachQuickOpenItem extends QuickOpenItem {
}
export class TaskConfigureQuickOpenItem extends QuickOpenGroupItem {

protected taskDefinitionRegistry: TaskDefinitionRegistry;

constructor(
protected readonly task: TaskConfiguration,
protected readonly taskService: TaskService,
protected readonly labelProvider: LabelProvider
protected readonly labelProvider: LabelProvider,
protected readonly workspaceService: WorkspaceService,
protected readonly isMulti: boolean
) {
super();
const stat = this.workspaceService.workspace;
this.isMulti = stat ? !stat.isDirectory : false;
}

getLabel(): string {
return `${this.task._source}: ${this.task.label}`;
if (this.taskDefinitionRegistry && !!this.taskDefinitionRegistry.getDefinition(this.task)) {
return `${this.task._source}: ${this.task.label}`;
}
return `${this.task.type}: ${this.task.label}`;
}

getDescription(): string {
if (this.task._scope) {
return this.labelProvider.getLongName(new URI(this.task._scope));
if (!this.isMulti) {
return '';
}
if (this.taskDefinitionRegistry && !!this.taskDefinitionRegistry.getDefinition(this.task)) {
if (this.task._scope) {
return new URI(this.task._scope).displayName;
}
return this.task._source;
} else {
return new URI(this.task._source).displayName;
}
return this.task._source;
}

run(mode: QuickOpenMode): boolean {
Expand Down

0 comments on commit 7ab3104

Please sign in to comment.