@@ -92,6 +92,8 @@ export class PRNode extends TreeNode implements CommentHandler, vscode.Commentin
9292
9393 private _inMemPRContentProvider ?: vscode . Disposable ;
9494
95+ private _refreshCommentsInProgress ?: Promise < void > ;
96+
9597 private _command : vscode . Command ;
9698
9799 private _commentHandlerId : string ;
@@ -198,7 +200,13 @@ export class PRNode extends TreeNode implements CommentHandler, vscode.Commentin
198200 // Create Comment Threads when the editor is visible
199201 // Dispose when the editor is invisible and remove them from the cache map
200202 // Comment Threads in cache map is updated only when users trigger refresh
201- await this . refreshExistingPREditors ( e , false ) ;
203+ if ( ! this . _refreshCommentsInProgress ) {
204+ this . _refreshCommentsInProgress = this . refreshExistingPREditors ( e , false ) ;
205+ } else {
206+ this . _refreshCommentsInProgress = this . _refreshCommentsInProgress . then ( async _ => {
207+ return await this . refreshExistingPREditors ( e , false ) ;
208+ } ) ;
209+ }
202210 } ) ) ;
203211
204212 this . _disposables . push ( vscode . window . onDidChangeActiveTextEditor ( async e => {
@@ -309,8 +317,10 @@ export class PRNode extends TreeNode implements CommentHandler, vscode.Commentin
309317 }
310318 } ) ;
311319
320+ const fileChanges = await this . getFileChanges ( ) ;
321+
312322 currentPRDocuments . forEach ( async editor => {
313- let fileChange = ( await this . getFileChanges ( ) ) . find ( fc => fc . fileName === editor . fileName ) ;
323+ let fileChange = fileChanges . find ( fc => fc . fileName === editor . fileName ) ;
314324
315325 if ( ! fileChange || fileChange instanceof RemoteFileChangeNode ) {
316326 return ;
@@ -331,7 +341,7 @@ export class PRNode extends TreeNode implements CommentHandler, vscode.Commentin
331341 oldCommentThreads = [ ...oldLeftSideCommentThreads , ...oldRightSideCommentThreads ] ;
332342 }
333343
334- this . updateFileChangeCommentThreads ( oldCommentThreads , [ ...newLeftCommentThreads , ...newRightSideCommentThreads ] , fileChange ) ;
344+ this . updateFileChangeCommentThreads ( oldCommentThreads , [ ...newLeftCommentThreads , ...newRightSideCommentThreads ] , fileChange , commentThreadCache ) ;
335345 } ) ;
336346
337347 }
@@ -447,10 +457,9 @@ export class PRNode extends TreeNode implements CommentHandler, vscode.Commentin
447457 return true ;
448458 }
449459
450- private async createCommentThreads ( fileName : string , commentThreads : ThreadData [ ] ) {
451- const prCommentController = ( await this . resolvePRCommentController ( ) ) ;
460+ private createCommentThreads ( fileName : string , commentThreads : ThreadData [ ] , commentThreadCache : { [ key : string ] : GHPRCommentThread [ ] } ) {
452461 const threads = commentThreads . map ( thread => createVSCodeCommentThread ( thread , this . _commentController ! ) ) ;
453- prCommentController . commentThreadCache [ fileName ] = threads ;
462+ commentThreadCache [ fileName ] = threads ;
454463 }
455464
456465 private updateCommentThreadComments ( thread : GHPRCommentThread , newComments : ( GHPRComment | TemporaryComment ) [ ] ) {
@@ -515,7 +524,7 @@ export class PRNode extends TreeNode implements CommentHandler, vscode.Commentin
515524 // #endregion
516525
517526 // #region Incremental updates
518- private updateFileChangeCommentThreads ( oldCommentThreads : GHPRCommentThread [ ] , newCommentThreads : ThreadData [ ] , newFileChange : InMemFileChangeNode ) {
527+ private updateFileChangeCommentThreads ( oldCommentThreads : GHPRCommentThread [ ] , newCommentThreads : ThreadData [ ] , newFileChange : InMemFileChangeNode , commentThreadCache : { [ key : string ] : GHPRCommentThread [ ] } ) {
519528 // remove
520529 oldCommentThreads . forEach ( thread => {
521530 // No current threads match old thread, it has been removed
@@ -566,7 +575,7 @@ export class PRNode extends TreeNode implements CommentHandler, vscode.Commentin
566575 } ) ;
567576
568577 if ( added . length ) {
569- this . createCommentThreads ( newFileChange . fileName , added ) ;
578+ this . createCommentThreads ( newFileChange . fileName , added , commentThreadCache ) ;
570579 }
571580 }
572581 }
0 commit comments