@@ -15,8 +15,8 @@ import { EXTENSION_ID } from '../constants';
1515import { CopilotRemoteAgentManager } from '../github/copilotRemoteAgent' ;
1616import { CredentialStore } from '../github/credentials' ;
1717import { FolderRepositoryManager , ReposManagerState } from '../github/folderRepositoryManager' ;
18+ import { PullRequestChangeEvent } from '../github/githubRepository' ;
1819import { PRType } from '../github/interface' ;
19- import { IssueModel } from '../github/issueModel' ;
2020import { issueMarkdown } from '../github/markdownUtils' ;
2121import { NotificationProvider } from '../github/notifications' ;
2222import { PullRequestModel } from '../github/pullRequestModel' ;
@@ -60,7 +60,7 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
6060 this . _register ( this . prsTreeModel . onDidChangeData ( e => {
6161 if ( e instanceof FolderRepositoryManager ) {
6262 this . refreshRepo ( e ) ;
63- } else if ( Array . isArray ( e ) && e [ 0 ] instanceof IssueModel ) {
63+ } else if ( Array . isArray ( e ) ) {
6464 this . refreshPullRequests ( e ) ;
6565 } else {
6666 this . refresh ( undefined , true ) ;
@@ -322,18 +322,52 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
322322 }
323323 }
324324
325- private refreshPullRequests ( pullRequests : IssueModel [ ] ) : void {
325+ private refreshPullRequests ( pullRequests : PullRequestChangeEvent [ ] ) : void {
326326 if ( ! this . _children ?. length || ! pullRequests ?. length ) {
327327 return ;
328328 }
329- const toRefresh : TreeNode [ ] = [ ] ;
329+ const prNodesToRefresh : TreeNode [ ] = [ ] ;
330+ const prsWithStateChange = new Set ( ) ;
331+ const prNumbers = new Set ( ) ;
332+
333+ for ( const prChange of pullRequests ) {
334+ prNumbers . add ( prChange . model . number ) ;
335+ if ( prChange . event . state ) {
336+ prsWithStateChange . add ( prChange . model . number ) ;
337+ }
338+ }
339+
340+ const hasPRNode = ( node : TreeNode ) => {
341+ const prNodes = node . children ?? [ ] ;
342+ for ( const prNode of prNodes ) {
343+ if ( prNode instanceof PRNode && prsWithStateChange . has ( prNode . pullRequestModel . number ) ) {
344+ return true ;
345+ }
346+ }
347+ return false ;
348+ } ;
349+
350+ const categoriesToRefresh : Set < CategoryTreeNode > = new Set ( ) ;
351+ // First find the categories to refresh, since if we refresh a category we don't need to specifically refresh its children
352+ for ( const child of this . _children ) {
353+ if ( child instanceof WorkspaceFolderNode ) {
354+ const categories = child . children ?? [ ] ;
355+ for ( const category of categories ) {
356+ if ( category instanceof CategoryTreeNode && ! categoriesToRefresh . has ( category ) && hasPRNode ( category ) ) {
357+ categoriesToRefresh . add ( category ) ;
358+ }
359+ }
360+ } else if ( child instanceof CategoryTreeNode && ! categoriesToRefresh . has ( child ) && hasPRNode ( child ) ) {
361+ categoriesToRefresh . add ( child ) ;
362+ }
363+ }
364+
330365 // 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.
331- const prNumbers = new Set ( pullRequests . map ( pr => pr . number ) ) ;
332366 const collectPRNodes = ( node : TreeNode ) => {
333367 const prNodes = node . children ?? [ ] ;
334368 for ( const prNode of prNodes ) {
335369 if ( prNode instanceof PRNode && prNumbers . has ( prNode . pullRequestModel . number ) ) {
336- toRefresh . push ( prNode ) ;
370+ prNodesToRefresh . push ( prNode ) ;
337371 }
338372 }
339373 } ;
@@ -342,16 +376,16 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
342376 if ( child instanceof WorkspaceFolderNode ) {
343377 const categories = child . children ?? [ ] ;
344378 for ( const category of categories ) {
345- if ( category instanceof CategoryTreeNode ) {
379+ if ( category instanceof CategoryTreeNode && ! categoriesToRefresh . has ( category ) ) {
346380 collectPRNodes ( category ) ;
347381 }
348382 }
349- } else if ( child instanceof CategoryTreeNode ) {
383+ } else if ( child instanceof CategoryTreeNode && ! categoriesToRefresh . has ( child ) ) {
350384 collectPRNodes ( child ) ;
351385 }
352386 }
353- if ( toRefresh . length ) {
354- this . _onDidChangeTreeData . fire ( toRefresh ) ;
387+ if ( prNodesToRefresh . length || categoriesToRefresh . size > 0 ) {
388+ this . _onDidChangeTreeData . fire ( [ ... Array . from ( categoriesToRefresh ) , ... prNodesToRefresh ] ) ;
355389 }
356390 }
357391
0 commit comments