@@ -16,6 +16,7 @@ import { CopilotRemoteAgentManager } from '../github/copilotRemoteAgent';
1616import { CredentialStore } from '../github/credentials' ;
1717import { FolderRepositoryManager , ReposManagerState } from '../github/folderRepositoryManager' ;
1818import { PRType } from '../github/interface' ;
19+ import { IssueModel } from '../github/issueModel' ;
1920import { issueMarkdown } from '../github/markdownUtils' ;
2021import { NotificationProvider } from '../github/notifications' ;
2122import { PullRequestModel } from '../github/pullRequestModel' ;
@@ -33,7 +34,7 @@ import { TreeUtils } from './treeNodes/treeUtils';
3334import { WorkspaceFolderNode } from './treeNodes/workspaceFolderNode' ;
3435
3536export class PullRequestsTreeDataProvider extends Disposable implements vscode . TreeDataProvider < TreeNode > , BaseTreeNode {
36- private _onDidChangeTreeData = new vscode . EventEmitter < TreeNode | void > ( ) ;
37+ private _onDidChangeTreeData = new vscode . EventEmitter < TreeNode [ ] | TreeNode | void > ( ) ;
3738 readonly onDidChangeTreeData = this . _onDidChangeTreeData . event ;
3839 private _onDidChange = new vscode . EventEmitter < vscode . Uri > ( ) ;
3940 get onDidChange ( ) : vscode . Event < vscode . Uri > {
@@ -56,7 +57,15 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
5657 constructor ( private readonly _telemetry : ITelemetry , private readonly _context : vscode . ExtensionContext , private readonly _reposManager : RepositoriesManager , private readonly _copilotManager : CopilotRemoteAgentManager ) {
5758 super ( ) ;
5859 this . prsTreeModel = this . _register ( new PrsTreeModel ( this . _telemetry , this . _reposManager , _context ) ) ;
59- this . _register ( this . prsTreeModel . onDidChangeData ( folderManager => folderManager ? this . refreshRepo ( folderManager ) : this . refresh ( ) ) ) ;
60+ this . _register ( this . prsTreeModel . onDidChangeData ( e => {
61+ if ( e instanceof FolderRepositoryManager ) {
62+ this . refreshRepo ( e ) ;
63+ } else if ( Array . isArray ( e ) && e [ 0 ] instanceof IssueModel ) {
64+ this . refreshPullRequests ( e ) ;
65+ } else {
66+ this . refresh ( ) ;
67+ }
68+ } ) ) ;
6069 this . _register ( new PRStatusDecorationProvider ( this . prsTreeModel , this . _copilotManager ) ) ;
6170 this . _register ( vscode . commands . registerCommand ( 'pr.refreshList' , _ => {
6271 this . refresh ( undefined , true ) ;
@@ -98,7 +107,6 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
98107 tooltip : this . _copilotManager . notificationsCount === 1 ? vscode . l10n . t ( 'Coding agent has 1 pull request to view' ) : vscode . l10n . t ( 'Coding agent has {0} pull requests to view' , this . _copilotManager . notificationsCount ) ,
99108 value : this . _copilotManager . notificationsCount
100109 } ;
101- this . refresh ( ) ;
102110 } else {
103111 this . _view . badge = undefined ;
104112 }
@@ -311,6 +319,39 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
311319 }
312320 }
313321
322+ private refreshPullRequests ( pullRequests : IssueModel [ ] ) : void {
323+ if ( ! this . _children ?. length || ! pullRequests ?. length ) {
324+ return ;
325+ }
326+ const toRefresh : TreeNode [ ] = [ ] ;
327+ // Yes, multiple PRs can exist in different repos with the same number, but at worst we'll refresh all the duplicate numbers, which shouldn't be many.
328+ const prNumbers = new Set ( pullRequests . map ( pr => pr . number ) ) ;
329+ const collectPRNodes = ( node : TreeNode ) => {
330+ const prNodes = node . children ?? [ ] ;
331+ for ( const prNode of prNodes ) {
332+ if ( prNode instanceof PRNode && prNumbers . has ( prNode . pullRequestModel . number ) ) {
333+ toRefresh . push ( prNode ) ;
334+ }
335+ }
336+ } ;
337+
338+ for ( const child of this . _children ) {
339+ if ( child instanceof WorkspaceFolderNode ) {
340+ const categories = child . children ?? [ ] ;
341+ for ( const category of categories ) {
342+ if ( category instanceof CategoryTreeNode ) {
343+ collectPRNodes ( category ) ;
344+ }
345+ }
346+ } else if ( child instanceof CategoryTreeNode ) {
347+ collectPRNodes ( child ) ;
348+ }
349+ }
350+ if ( toRefresh . length ) {
351+ this . _onDidChangeTreeData . fire ( toRefresh ) ;
352+ }
353+ }
354+
314355 getTreeItem ( element : TreeNode ) : vscode . TreeItem | Promise < vscode . TreeItem > {
315356 return element . getTreeItem ( ) ;
316357 }
0 commit comments