@@ -18,6 +18,7 @@ import { PRType } from '../github/interface';
1818import { issueMarkdown } from '../github/markdownUtils' ;
1919import { NotificationProvider } from '../github/notifications' ;
2020import { PullRequestModel } from '../github/pullRequestModel' ;
21+ import { PullRequestOverviewPanel } from '../github/pullRequestOverview' ;
2122import { RepositoriesManager } from '../github/repositoriesManager' ;
2223import { findDotComAndEnterpriseRemotes } from '../github/utils' ;
2324import { PRStatusDecorationProvider } from './prStatusDecorationProvider' ;
@@ -29,6 +30,7 @@ import { PRNode } from './treeNodes/pullRequestNode';
2930import { BaseTreeNode , TreeNode } from './treeNodes/treeNode' ;
3031import { TreeUtils } from './treeNodes/treeUtils' ;
3132import { WorkspaceFolderNode } from './treeNodes/workspaceFolderNode' ;
33+ import Logger from '../common/logger' ;
3234
3335export class PullRequestsTreeDataProvider extends Disposable implements vscode . TreeDataProvider < TreeNode > , BaseTreeNode {
3436 private _onDidChangeTreeData = new vscode . EventEmitter < TreeNode | void > ( ) ;
@@ -81,6 +83,12 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
8183 this . _view . badge = undefined ;
8284 this . _notificationClearTimeout = undefined ;
8385 } , 5000 ) ;
86+
87+ // Sync with currently active PR when view becomes visible
88+ const currentPR = PullRequestOverviewPanel . getCurrentPullRequest ( ) ;
89+ if ( currentPR ) {
90+ this . syncWithActivePullRequest ( currentPR ) ;
91+ }
8492 }
8593 } ) ) ;
8694
@@ -107,6 +115,14 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
107115
108116 this . _register ( this . _copilotManager . onDidCreatePullRequest ( ( ) => this . refresh ( ) ) ) ;
109117
118+ // Listen for PR overview panel changes to sync the tree view
119+ this . _register ( PullRequestOverviewPanel . onVisible ( pullRequest => {
120+ // Only sync if view is already visible (don't open the view)
121+ if ( this . _view . visible ) {
122+ this . syncWithActivePullRequest ( pullRequest ) ;
123+ }
124+ } ) ) ;
125+
110126 this . _children = [ ] ;
111127
112128 this . _register ( vscode . commands . registerCommand ( 'pr.configurePRViewlet' , async ( ) => {
@@ -174,6 +190,73 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
174190 return this . _view . reveal ( element , options ) ;
175191 }
176192
193+ /**
194+ * Sync the tree view with the currently active PR overview
195+ */
196+ private async syncWithActivePullRequest ( pullRequest : PullRequestModel ) : Promise < void > {
197+ const alreadySelected = this . _view . selection . find ( child => child instanceof PRNode && ( child . pullRequestModel . number === pullRequest . number ) && ( child . pullRequestModel . remote . owner === pullRequest . remote . owner ) && ( child . pullRequestModel . remote . repositoryName === pullRequest . remote . repositoryName ) ) ;
198+ if ( alreadySelected ) {
199+ return ;
200+ }
201+ try {
202+ // Find the PR node in the tree and reveal it
203+ const prNode = await this . findPRNode ( pullRequest ) ;
204+ if ( prNode ) {
205+ await this . reveal ( prNode , { select : true , focus : false , expand : false } ) ;
206+ }
207+ } catch ( error ) {
208+ // Silently ignore errors to avoid disrupting the user experience
209+ Logger . warn ( `Failed to sync tree view with active PR: ${ error } ` ) ;
210+ }
211+ }
212+
213+ /**
214+ * Find a PR node in the tree structure
215+ */
216+ private async findPRNode ( pullRequest : PullRequestModel ) : Promise < PRNode | undefined > {
217+ if ( this . _children . length === 0 ) {
218+ await this . getChildren ( ) ;
219+ }
220+
221+ for ( const child of this . _children ) {
222+ if ( child instanceof WorkspaceFolderNode ) {
223+ const found = await this . findPRNodeInWorkspaceFolder ( child , pullRequest ) ;
224+ if ( found ) return found ;
225+ } else if ( child instanceof CategoryTreeNode ) {
226+ const found = await this . findPRNodeInCategory ( child , pullRequest ) ;
227+ if ( found ) return found ;
228+ }
229+ }
230+ return undefined ;
231+ }
232+
233+ /**
234+ * Search for PR node within a workspace folder node
235+ */
236+ private async findPRNodeInWorkspaceFolder ( workspaceNode : WorkspaceFolderNode , pullRequest : PullRequestModel ) : Promise < PRNode | undefined > {
237+ const children = await workspaceNode . getChildren ( false ) ;
238+ for ( const child of children ) {
239+ if ( child instanceof CategoryTreeNode ) {
240+ const found = await this . findPRNodeInCategory ( child , pullRequest ) ;
241+ if ( found ) return found ;
242+ }
243+ }
244+ return undefined ;
245+ }
246+
247+ /**
248+ * Search for PR node within a category node
249+ */
250+ private async findPRNodeInCategory ( categoryNode : CategoryTreeNode , pullRequest : PullRequestModel ) : Promise < PRNode | undefined > {
251+ const children = await categoryNode . getChildren ( false ) ;
252+ for ( const child of children ) {
253+ if ( child instanceof PRNode && ( child . pullRequestModel . number === pullRequest . number ) && ( child . pullRequestModel . remote . owner === pullRequest . remote . owner ) && ( child . pullRequestModel . remote . repositoryName === pullRequest . remote . repositoryName ) ) {
254+ return child ;
255+ }
256+ }
257+ return undefined ;
258+ }
259+
177260 initialize ( reviewModels : ReviewModel [ ] , credentialStore : CredentialStore ) {
178261 if ( this . _initialized ) {
179262 throw new Error ( 'Tree has already been initialized!' ) ;
0 commit comments