-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: add "Preview System Prompt" button to Prompts settings for improved discoverability #7329
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -43,6 +43,7 @@ const PromptsSettings = ({ | |||||
| setCustomCondensingPrompt, | ||||||
| includeTaskHistoryInEnhance: contextIncludeTaskHistoryInEnhance, | ||||||
| setIncludeTaskHistoryInEnhance: contextSetIncludeTaskHistoryInEnhance, | ||||||
| mode, | ||||||
| } = useExtensionState() | ||||||
|
|
||||||
| // Use props if provided, otherwise fall back to context | ||||||
|
|
@@ -52,6 +53,9 @@ const PromptsSettings = ({ | |||||
| const [testPrompt, setTestPrompt] = useState("") | ||||||
| const [isEnhancing, setIsEnhancing] = useState(false) | ||||||
| const [activeSupportOption, setActiveSupportOption] = useState<SupportPromptType>("ENHANCE") | ||||||
| const [isDialogOpen, setIsDialogOpen] = useState(false) | ||||||
| const [selectedPromptContent, setSelectedPromptContent] = useState("") | ||||||
| const [selectedPromptTitle, setSelectedPromptTitle] = useState("") | ||||||
|
|
||||||
| useEffect(() => { | ||||||
| const handler = (event: MessageEvent) => { | ||||||
|
|
@@ -61,6 +65,12 @@ const PromptsSettings = ({ | |||||
| setTestPrompt(message.text) | ||||||
| } | ||||||
| setIsEnhancing(false) | ||||||
| } else if (message.type === "systemPrompt") { | ||||||
| if (message.text) { | ||||||
| setSelectedPromptContent(message.text) | ||||||
| setSelectedPromptTitle(`System Prompt (${message.mode} mode)`) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using the translation function (t) to set the system prompt title instead of a hard-coded template literal. For example, use t('prompts:systemPrompt.title', { modeName: message.mode }) to ensure consistency with translations.
Suggested change
This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX. |
||||||
| setIsDialogOpen(true) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -122,6 +132,43 @@ const PromptsSettings = ({ | |||||
| </SectionHeader> | ||||||
|
|
||||||
| <Section> | ||||||
| {/* System Prompt Preview Section */} | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This entire system prompt preview section (lines 135-167) duplicates functionality that already exists in ModesView.tsx. Could we extract this into a shared component like |
||||||
| <div className="mb-4"> | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This component is adding significant new functionality without any test coverage. Consider adding tests for:
|
||||||
| <div className="flex gap-2"> | ||||||
| <Button | ||||||
| variant="default" | ||||||
| onClick={() => { | ||||||
| vscode.postMessage({ | ||||||
| type: "getSystemPrompt", | ||||||
| mode: mode, | ||||||
| }) | ||||||
| }} | ||||||
| data-testid="preview-prompt-button"> | ||||||
| {t("prompts:systemPrompt.preview")} | ||||||
| </Button> | ||||||
| <StandardTooltip content={t("prompts:systemPrompt.copy")}> | ||||||
| <Button | ||||||
| variant="ghost" | ||||||
| size="icon" | ||||||
| onClick={() => { | ||||||
| vscode.postMessage({ | ||||||
| type: "copySystemPrompt", | ||||||
| mode: mode, | ||||||
| }) | ||||||
| }} | ||||||
| data-testid="copy-prompt-button"> | ||||||
| <span className="codicon codicon-copy"></span> | ||||||
| </Button> | ||||||
| </StandardTooltip> | ||||||
| </div> | ||||||
| <div className="text-sm text-vscode-descriptionForeground mt-1"> | ||||||
| {t("prompts:systemPrompt.previewDescription")} | ||||||
| </div> | ||||||
| </div> | ||||||
|
|
||||||
| <div className="border-t border-vscode-input-border my-4"></div> | ||||||
|
|
||||||
| {/* Support Prompts Section */} | ||||||
| <div> | ||||||
| <Select | ||||||
| value={activeSupportOption} | ||||||
|
|
@@ -281,6 +328,34 @@ const PromptsSettings = ({ | |||||
| )} | ||||||
| </div> | ||||||
| </Section> | ||||||
|
|
||||||
| {/* System Prompt Preview Dialog */} | ||||||
| {isDialogOpen && ( | ||||||
| <div className="fixed inset-0 flex justify-end bg-black/50 z-[1000]"> | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For improved accessibility, consider adding appropriate ARIA attributes (e.g., role='dialog', aria-modal='true') to the system prompt preview modal container.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dialog styling mixes inline Tailwind classes with what appears to be VSCode-specific CSS variables. For consistency and maintainability, consider consolidating to one approach. Also, the fixed positioning with 'inset-0' might cause issues on smaller screens. |
||||||
| <div className="w-[calc(100vw-100px)] h-full bg-vscode-editor-background shadow-md flex flex-col relative"> | ||||||
| <div className="flex-1 p-5 overflow-y-auto min-h-0"> | ||||||
| <Button | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accessibility issue: This close button only has an icon without an aria-label. Screen reader users won't know what this button does. Consider adding aria-label="Close dialog". |
||||||
| variant="ghost" | ||||||
| size="icon" | ||||||
| onClick={() => setIsDialogOpen(false)} | ||||||
| className="absolute top-5 right-5"> | ||||||
| <span className="codicon codicon-close"></span> | ||||||
| </Button> | ||||||
| <h2 className="mb-4"> | ||||||
| {selectedPromptTitle || t("prompts:systemPrompt.title", { modeName: mode })} | ||||||
| </h2> | ||||||
| <pre className="p-2 whitespace-pre-wrap break-words font-mono text-vscode-editor-font-size text-vscode-editor-foreground bg-vscode-editor-background border border-vscode-editor-lineHighlightBorder rounded overflow-y-auto"> | ||||||
| {selectedPromptContent} | ||||||
| </pre> | ||||||
| </div> | ||||||
| <div className="flex justify-end p-3 px-5 border-t border-vscode-editor-lineHighlightBorder bg-vscode-editor-background"> | ||||||
| <Button variant="secondary" onClick={() => setIsDialogOpen(false)}> | ||||||
| {t("prompts:createModeDialog.close")} | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This translation key 'prompts:createModeDialog.close' seems to be borrowed from a different context (createModeDialog). Consider adding a dedicated translation key for this dialog, like 'prompts:systemPromptDialog.close' for better maintainability. |
||||||
| </Button> | ||||||
| </div> | ||||||
| </div> | ||||||
| </div> | ||||||
| )} | ||||||
| </div> | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling here. What happens if message.text or message.mode is undefined? Consider adding defensive checks to prevent runtime errors.