Skip to content

Commit

Permalink
Prompt users to configure tasks
Browse files Browse the repository at this point in the history
Fixes #6525

- adjust the `run task` to display an item which prompts users to configure tasks when
no tasks are currently available.
- adjusts the `run build task` to display an item which prompts users to configure
tasks when no tasks are currently available.
- adjusts the `run test task` to display an item which prompts users to configure
tasks when no tasks are currently available.

Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Nov 12, 2019
1 parent a2d89c8 commit 8fc7da0
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions packages/task/src/browser/quick-open-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,22 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
);

this.actionProvider = this.items.length ? this.taskActionProvider : undefined;
}

async open(): Promise<void> {
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<void> {
await this.init();
this.quickOpenService.open(this, {
placeholder: 'Select the task to run',
fuzzyMatchLabel: true,
Expand Down Expand Up @@ -262,12 +267,11 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
async runBuildOrTestTask(buildOrTestType: 'build' | 'test'): Promise<void> {
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) =>
Expand All @@ -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;
Expand Down Expand Up @@ -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, {
Expand Down

0 comments on commit 8fc7da0

Please sign in to comment.