Skip to content

Commit c6b1d6d

Browse files
committed
fix issue related to no prompts showing up and always keep the docs item in the list
1 parent a45463d commit c6b1d6d

File tree

3 files changed

+45
-69
lines changed

3 files changed

+45
-69
lines changed

src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/chatAttachPromptAction.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { CHAT_CATEGORY } from '../chatActions.js';
77
import { localize2 } from '../../../../../../nls.js';
8-
import { showHowToCreateLink } from './dialogs/showHowToCreate.js';
98
import { Action2 } from '../../../../../../platform/actions/common/actions.js';
109
import { IPromptsService } from '../../../common/promptSyntax/service/types.js';
1110
import { ILabelService } from '../../../../../../platform/label/common/label.js';
@@ -53,19 +52,13 @@ export class AttachPromptAction extends Action2 {
5352
// find all prompt files in the user workspace
5453
const promptFiles = await promptsService.listPromptFiles();
5554

56-
// if no prompt files found, show instructions on how to create one
57-
if (promptFiles.length === 0) {
58-
return await showHowToCreateLink(openerService, quickInputService);
59-
}
60-
61-
await askToSelectPrompt(
62-
{
63-
...options,
64-
promptFiles,
65-
labelService,
66-
viewsService,
67-
openerService,
68-
quickInputService,
69-
});
55+
await askToSelectPrompt({
56+
...options,
57+
promptFiles,
58+
labelService,
59+
viewsService,
60+
openerService,
61+
quickInputService,
62+
});
7063
}
7164
}

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

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { IChatAttachPromptActionOptions } from '../chatAttachPromptAction.js';
1111
import { IPromptPath } from '../../../../common/promptSyntax/service/types.js';
1212
import { DisposableStore } from '../../../../../../../base/common/lifecycle.js';
1313
import { dirname, extUri } from '../../../../../../../base/common/resources.js';
14+
import { DOCUMENTATION_URL } from '../../../../common/promptSyntax/constants.js';
1415
import { isLinux, isWindows } from '../../../../../../../base/common/platform.js';
1516
import { ILabelService } from '../../../../../../../platform/label/common/label.js';
1617
import { IOpenerService } from '../../../../../../../platform/opener/common/opener.js';
@@ -50,6 +51,20 @@ export interface ISelectPromptOptions {
5051
readonly quickInputService: IQuickInputService;
5152
}
5253

54+
/**
55+
* A special quick pick item that links to the documentation.
56+
*/
57+
const DOCS_OPTION: WithUriValue<IQuickPickItem> = {
58+
type: 'item',
59+
label: localize(
60+
'commands.prompts.use.select-dialog.docs-label',
61+
'Learn how to create reusable prompts',
62+
),
63+
description: DOCUMENTATION_URL,
64+
tooltip: DOCUMENTATION_URL,
65+
value: URI.parse(DOCUMENTATION_URL),
66+
};
67+
5368
/**
5469
* Shows the prompt selection dialog to the user that allows to select a prompt file(s).
5570
*
@@ -61,16 +76,15 @@ export const askToSelectPrompt = async (
6176
): Promise<void> => {
6277
const { promptFiles, resource, quickInputService, labelService } = options;
6378

64-
// a sanity check - this function must be used only if there are prompt files to show
65-
assert(
66-
promptFiles.length > 0,
67-
'Prompt files list must not be empty.',
68-
);
69-
7079
const fileOptions = promptFiles.map(({ uri }) => {
7180
return createPickItem(uri, labelService);
7281
});
7382

83+
/**
84+
* Add a link to the documentation to the end of prompts list.
85+
*/
86+
fileOptions.push(DOCS_OPTION);
87+
7488
// if a resource is provided, create an `activeItem` for it to pre-select
7589
// it in the UI, and sort the list so the active item appears at the top
7690
let activeItem: WithUriValue<IQuickPickItem> | undefined;
@@ -101,6 +115,13 @@ export const askToSelectPrompt = async (
101115
});
102116
}
103117

118+
/**
119+
* If still no active item present, fall back to the first item in the list.
120+
*/
121+
if (!activeItem) {
122+
activeItem = fileOptions[0];
123+
}
124+
104125
// otherwise show the prompt file selection dialog
105126
const { openerService } = options;
106127

@@ -129,8 +150,17 @@ export const askToSelectPrompt = async (
129150
const { selectedItems } = quickPick;
130151
const { alt, ctrlCmd } = quickPick.keyMods;
131152

153+
// sanity check to confirm our expectations
154+
assert(
155+
selectedItems.length === 1,
156+
`Only one item can be accepted, got '${selectedItems.length}'.`,
157+
);
158+
159+
// whether user selected the docs link option
160+
const docsSelected = (selectedItems[0] === DOCS_OPTION);
161+
132162
// if `super` key was pressed, open the selected prompt file(s)
133-
if (ctrlCmd) {
163+
if (ctrlCmd || docsSelected) {
134164
return await openFiles(selectedItems, openerService);
135165
}
136166

src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/showHowToCreate.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)