Skip to content

Commit 98b4750

Browse files
Copilotalexr00
andcommitted
Use Tab API to detect diff editors in #openPullRequest tool
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent f42edf5 commit 98b4750

3 files changed

Lines changed: 35 additions & 19 deletions

File tree

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,13 @@ declare module 'vscode' {
646646
}
647647

648648
export interface ChatRequest {
649-
modeInstructions?: string;
650-
modeInstructionsToolReferences?: readonly ChatLanguageModelToolReference[];
649+
readonly modeInstructions?: string;
650+
readonly modeInstructions2?: ChatRequestModeInstructions;
651+
}
652+
653+
export interface ChatRequestModeInstructions {
654+
readonly content: string;
655+
readonly toolReferences?: readonly ChatLanguageModelToolReference[];
656+
readonly metadata?: Record<string, boolean | string | number>;
651657
}
652658
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ declare module 'vscode' {
5555
*/
5656
readonly attempt: number;
5757

58+
/**
59+
* The session identifier for this chat request
60+
*/
61+
readonly sessionId: string;
62+
5863
/**
5964
* If automatic command detection is enabled.
6065
*/
@@ -182,6 +187,8 @@ declare module 'vscode' {
182187

183188
isQuotaExceeded?: boolean;
184189

190+
isRateLimited?: boolean;
191+
185192
level?: ChatErrorLevel;
186193

187194
code?: string;

src/lm/tools/openPullRequestTool.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,27 @@ export class OpenPullRequestTool extends PullRequestTool {
1919
return panelPR;
2020
}
2121

22-
// Check if the active file is a diff view or multidiff view showing PR content
23-
const activeEditor = vscode.window.activeTextEditor;
24-
if (activeEditor?.document.uri) {
25-
const uri = activeEditor.document.uri;
22+
// Check if the active tab is a diff editor showing PR content
23+
const activeTab = vscode.window.tabGroups.activeTabGroup.activeTab;
24+
if (activeTab?.input instanceof vscode.TabInputTextDiff) {
25+
const diffInput = activeTab.input;
26+
const urisToCheck = [diffInput.original, diffInput.modified];
2627

27-
if (uri.scheme === Schemes.Pr) {
28-
// This is a PR diff from GitHub
29-
const prParams = fromPRUri(uri);
30-
if (prParams) {
31-
return this._findPullRequestByNumber(prParams.prNumber, prParams.remoteName);
32-
}
33-
} else if (uri.scheme === Schemes.Review) {
34-
// This is a review diff from a checked out PR
35-
const reviewParams = fromReviewUri(uri.query);
36-
if (reviewParams) {
37-
// For review scheme, find the active/checked out PR
38-
const folderManager = this.folderManagers.folderManagers.find(manager => manager.activePullRequest);
39-
return folderManager?.activePullRequest;
28+
for (const uri of urisToCheck) {
29+
if (uri.scheme === Schemes.Pr) {
30+
// This is a PR diff from GitHub
31+
const prParams = fromPRUri(uri);
32+
if (prParams) {
33+
return this._findPullRequestByNumber(prParams.prNumber, prParams.remoteName);
34+
}
35+
} else if (uri.scheme === Schemes.Review) {
36+
// This is a review diff from a checked out PR
37+
const reviewParams = fromReviewUri(uri.query);
38+
if (reviewParams) {
39+
// For review scheme, find the active/checked out PR
40+
const folderManager = this.folderManagers.folderManagers.find(manager => manager.activePullRequest);
41+
return folderManager?.activePullRequest;
42+
}
4043
}
4144
}
4245
}

0 commit comments

Comments
 (0)