提交 81cf7235 编写于 作者: A Alex Ross

Skip the task quick pick when only one task + setting

Related to https://github.com/microsoft/vscode/pull/47853
上级 ccbb0da0
......@@ -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';
......@@ -2022,6 +2023,8 @@ 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));
......@@ -2029,15 +2032,18 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
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 => {
......@@ -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;
});
}
......
......@@ -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
}
}
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册