Skip to content

Commit 52c22d5

Browse files
authored
fix mode and instruction pickers & polish (microsoft#250268)
1 parent fa489b1 commit 52c22d5

File tree

1 file changed

+16
-15
lines changed
  • src/vs/workbench/contrib/chat/browser/actions/promptActions/dialogs/askToSelectPrompt

1 file changed

+16
-15
lines changed

src/vs/workbench/contrib/chat/browser/actions/promptActions/dialogs/askToSelectPrompt/promptFilePickers.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { localize } from '../../../../../../../../nls.js';
77
import { URI } from '../../../../../../../../base/common/uri.js';
88
import { assert } from '../../../../../../../../base/common/assert.js';
99
import { Codicon } from '../../../../../../../../base/common/codicons.js';
10-
import { WithUriValue } from '../../../../../../../../base/common/types.js';
1110
import { ThemeIcon } from '../../../../../../../../base/common/themables.js';
1211
import { IPromptPath, IPromptsService } from '../../../../../common/promptSyntax/service/types.js';
1312
import { dirname, extUri, joinPath } from '../../../../../../../../base/common/resources.js';
@@ -177,6 +176,7 @@ export class PromptFilePickers {
177176
async selectPromptFile(options: ISelectOptions): Promise<ISelectPromptResult | undefined> {
178177
const quickPick = this._quickInputService.createQuickPick<IPromptPickerQuickPickItem>();
179178
quickPick.busy = true;
179+
quickPick.placeholder = localize('searching', 'Searching for files...');
180180
try {
181181
const fileOptions = await this._createPromptPickItems(options);
182182
const activeItem = options.resource && fileOptions.find(f => extUri.isEqual(f.value, options.resource));
@@ -256,15 +256,15 @@ export class PromptFilePickers {
256256
if (options.optionDelete !== false) {
257257
buttons.push(DELETE_BUTTON);
258258
}
259-
const promptFiles = await this._promptsService.listPromptFiles(PromptsType.prompt, CancellationToken.None);
259+
const promptFiles = await this._promptsService.listPromptFiles(options.type, CancellationToken.None);
260260

261261
const fileOptions = promptFiles.map((promptFile) => {
262262
return this._createPromptPickItem(promptFile, buttons);
263263
});
264264

265265
// if a resource is provided, create an `activeItem` for it to pre-select
266266
// it in the UI, and sort the list so the active item appears at the top
267-
let activeItem: WithUriValue<IQuickPickItem> | undefined;
267+
let activeItem: IPromptPickerQuickPickItem | undefined;
268268
if (options.resource) {
269269
activeItem = fileOptions.find((file) => {
270270
return extUri.isEqual(file.value, options.resource);
@@ -318,7 +318,7 @@ export class PromptFilePickers {
318318
}
319319
}
320320

321-
private _createPromptPickItem(promptFile: IPromptPath, buttons: IQuickInputButton[]): WithUriValue<IQuickPickItem> {
321+
private _createPromptPickItem(promptFile: IPromptPath, buttons: IQuickInputButton[]): IPromptPickerQuickPickItem {
322322
const { uri, storage } = promptFile;
323323
const fileWithoutExtension = getCleanPromptName(uri);
324324

@@ -343,7 +343,7 @@ export class PromptFilePickers {
343343
};
344344
}
345345

346-
private async _handleButtonClick(quickPick: IQuickPick<WithUriValue<IQuickPickItem>>, context: IQuickPickItemButtonEvent<WithUriValue<IQuickPickItem>>, options: ISelectOptions): Promise<void> {
346+
private async _handleButtonClick(quickPick: IQuickPick<IPromptPickerQuickPickItem>, context: IQuickPickItemButtonEvent<IPromptPickerQuickPickItem>, options: ISelectOptions): Promise<void> {
347347
const { item, button } = context;
348348
const { value, } = item;
349349

@@ -358,15 +358,16 @@ export class PromptFilePickers {
358358
// don't close the main prompt selection dialog by the confirmation dialog
359359
const previousIgnoreFocusOut = quickPick.ignoreFocusOut;
360360
quickPick.ignoreFocusOut = true;
361-
362-
const currentFolder = dirname(value);
363-
const newName = await this._instaService.invokeFunction(askForPromptFileName, options.type, currentFolder);
364-
if (newName) {
365-
await this._fileService.move(value, joinPath(currentFolder, newName));
361+
try {
362+
const currentFolder = dirname(value);
363+
const newName = await this._instaService.invokeFunction(askForPromptFileName, options.type, currentFolder);
364+
if (newName) {
365+
await this._fileService.move(value, joinPath(currentFolder, newName));
366+
}
367+
} finally {
368+
quickPick.ignoreFocusOut = previousIgnoreFocusOut;
369+
quickPick.items = await this._createPromptPickItems(options);
366370
}
367-
368-
quickPick.ignoreFocusOut = previousIgnoreFocusOut;
369-
quickPick.items = await this._createPromptPickItems(options);
370371
return;
371372
}
372373

@@ -378,7 +379,7 @@ export class PromptFilePickers {
378379
`Expected maximum one active item, got '${quickPick.activeItems.length}'.`,
379380
);
380381

381-
const activeItem: WithUriValue<IQuickPickItem> | undefined = quickPick.activeItems[0];
382+
const activeItem: IPromptPickerQuickPickItem | undefined = quickPick.activeItems[0];
382383

383384
// sanity checks - prompt file exists and is not a folder
384385
const info = await this._fileService.stat(value);
@@ -433,7 +434,7 @@ export class PromptFilePickers {
433434
// we set the previous item as new active, or the next item
434435
// if removed prompt item was in the beginning of the list
435436
const newActiveItemIndex = Math.max(removedIndex - 1, 0);
436-
const newActiveItem: WithUriValue<IQuickPickItem> | undefined = quickPick.items[newActiveItemIndex];
437+
const newActiveItem: IPromptPickerQuickPickItem | undefined = quickPick.items[newActiveItemIndex];
437438

438439
quickPick.activeItems = newActiveItem ? [newActiveItem] : [];
439440
}

0 commit comments

Comments
 (0)