1313using Microsoft . VisualStudio . Text ;
1414using Microsoft . VisualStudio . Text . Editor ;
1515using Microsoft . VisualStudio . Text . Tagging ;
16+ using ReactiveUI ;
17+
1618namespace GitHub . InlineReviews . Tags
1719{
1820 /// <summary>
@@ -34,6 +36,7 @@ sealed class InlineCommentTagger : ITagger<InlineCommentTag>, IDisposable
3436 IPullRequestSession session ;
3537 IPullRequestSessionFile file ;
3638 IDisposable fileSubscription ;
39+ IDisposable sessionManagerSubscription ;
3740
3841 public InlineCommentTagger (
3942 IGitService gitService ,
@@ -66,6 +69,8 @@ public InlineCommentTagger(
6669
6770 public void Dispose ( )
6871 {
72+ sessionManagerSubscription ? . Dispose ( ) ;
73+ sessionManagerSubscription = null ;
6974 fileSubscription ? . Dispose ( ) ;
7075 fileSubscription = null ;
7176 }
@@ -78,7 +83,7 @@ public IEnumerable<ITagSpan<InlineCommentTag>> GetTags(NormalizedSnapshotSpanCol
7883 ForgetWithLogging ( Initialize ( ) ) ;
7984 return EmptyTags ;
8085 }
81- else if ( file != null )
86+ else if ( file ? . InlineCommentThreads != null )
8287 {
8388 var result = new List < ITagSpan < InlineCommentTag > > ( ) ;
8489 var currentSession = session ?? sessionManager . CurrentSession ;
@@ -151,21 +156,34 @@ async Task Initialize()
151156 relativePath = bufferInfo . RelativePath ;
152157 file = await session . GetFile ( relativePath ) ;
153158 leftHandSide = bufferInfo . IsLeftComparisonBuffer ;
159+ NotifyTagsChanged ( ) ;
154160 }
155161 else
156162 {
157- relativePath = sessionManager . GetRelativePath ( buffer ) ;
163+ await InitializeLiveFile ( ) ;
164+ sessionManagerSubscription = sessionManager
165+ . WhenAnyValue ( x => x . CurrentSession )
166+ . Skip ( 1 )
167+ . Subscribe ( _ => ForgetWithLogging ( InitializeLiveFile ( ) ) ) ;
168+ }
169+ }
158170
159- if ( relativePath != null )
160- {
161- var liveFile = await sessionManager . GetLiveFile ( relativePath , view , buffer ) ;
162- liveFile . LinesChanged . Subscribe ( NotifyTagsChanged ) ;
163- file = liveFile ;
164- }
165- else
166- {
167- file = null ;
168- }
171+ async Task InitializeLiveFile ( )
172+ {
173+ fileSubscription ? . Dispose ( ) ;
174+ fileSubscription = null ;
175+
176+ relativePath = sessionManager . GetRelativePath ( buffer ) ;
177+
178+ if ( relativePath != null )
179+ {
180+ var liveFile = await sessionManager . GetLiveFile ( relativePath , view , buffer ) ;
181+ fileSubscription = liveFile . LinesChanged . Subscribe ( NotifyTagsChanged ) ;
182+ file = liveFile ;
183+ }
184+ else
185+ {
186+ file = null ;
169187 }
170188
171189 NotifyTagsChanged ( ) ;
0 commit comments