diff --git a/packages/task/src/browser/quick-open-task.ts b/packages/task/src/browser/quick-open-task.ts index e5eae470680d8..400dd7c8651eb 100644 --- a/packages/task/src/browser/quick-open-task.ts +++ b/packages/task/src/browser/quick-open-task.ts @@ -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 { @@ -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 { const recentTasks = this.taskService.recentTasks; @@ -71,11 +66,11 @@ 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 }); @@ -83,7 +78,7 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { 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 @@ -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 @@ -173,17 +168,29 @@ 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.isMulti); + item['taskDefinitionRegistry'] = this.taskDefinitionRegistry; + return item; + }), + ...filteredProvidedTasks.map((task, index) => { + const item = new TaskConfigureQuickOpenItem(task, this.taskService, this.labelProvider, this.isMulti); + item['taskDefinitionRegistry'] = this.taskDefinitionRegistry; + return item; + }), + ); this.quickOpenService.open(this, { placeholder: 'Select a task to configure', @@ -312,23 +319,36 @@ 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 isMulti: boolean ) { super(); } 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 {