Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support pinning in Run Task quickpick #160565

Merged
merged 2 commits into from Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts
Expand Up @@ -80,6 +80,7 @@ import { IPathService } from 'vs/workbench/services/path/common/pathService';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { TerminalExitReason } from 'vs/platform/terminal/common/terminal';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';

const QUICKOPEN_HISTORY_LIMIT_CONFIG = 'task.quickOpen.history';
const PROBLEM_MATCHER_NEVER_CONFIG = 'task.problemMatchers.neverPrompt';
Expand Down Expand Up @@ -261,7 +262,8 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
@ILogService private readonly _logService: ILogService,
@IThemeService private readonly _themeService: IThemeService,
@ILifecycleService private readonly _lifecycleService: ILifecycleService,
@IRemoteAgentService remoteAgentService: IRemoteAgentService
@IRemoteAgentService remoteAgentService: IRemoteAgentService,
@IInstantiationService private readonly _instantiationService: IInstantiationService
) {
super();

Expand Down Expand Up @@ -2639,7 +2641,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
return entries;
}
private async _showTwoLevelQuickPick(placeHolder: string, defaultEntry?: ITaskQuickPickEntry, type?: string, name?: string) {
return TaskQuickPick.show(this, this._configurationService, this._quickInputService, this._notificationService, this._dialogService, this._themeService, placeHolder, defaultEntry, type, name);
return this._instantiationService.createInstance(TaskQuickPick).show(placeHolder, defaultEntry, type, name);
}

private async _showQuickPick(tasks: Promise<Task[]> | Task[], placeHolder: string, defaultEntry?: ITaskQuickPickEntry, group: boolean = false, sort: boolean = false, selectedEntry?: ITaskQuickPickEntry, additionalEntries?: ITaskQuickPickEntry[], type?: string, name?: string): Promise<ITaskQuickPickEntry | undefined | null> {
Expand Down Expand Up @@ -3268,7 +3270,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
if (this._isTaskEntry(selection)) {
this._configureTask(selection.task);
} else if (this._isSettingEntry(selection)) {
const taskQuickPick = new TaskQuickPick(this, this._configurationService, this._quickInputService, this._notificationService, this._themeService, this._dialogService);
const taskQuickPick = this._instantiationService.createInstance(TaskQuickPick);
taskQuickPick.handleSettingOption(selection.settingType);
} else if (selection.folder && (this._contextService.getWorkbenchState() !== WorkbenchState.EMPTY)) {
this._openTaskFile(selection.folder.toResource('.vscode/tasks.json'), TaskSourceKind.Workspace);
Expand Down
31 changes: 14 additions & 17 deletions src/vs/workbench/contrib/tasks/browser/taskQuickPick.ts
Expand Up @@ -21,6 +21,8 @@ import { registerIcon } from 'vs/platform/theme/common/iconRegistry';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { getColorClass, getColorStyleElement } from 'vs/workbench/contrib/terminal/browser/terminalIcon';
import { TaskQuickPickEntryType } from 'vs/workbench/contrib/tasks/browser/abstractTaskService';
import { showWithPinnedItems } from 'vs/platform/quickinput/browser/quickPickPin';
import { IStorageService } from 'vs/platform/storage/common/storage';

export const QUICKOPEN_DETAIL_CONFIG = 'task.quickOpen.detail';
export const QUICKOPEN_SKIP_CONFIG = 'task.quickOpen.skip';
Expand All @@ -42,16 +44,19 @@ const SHOW_ALL: string = nls.localize('taskQuickPick.showAll', "Show All Tasks..
export const configureTaskIcon = registerIcon('tasks-list-configure', Codicon.gear, nls.localize('configureTaskIcon', 'Configuration icon in the tasks selection list.'));
const removeTaskIcon = registerIcon('tasks-remove', Codicon.close, nls.localize('removeTaskIcon', 'Icon for remove in the tasks selection list.'));

const runTaskStorageKey = 'runTaskStorageKey';

export class TaskQuickPick extends Disposable {
private _sorter: TaskSorter;
private _topLevelEntries: QuickPickInput<ITaskTwoLevelQuickPickEntry>[] | undefined;
constructor(
private _taskService: ITaskService,
private _configurationService: IConfigurationService,
private _quickInputService: IQuickInputService,
private _notificationService: INotificationService,
private _themeService: IThemeService,
private _dialogService: IDialogService) {
@ITaskService private _taskService: ITaskService,
@IConfigurationService private _configurationService: IConfigurationService,
@IQuickInputService private _quickInputService: IQuickInputService,
@INotificationService private _notificationService: INotificationService,
@IThemeService private _themeService: IThemeService,
@IDialogService private _dialogService: IDialogService,
@IStorageService private _storageService: IStorageService) {
super();
this._sorter = this._taskService.createSorter();
}
Expand Down Expand Up @@ -225,8 +230,6 @@ export class TaskQuickPick extends Disposable {
picker.placeholder = placeHolder;
picker.matchOnDescription = true;
picker.ignoreFocusOut = false;
picker.show();

picker.onDidTriggerItemButton(async (context) => {
const task = context.item.task;
if (context.button.iconClass === ThemeIcon.asClassName(removeTaskIcon)) {
Expand All @@ -238,7 +241,7 @@ export class TaskQuickPick extends Disposable {
if (indexToRemove >= 0) {
picker.items = [...picker.items.slice(0, indexToRemove), ...picker.items.slice(indexToRemove + 1)];
}
} else {
} else if (context.button.iconClass === ThemeIcon.asClassName(configureTaskIcon)) {
this._quickInputService.cancel();
if (ContributedTask.is(task)) {
this._taskService.customize(task, undefined, true);
Expand Down Expand Up @@ -299,6 +302,7 @@ export class TaskQuickPick extends Disposable {

private async _doPickerFirstLevel(picker: IQuickPick<ITaskTwoLevelQuickPickEntry>, taskQuickPickEntries: QuickPickInput<ITaskTwoLevelQuickPickEntry>[]): Promise<Task | ConfiguringTask | string | null | undefined> {
picker.items = taskQuickPickEntries;
showWithPinnedItems(this._storageService, runTaskStorageKey, picker, true);
const firstLevelPickerResult = await new Promise<ITaskTwoLevelQuickPickEntry | undefined | null>(resolve => {
Event.once(picker.onDidAccept)(async () => {
resolve(picker.selectedItems ? picker.selectedItems[0] : undefined);
Expand All @@ -317,7 +321,7 @@ export class TaskQuickPick extends Disposable {
picker.value = name || '';
picker.items = await this._getEntriesForProvider(type);
}
picker.show();
showWithPinnedItems(this._storageService, runTaskStorageKey, picker, true);
picker.busy = false;
const secondLevelPickerResult = await new Promise<ITaskTwoLevelQuickPickEntry | undefined | null>(resolve => {
Event.once(picker.onDidAccept)(async () => {
Expand Down Expand Up @@ -400,11 +404,4 @@ export class TaskQuickPick extends Disposable {
}
return resolvedTask;
}

static async show(taskService: ITaskService, configurationService: IConfigurationService,
quickInputService: IQuickInputService, notificationService: INotificationService,
dialogService: IDialogService, themeService: IThemeService, placeHolder: string, defaultEntry?: ITaskQuickPickEntry, type?: string, name?: string) {
const taskQuickPick = new TaskQuickPick(taskService, configurationService, quickInputService, notificationService, themeService, dialogService);
return taskQuickPick.show(placeHolder, defaultEntry, type, name);
}
}
6 changes: 4 additions & 2 deletions src/vs/workbench/contrib/tasks/browser/tasksQuickAccess.ts
Expand Up @@ -18,6 +18,7 @@ import { isString } from 'vs/base/common/types';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IStorageService } from 'vs/platform/storage/common/storage';

export class TasksQuickAccessProvider extends PickerQuickAccessProvider<IPickerQuickAccessItem> {

Expand All @@ -30,7 +31,8 @@ export class TasksQuickAccessProvider extends PickerQuickAccessProvider<IPickerQ
@IQuickInputService private _quickInputService: IQuickInputService,
@INotificationService private _notificationService: INotificationService,
@IDialogService private _dialogService: IDialogService,
@IThemeService private _themeService: IThemeService
@IThemeService private _themeService: IThemeService,
@IStorageService private _storageService: IStorageService
) {
super(TasksQuickAccessProvider.PREFIX, {
noResultsPick: {
Expand All @@ -44,7 +46,7 @@ export class TasksQuickAccessProvider extends PickerQuickAccessProvider<IPickerQ
return [];
}

const taskQuickPick = new TaskQuickPick(this._taskService, this._configurationService, this._quickInputService, this._notificationService, this._themeService, this._dialogService);
const taskQuickPick = new TaskQuickPick(this._taskService, this._configurationService, this._quickInputService, this._notificationService, this._themeService, this._dialogService, this._storageService);
const topLevelPicks = await taskQuickPick.getTopLevelEntries();
const taskPicks: Array<IPickerQuickAccessItem | IQuickPickSeparator> = [];

Expand Down
Expand Up @@ -125,7 +125,8 @@ export class TaskService extends AbstractTaskService {
logService,
themeService,
lifecycleService,
remoteAgentService
remoteAgentService,
instantiationService
);
this._register(lifecycleService.onBeforeShutdown(event => event.veto(this.beforeShutdown(), 'veto.tasks')));
}
Expand Down