Skip to content

Commit 2c8786f

Browse files
Copilotalexr00
andcommitted
Fix #openPullRequest to consider diff editors and use consistent terminology
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent c930948 commit 2c8786f

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/lm/tools/openPullRequestTool.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,39 @@ export class OpenPullRequestTool extends PullRequestTool {
1212
public static readonly toolId = 'github-pull-request_openPullRequest';
1313

1414
protected _findActivePullRequest(): PullRequestModel | undefined {
15-
return PullRequestOverviewPanel.currentPanel?.getCurrentItem();
15+
// First check if there's a PR overview panel open
16+
const panelPR = PullRequestOverviewPanel.currentPanel?.getCurrentItem();
17+
if (panelPR) {
18+
return panelPR;
19+
}
20+
21+
// If no overview panel is open, check if there's an active PR (checked out locally)
22+
// This covers the case where users are viewing PR diffs without the overview panel
23+
const folderManager = this.folderManagers.folderManagers.find((manager) => manager.activePullRequest);
24+
return folderManager?.activePullRequest;
1625
}
1726

1827
protected _confirmationTitle(): string {
1928
return vscode.l10n.t('Open Pull Request');
2029
}
30+
31+
override async prepareInvocation(): Promise<vscode.PreparedToolInvocation> {
32+
const pullRequest = this._findActivePullRequest();
33+
return {
34+
pastTenseMessage: pullRequest ? vscode.l10n.t('Read pull request "{0}"', pullRequest.title) : vscode.l10n.t('No open pull request'),
35+
invocationMessage: pullRequest ? vscode.l10n.t('Reading pull request "{0}"', pullRequest.title) : vscode.l10n.t('Reading open pull request'),
36+
confirmationMessages: { title: this._confirmationTitle(), message: pullRequest ? vscode.l10n.t('Allow reading the details of "{0}"?', pullRequest.title) : vscode.l10n.t('Allow reading the details of the open pull request?') },
37+
};
38+
}
39+
40+
override async invoke(options: vscode.LanguageModelToolInvocationOptions<any>, token: vscode.CancellationToken): Promise<vscode.ExtendedLanguageModelToolResult | undefined> {
41+
let pullRequest = this._findActivePullRequest();
42+
43+
if (!pullRequest) {
44+
return new vscode.LanguageModelToolResult([new vscode.LanguageModelTextPart('There is no open pull request')]);
45+
}
46+
47+
// Delegate to the base class for the actual implementation
48+
return super.invoke(options, token);
49+
}
2150
}

0 commit comments

Comments
 (0)