diff --git a/packages/task/src/browser/quick-open-task.ts b/packages/task/src/browser/quick-open-task.ts index ee17b332d8018..343d77ea790f4 100644 --- a/packages/task/src/browser/quick-open-task.ts +++ b/packages/task/src/browser/quick-open-task.ts @@ -111,17 +111,22 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { ); this.actionProvider = this.items.length ? this.taskActionProvider : undefined; + } + async open(): Promise { + await this.init(); if (!this.items.length) { this.items.push(new QuickOpenItem({ - label: 'No tasks found', - run: (mode: QuickOpenMode): boolean => false + label: 'No task to run found. Configure Tasks...', + run: (mode: QuickOpenMode): boolean => { + if (mode !== QuickOpenMode.OPEN) { + return false; + } + this.configure(); + return true; + } })); } - } - - async open(): Promise { - await this.init(); this.quickOpenService.open(this, { placeholder: 'Select the task to run', fuzzyMatchLabel: true, @@ -262,12 +267,11 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { async runBuildOrTestTask(buildOrTestType: 'build' | 'test'): Promise { const shouldRunBuildTask = buildOrTestType === 'build'; await this.init(); + const buildOrTestTasks = this.items.filter((t: TaskRunQuickOpenItem) => + shouldRunBuildTask ? TaskCustomization.isBuildTask(t.getTask()) : TaskCustomization.isTestTask(t.getTask()) + ); if (this.items.length > 1 || this.items.length === 1 && (this.items[0] as TaskRunQuickOpenItem).getTask !== undefined) { // the item in `this.items` is not 'No tasks found' - - const buildOrTestTasks = this.items.filter((t: TaskRunQuickOpenItem) => - shouldRunBuildTask ? TaskCustomization.isBuildTask(t.getTask()) : TaskCustomization.isTestTask(t.getTask()) - ); this.actionProvider = undefined; if (buildOrTestTasks.length > 0) { // build / test tasks are defined in the workspace const defaultBuildOrTestTasks = buildOrTestTasks.filter((t: TaskRunQuickOpenItem) => @@ -290,7 +294,7 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { } else { // no build / test tasks, display an action item to configure the build / test task this.items = [new QuickOpenItem({ - label: `No ${buildOrTestType} task to run found. Configure ${buildOrTestType} task...`, + label: `No ${buildOrTestType} task to run found. Configure ${buildOrTestType.charAt(0).toUpperCase() + buildOrTestType.slice(1)} Task...`, run: (mode: QuickOpenMode): boolean => { if (mode !== QuickOpenMode.OPEN) { return false; @@ -322,6 +326,19 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler { } })]; } + } else { // no tasks are currently present, prompt users if they'd like to configure a task. + this.items = [ + new QuickOpenItem({ + label: `No ${buildOrTestType} task to run found. Configure ${buildOrTestType.charAt(0).toUpperCase() + buildOrTestType.slice(1)} Task...`, + run: (mode: QuickOpenMode): boolean => { + if (mode !== QuickOpenMode.OPEN) { + return false; + } + this.configure(); + return true; + } + }) + ]; } this.quickOpenService.open(this, {