Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 3adac31

Browse files
committed
React to session changes in InlineCommentTagger.
1 parent 8841522 commit 3adac31

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

src/GitHub.InlineReviews/Services/PullRequestSessionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public string GetRelativePath(ITextBuffer buffer)
125125
var document = sessionService.GetDocument(buffer);
126126
var path = document?.FilePath;
127127

128-
if (!string.IsNullOrWhiteSpace(path) && Path.IsPathRooted(path))
128+
if (!string.IsNullOrWhiteSpace(path) && Path.IsPathRooted(path) && repository != null)
129129
{
130130
var basePath = repository.LocalPath;
131131

src/GitHub.InlineReviews/Tags/InlineCommentTagger.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
using Microsoft.VisualStudio.Text;
1414
using Microsoft.VisualStudio.Text.Editor;
1515
using Microsoft.VisualStudio.Text.Tagging;
16+
using ReactiveUI;
17+
1618
namespace 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

Comments
 (0)