@@ -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