Skip to content

Commit 10a2e13

Browse files
Copilotrebornix
andauthored
Add "Checkout Pull Request" command to chat session context menu (#7669)
* Initial plan * Initial exploration of chat session context menu structure Co-authored-by: rebornix <876920+rebornix@users.noreply.github.com> * Add Checkout Pull Request command to chat session context menu - Add pr.checkoutChatSessionPullRequest command to package.json - Add localized title to package.nls.json - Implement checkoutChatSessionPullRequest function in src/commands.ts - Register command in src/commands.ts - Add command to chat/chatSessions context menu positioned above Close Pull Request - Reuse existing switchToPr functionality for checkout logic * polish * fix line feed --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rebornix <876920+rebornix@users.noreply.github.com> Co-authored-by: Peng Lyu <penn.lv@gmail.com>
1 parent 1d3706f commit 10a2e13

6 files changed

Lines changed: 48 additions & 12 deletions

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,11 @@
17521752
"title": "%command.pr.resetCodingAgentPreferences.title%",
17531753
"category": "%command.pull.request.category%"
17541754
},
1755+
{
1756+
"command": "pr.checkoutChatSessionPullRequest",
1757+
"title": "%command.pr.checkoutChatSessionPullRequest.title%",
1758+
"category": "%command.pull.request.category%"
1759+
},
17551760
{
17561761
"command": "pr.closeChatSessionPullRequest",
17571762
"title": "%command.pr.closeChatSessionPullRequest.title%",
@@ -3418,6 +3423,11 @@
34183423
"when": "chatSessionType == copilot-swe-agent",
34193424
"group": "inline"
34203425
},
3426+
{
3427+
"command": "pr.checkoutChatSessionPullRequest",
3428+
"when": "chatSessionType == copilot-swe-agent",
3429+
"group": "context"
3430+
},
34213431
{
34223432
"command": "pr.closeChatSessionPullRequest",
34233433
"when": "chatSessionType == copilot-swe-agent",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@
321321
"command.notifications.configureNotificationsViewlet.title": "Configure...",
322322
"command.notification.chatSummarizeNotification.title": "Summarize With Copilot",
323323
"command.codingAgent.openSessionLog.title": "Open Coding Agent Session Log",
324+
"command.pr.checkoutChatSessionPullRequest.title": "Checkout Pull Request",
324325
"command.pr.closeChatSessionPullRequest.title": "Close Pull Request",
325326
"command.pr.preferredCodingAgentGitHubRemote.title": "Set Preferred GitHub Remote for Coding Agent Sessions",
326327
"command.pr.resetCodingAgentPreferences.title": "Reset Coding Agent Workspace Preferences",

src/@types/vscode.proposed.chatParticipantAdditions.d.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,18 @@ declare module 'vscode' {
164164
/**
165165
* A specialized progress part for displaying thinking/reasoning steps.
166166
*/
167-
export class ChatResponseThinkingProgressPart extends ChatResponseProgressPart {
168-
value: string;
167+
export class ChatResponseThinkingProgressPart {
168+
value: string | string[];
169169
id?: string;
170-
metadata?: string;
170+
metadata?: { readonly [key: string]: any };
171171
task?: (progress: Progress<LanguageModelThinkingPart>) => Thenable<string | void>;
172172

173173
/**
174174
* Creates a new thinking progress part.
175175
* @param value An initial progress message
176176
* @param task A task that will emit thinking parts during its execution
177177
*/
178-
constructor(value: string, id?: string, metadata?: string, task?: (progress: Progress<LanguageModelThinkingPart>) => Thenable<string | void>);
178+
constructor(value: string | string[], id?: string, metadata?: { readonly [key: string]: any }, task?: (progress: Progress<LanguageModelThinkingPart>) => Thenable<string | void>);
179179
}
180180

181181
export class ChatResponseReferencePart2 {
@@ -328,18 +328,18 @@ declare module 'vscode' {
328328
}
329329

330330
export type ThinkingDelta = {
331-
text?: string;
331+
text?: string | string[];
332332
id: string;
333-
metadata?: string;
333+
metadata?: { readonly [key: string]: any };
334334
} | {
335-
text?: string;
335+
text?: string | string[];
336336
id?: string;
337-
metadata: string;
337+
metadata: { readonly [key: string]: any };
338338
} |
339339
{
340-
text: string;
340+
text: string | string[];
341341
id?: string;
342-
metadata?: string;
342+
metadata?: { readonly [key: string]: any };
343343
};
344344

345345
export enum ChatResponseClearToPreviousToolInvocationReason {

src/@types/vscode.proposed.chatParticipantPrivate.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ declare module 'vscode' {
183183
isQuotaExceeded?: boolean;
184184

185185
level?: ChatErrorLevel;
186+
187+
code?: string;
186188
}
187189

188190
export namespace chat {

src/@types/vscode.proposed.languageModelDataPart.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ declare module 'vscode' {
4242
* A string or heterogeneous array of things that a message can contain as content. Some parts may be message-type
4343
* specific for some models.
4444
*/
45-
content: Array<LanguageModelTextPart | LanguageModelToolResultPart2 | LanguageModelToolCallPart | LanguageModelDataPart>;
45+
content: Array<LanguageModelTextPart | LanguageModelToolResultPart2 | LanguageModelToolCallPart | LanguageModelDataPart | LanguageModelThinkingPart>;
4646

4747
/**
4848
* The optional name of a user for this message.
@@ -56,7 +56,7 @@ declare module 'vscode' {
5656
* @param content The content of the message.
5757
* @param name The optional name of a user for the message.
5858
*/
59-
constructor(role: LanguageModelChatMessageRole, content: string | Array<LanguageModelTextPart | LanguageModelToolResultPart2 | LanguageModelToolCallPart | LanguageModelDataPart>, name?: string);
59+
constructor(role: LanguageModelChatMessageRole, content: string | Array<LanguageModelTextPart | LanguageModelToolResultPart2 | LanguageModelToolCallPart | LanguageModelDataPart | LanguageModelThinkingPart>, name?: string);
6060
}
6161

6262
/**

src/commands.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,22 @@ export function registerCommands(
967967
await openDescription(telemetry, issueModel, descriptionNode, folderManager, revealDescription, !(argument instanceof RepositoryChangesNode), tree.notificationProvider);
968968
}
969969

970+
async function checkoutChatSessionPullRequest(argument: ChatSessionWithPR) {
971+
const pr = argument.pullRequest;
972+
if (!pr) {
973+
Logger.warn(`No pull request found in chat session`, logId);
974+
return;
975+
}
976+
977+
const folderManager = reposManager.getManagerForRepository(pr.githubRepository.remote.owner, pr.githubRepository.remote.repositoryName);
978+
if (!folderManager) {
979+
Logger.warn(`No folder manager found for pull request ${pr.number}`, logId);
980+
return vscode.window.showErrorMessage(vscode.l10n.t('Unable to find repository for pull request #{0}', pr.number.toString()));
981+
}
982+
983+
return switchToPr(folderManager, pr, folderManager.repository, false);
984+
}
985+
970986
async function closeChatSessionPullRequest(argument: ChatSessionWithPR) {
971987
const pr = argument.pullRequest;
972988
if (!pr) {
@@ -988,6 +1004,13 @@ export function registerCommands(
9881004
// TODO: show a progress icon until the cancelation is finished
9891005
}
9901006

1007+
context.subscriptions.push(
1008+
vscode.commands.registerCommand(
1009+
'pr.checkoutChatSessionPullRequest',
1010+
checkoutChatSessionPullRequest
1011+
)
1012+
);
1013+
9911014
context.subscriptions.push(
9921015
vscode.commands.registerCommand(
9931016
'pr.closeChatSessionPullRequest',

0 commit comments

Comments
 (0)