@@ -20,8 +20,9 @@ import { FileChangeNode } from './fileChangeNode';
2020import { TreeNode } from './treeNode' ;
2121
2222export class PRNode extends TreeNode {
23- private richContentChanges : RichFileChange [ ] ;
24- private commentsCache : Map < String , Comment [ ] > ;
23+ private _richContentChanges : RichFileChange [ ] ;
24+ private _commentsCache : Map < String , Comment [ ] > ;
25+ private _documentCommentsProvider : vscode . Disposable ;
2526
2627 constructor (
2728 private _prManager : IPullRequestManager ,
@@ -30,16 +31,25 @@ export class PRNode extends TreeNode {
3031 private _isLocal : boolean
3132 ) {
3233 super ( ) ;
34+ this . _documentCommentsProvider = null ;
3335 }
3436
3537 async getChildren ( ) : Promise < TreeNode [ ] > {
3638 try {
39+ if ( this . _documentCommentsProvider ) {
40+ this . _documentCommentsProvider . dispose ( ) ;
41+ }
42+
43+ if ( this . childrenDisposables && this . childrenDisposables . length ) {
44+ this . childrenDisposables . forEach ( dp => dp . dispose ( ) ) ;
45+ }
46+
3747 const comments = await this . _prManager . getPullRequestComments ( this . pullRequestModel ) ;
3848 const data = await this . _prManager . getPullRequestChangedFiles ( this . pullRequestModel ) ;
3949 await this . _prManager . fullfillPullRequestCommitInfo ( this . pullRequestModel ) ;
40- this . richContentChanges = await parseDiff ( data , this . repository , this . pullRequestModel . base . sha ) ;
41- this . commentsCache = new Map < String , Comment [ ] > ( ) ;
42- let fileChanges = this . richContentChanges . map ( change => {
50+ this . _richContentChanges = await parseDiff ( data , this . repository , this . pullRequestModel . base . sha ) ;
51+ this . _commentsCache = new Map < String , Comment [ ] > ( ) ;
52+ let fileChanges = this . _richContentChanges . map ( change => {
4353 let fileInRepo = path . resolve ( this . repository . path , change . fileName ) ;
4454 let changedItem = new FileChangeNode (
4555 this . pullRequestModel ,
@@ -51,22 +61,26 @@ export class PRNode extends TreeNode {
5161 change . diffHunks ,
5262 comments . filter ( comment => comment . path === change . fileName && comment . position !== null )
5363 ) ;
54- this . commentsCache . set ( change . fileName , changedItem . comments ) ;
64+ this . _commentsCache . set ( change . fileName , changedItem . comments ) ;
5565 return changedItem ;
5666 } ) ;
5767
5868 const _onDidChangeCommentThreads = new vscode . EventEmitter < vscode . CommentThreadChangedEvent > ( ) ;
59- vscode . workspace . registerDocumentCommentProvider ( {
69+
70+ this . _documentCommentsProvider = vscode . workspace . registerDocumentCommentProvider ( {
6071 onDidChangeCommentThreads : _onDidChangeCommentThreads . event ,
6172 provideDocumentComments : this . provideDocumentComments . bind ( this ) ,
6273 createNewCommentThread : this . createNewCommentThread . bind ( this ) ,
6374 replyToCommentThread : this . replyToCommentThread . bind ( this )
6475 } ) ;
6576
66- return [ new DescriptionNode ( 'Description' , {
77+ let result = [ new DescriptionNode ( 'Description' , {
6778 light : Resource . icons . light . Description ,
6879 dark : Resource . icons . dark . Description
6980 } , this . pullRequestModel ) , ...fileChanges ] ;
81+
82+ this . childrenDisposables = result ;
83+ return result ;
7084 } catch ( e ) {
7185 Logger . appendLine ( e ) ;
7286 }
@@ -88,7 +102,7 @@ export class PRNode extends TreeNode {
88102 let uri = document . uri ;
89103 let params = JSON . parse ( uri . query ) ;
90104
91- let fileChange = this . richContentChanges . find ( change => change . fileName === params . fileName ) ;
105+ let fileChange = this . _richContentChanges . find ( change => change . fileName === params . fileName ) ;
92106
93107 if ( ! fileChange ) {
94108 return null ;
@@ -144,7 +158,7 @@ export class PRNode extends TreeNode {
144158 if ( document . uri . scheme === 'pr' ) {
145159 let params = JSON . parse ( document . uri . query ) ;
146160 let isBase = params . base ;
147- let fileChange = this . richContentChanges . find ( change => change . fileName === params . fileName ) ;
161+ let fileChange = this . _richContentChanges . find ( change => change . fileName === params . fileName ) ;
148162 if ( ! fileChange ) {
149163 return null ;
150164 }
@@ -168,7 +182,7 @@ export class PRNode extends TreeNode {
168182 commentingRanges . push ( new vscode . Range ( startingLine , 0 , startingLine + length , 0 ) ) ;
169183 }
170184
171- let matchingComments = this . commentsCache . get ( fileChange . fileName ) ;
185+ let matchingComments = this . _commentsCache . get ( fileChange . fileName ) ;
172186
173187 if ( ! matchingComments || ! matchingComments . length ) {
174188 return {
@@ -218,4 +232,12 @@ export class PRNode extends TreeNode {
218232
219233 return null ;
220234 }
235+
236+ dispose ( ) : void {
237+ super . dispose ( ) ;
238+
239+ if ( this . _documentCommentsProvider ) {
240+ this . _documentCommentsProvider . dispose ( ) ;
241+ }
242+ }
221243}
0 commit comments