Skip to content

Commit

Permalink
Skip the task quick pick when only one task + setting
Browse files Browse the repository at this point in the history
Related to #47853
  • Loading branch information
alexr00 committed Oct 24, 2019
1 parent ccbb0da commit 81cf723
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cance
const QUICKOPEN_HISTORY_LIMIT_CONFIG = 'task.quickOpen.history';
const QUICKOPEN_DETAIL_CONFIG = 'task.quickOpen.detail';
const PROBLEM_MATCHER_NEVER_CONFIG = 'task.problemMatchers.neverPrompt';
const QUICKOPEN_SKIP_CONFIG = 'task.quickOpen.skip';

export namespace ConfigureTaskAction {
export const ID = 'workbench.action.tasks.configureTaskRunner';
Expand Down Expand Up @@ -2022,22 +2023,27 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
}

private showQuickPick(tasks: Promise<Task[]> | Task[], placeHolder: string, defaultEntry?: TaskQuickPickEntry, group: boolean = false, sort: boolean = false, selectedEntry?: TaskQuickPickEntry, additionalEntries?: TaskQuickPickEntry[]): Promise<TaskQuickPickEntry | undefined | null> {
const tokenSource = new CancellationTokenSource();
const cancellationToken: CancellationToken = tokenSource.token;
let _createEntries = (): Promise<QuickPickInput<TaskQuickPickEntry>[]> => {
if (Array.isArray(tasks)) {
return Promise.resolve(this.createTaskQuickPickEntries(tasks, group, sort, selectedEntry));
} else {
return tasks.then((tasks) => this.createTaskQuickPickEntries(tasks, group, sort, selectedEntry));
}
};
return this.quickInputService.pick(_createEntries().then((entries) => {
if ((entries.length === 0) && defaultEntry) {
const pickEntries = _createEntries().then((entries) => {
if ((entries.length === 1) && this.configurationService.getValue<boolean>(QUICKOPEN_SKIP_CONFIG)) {
tokenSource.cancel();
} else if ((entries.length === 0) && defaultEntry) {
entries.push(defaultEntry);
} else if (entries.length > 1 && additionalEntries && additionalEntries.length > 0) {
entries.push({ type: 'separator', label: '' });
entries.push(additionalEntries[0]);
}
return entries;
}), {
});
return this.quickInputService.pick(pickEntries, {
placeHolder,
matchOnDescription: true,
onDidTriggerItemButton: context => {
Expand All @@ -2049,6 +2055,18 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
this.openConfig(task);
}
}
}, cancellationToken).then(async (selection) => {
if (cancellationToken.isCancellationRequested) {
// canceled when there's only one task
const task = (await pickEntries)[0];
if ((<any>task).task) {
selection = <TaskQuickPickEntry>task;
}
}
if (!selection) {
return;
}
return selection;
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/contrib/tasks/browser/task.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ configurationRegistry.registerConfiguration({
markdownDescription: nls.localize('task.quickOpen.detail', "Controls whether to show the task detail for task that have a detail in the Run Task quick pick."),
type: 'boolean',
default: true
},
'task.quickOpen.skip': {
type: 'boolean',
description: nls.localize('task.quickOpen.skip', "Controls whether the task quick pick is skipped when there is only one task to pick from."),
default: false
}
}
});

0 comments on commit 81cf723

Please sign in to comment.