Skip to content

Commit 81cf723

Browse files
committed
Skip the task quick pick when only one task + setting
Related to microsoft#47853
1 parent ccbb0da commit 81cf723

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cance
8383
const QUICKOPEN_HISTORY_LIMIT_CONFIG = 'task.quickOpen.history';
8484
const QUICKOPEN_DETAIL_CONFIG = 'task.quickOpen.detail';
8585
const PROBLEM_MATCHER_NEVER_CONFIG = 'task.problemMatchers.neverPrompt';
86+
const QUICKOPEN_SKIP_CONFIG = 'task.quickOpen.skip';
8687

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

20242025
private showQuickPick(tasks: Promise<Task[]> | Task[], placeHolder: string, defaultEntry?: TaskQuickPickEntry, group: boolean = false, sort: boolean = false, selectedEntry?: TaskQuickPickEntry, additionalEntries?: TaskQuickPickEntry[]): Promise<TaskQuickPickEntry | undefined | null> {
2026+
const tokenSource = new CancellationTokenSource();
2027+
const cancellationToken: CancellationToken = tokenSource.token;
20252028
let _createEntries = (): Promise<QuickPickInput<TaskQuickPickEntry>[]> => {
20262029
if (Array.isArray(tasks)) {
20272030
return Promise.resolve(this.createTaskQuickPickEntries(tasks, group, sort, selectedEntry));
20282031
} else {
20292032
return tasks.then((tasks) => this.createTaskQuickPickEntries(tasks, group, sort, selectedEntry));
20302033
}
20312034
};
2032-
return this.quickInputService.pick(_createEntries().then((entries) => {
2033-
if ((entries.length === 0) && defaultEntry) {
2035+
const pickEntries = _createEntries().then((entries) => {
2036+
if ((entries.length === 1) && this.configurationService.getValue<boolean>(QUICKOPEN_SKIP_CONFIG)) {
2037+
tokenSource.cancel();
2038+
} else if ((entries.length === 0) && defaultEntry) {
20342039
entries.push(defaultEntry);
20352040
} else if (entries.length > 1 && additionalEntries && additionalEntries.length > 0) {
20362041
entries.push({ type: 'separator', label: '' });
20372042
entries.push(additionalEntries[0]);
20382043
}
20392044
return entries;
2040-
}), {
2045+
});
2046+
return this.quickInputService.pick(pickEntries, {
20412047
placeHolder,
20422048
matchOnDescription: true,
20432049
onDidTriggerItemButton: context => {
@@ -2049,6 +2055,18 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
20492055
this.openConfig(task);
20502056
}
20512057
}
2058+
}, cancellationToken).then(async (selection) => {
2059+
if (cancellationToken.isCancellationRequested) {
2060+
// canceled when there's only one task
2061+
const task = (await pickEntries)[0];
2062+
if ((<any>task).task) {
2063+
selection = <TaskQuickPickEntry>task;
2064+
}
2065+
}
2066+
if (!selection) {
2067+
return;
2068+
}
2069+
return selection;
20522070
});
20532071
}
20542072

src/vs/workbench/contrib/tasks/browser/task.contribution.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ configurationRegistry.registerConfiguration({
367367
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."),
368368
type: 'boolean',
369369
default: true
370+
},
371+
'task.quickOpen.skip': {
372+
type: 'boolean',
373+
description: nls.localize('task.quickOpen.skip', "Controls whether the task quick pick is skipped when there is only one task to pick from."),
374+
default: false
370375
}
371376
}
372377
});

0 commit comments

Comments
 (0)