-
Notifications
You must be signed in to change notification settings - Fork 121
show copilot instructions prompt at startup #2361
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
Open
minestarks
wants to merge
2
commits into
main
Choose a base branch
from
minestarks/copilot-instructions-prompt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,7 +174,7 @@ async function hasQSharpCopilotInstructions( | |
* Command to update or create the Copilot instructions file for Q#. | ||
* Shows a prompt to the user and updates the file if confirmed. | ||
*/ | ||
async function updateGhCopilotInstructionsCommand() { | ||
async function updateGhCopilotInstructionsCommand(userInvoked: boolean) { | ||
const workspaceFolders = vscode.workspace.workspaceFolders; | ||
if (!workspaceFolders || workspaceFolders.length === 0) { | ||
vscode.window.showErrorMessage("No workspace folder is open"); | ||
|
@@ -191,10 +191,13 @@ async function updateGhCopilotInstructionsCommand() { | |
resourceUri = currentDoc ?? workspaceFolders[0].uri; | ||
} | ||
|
||
return await updateCopilotInstructions(resourceUri); | ||
return await updateCopilotInstructions(resourceUri, userInvoked); | ||
} | ||
|
||
export async function updateCopilotInstructions(resource: vscode.Uri) { | ||
export async function updateCopilotInstructions( | ||
resource: vscode.Uri, | ||
userInvoked: boolean, | ||
): Promise<vscode.MessageItem | undefined> { | ||
// Always add copilot instructions in the workspace root | ||
const workspaceFolder = vscode.workspace.getWorkspaceFolder(resource)?.uri; | ||
if (!workspaceFolder) { | ||
|
@@ -206,24 +209,46 @@ export async function updateCopilotInstructions(resource: vscode.Uri) { | |
return; | ||
} | ||
|
||
sendTelemetryEvent(EventType.UpdateCopilotInstructionsStart, {}, {}); | ||
sendTelemetryEvent( | ||
EventType.UpdateCopilotInstructionsStart, | ||
{ | ||
trigger: userInvoked ? "user" : "startup", | ||
}, | ||
{}, | ||
); | ||
|
||
const buttons = [{ title: "Yes" }, { title: "No", isCloseAffordance: true }]; | ||
if (!userInvoked) { | ||
buttons.push({ title: "Don't show again" }); | ||
} | ||
|
||
const modal = userInvoked; | ||
|
||
// Show a yes/no prompt to the user | ||
const response = await vscode.window.showInformationMessage( | ||
"We're about to update your `copilot-instructions.md` file.\n\n" + | ||
"This file helps GitHub Copilot understand and work better with Q# files and features provided by the Quantum Development Kit extension.\n\n" + | ||
"Would you like to proceed with updating `copilot-instructions.md`?", | ||
{ modal: true }, | ||
{ title: "Yes" }, | ||
{ title: "No", isCloseAffordance: true }, | ||
"Add Q# guidance to copilot-instructions.md?\n\n" + | ||
"Updating this file will help GitHub Copilot understand and work better with Q# files and other Quantum Development Kit features.\n\n" + | ||
"Learn more at " + | ||
(modal | ||
? "https://aka.ms/qdk.copilot" // links don't render in modal dialogs | ||
: "[https://aka.ms/qdk.copilot](https://aka.ms/qdk.copilot)"), | ||
{ | ||
modal, | ||
}, | ||
...buttons, | ||
); | ||
|
||
if (response?.title !== "Yes") { | ||
sendTelemetryEvent(EventType.UpdateCopilotInstructionsEnd, { | ||
reason: "User canceled", | ||
flowStatus: UserFlowStatus.Aborted, | ||
}); | ||
return; // User canceled or dismissed the dialog | ||
|
||
vscode.window.showInformationMessage( | ||
"To add Q# guidance to copilot-instructions.md at any time, " + | ||
'run the command "Q#: Update Copilot instructions file for Q#".', | ||
); | ||
|
||
return response; // User dismissed the dialog | ||
} | ||
|
||
try { | ||
|
@@ -274,7 +299,8 @@ export async function updateCopilotInstructions(resource: vscode.Uri) { | |
{ flowStatus: UserFlowStatus.Failed, reason: "Error" }, | ||
{}, | ||
); | ||
return; | ||
|
||
return response; | ||
} | ||
|
||
// Send telemetry event for successful completion | ||
|
@@ -292,7 +318,24 @@ export function registerGhCopilotInstructionsCommand( | |
context.subscriptions.push( | ||
vscode.commands.registerCommand( | ||
"qsharp-vscode.updateCopilotInstructions", | ||
updateGhCopilotInstructionsCommand, | ||
() => updateGhCopilotInstructionsCommand(true), | ||
), | ||
); | ||
|
||
// Also do a one-time prompt at startup | ||
if ( | ||
context.globalState.get<boolean>( | ||
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. might want to make this |
||
"showUpdateCopilotInstructionsPromptAtStartup", | ||
true, | ||
) | ||
) { | ||
updateGhCopilotInstructionsCommand(false).then((response) => { | ||
if (response?.title === "Don't show again") { | ||
context.globalState.update( | ||
"showUpdateCopilotInstructionsPromptAtStartup", | ||
false, | ||
); | ||
} | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If it's user invoked, should we show a confirmation at all, or just update it? It's not like we're doing anything destructive, we only add content. If they explicitly invoked the command, prompting again might be excessive.
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.
Maybe. My goal in showing the prompt was to help the user understand what they just clicked on. They may have been just poking around in the command palette - without this message, there's nothing telling them what actually happened, and I doubt most users would just know about
copilot-instructions.md
.