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

Commit b9d176a

Browse files
grokysSteven Kirk
authored andcommitted
Add change notifications to IPullRequestSessionFile
Moved from `IPullRequestLiveFile`, which has been deleted. Also added InlineCommentTagger tests.
1 parent 75be49c commit b9d176a

File tree

12 files changed

+449
-76
lines changed

12 files changed

+449
-76
lines changed

src/GitHub.Exports.Reactive/GitHub.Exports.Reactive.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
<Compile Include="Models\IAvatarContainer.cs" />
105105
<Compile Include="Models\IConnectionRepositoryHostMap.cs" />
106106
<Compile Include="Models\IInlineCommentThreadModel.cs" />
107-
<Compile Include="Models\IPullRequestSessionLiveFile.cs" />
108107
<Compile Include="Models\IPullRequestSessionFile.cs" />
109108
<Compile Include="Models\IRepositoryHosts.cs" />
110109
<Compile Include="Models\PullRequestTextBufferInfo.cs" />

src/GitHub.Exports.Reactive/Models/IPullRequestSessionFile.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,11 @@ public interface IPullRequestSessionFile : INotifyPropertyChanged
4141
/// Gets the inline comments threads for the file.
4242
/// </summary>
4343
IReadOnlyList<IInlineCommentThreadModel> InlineCommentThreads { get; }
44+
45+
/// <summary>
46+
/// Gets an observable that is raised with a collection of 0-based line numbers when the
47+
/// review comments on the file are changed.
48+
/// </summary>
49+
IObservable<IReadOnlyList<int>> LinesChanged { get; }
4450
}
4551
}

src/GitHub.Exports.Reactive/Models/IPullRequestSessionLiveFile.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/GitHub.Exports.Reactive/Services/IPullRequestSessionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public interface IPullRequestSessionManager : INotifyPropertyChanged
3838
/// <param name="textView">The text view that is showing the file.</param>
3939
/// <param name="textBuffer">The text buffer with the file contents.</param>
4040
/// <returns>An <see cref="IPullRequestSessionLiveFile"/>.</returns>
41-
Task<IPullRequestSessionLiveFile> GetLiveFile(
41+
Task<IPullRequestSessionFile> GetLiveFile(
4242
string relativePath,
4343
ITextView textView,
4444
ITextBuffer textBuffer);

src/GitHub.InlineReviews/Models/PullRequestSessionFile.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reactive.Subjects;
35
using GitHub.Models;
46
using ReactiveUI;
57

@@ -17,6 +19,7 @@ namespace GitHub.InlineReviews.Models
1719
/// <seealso cref="PullRequestSessionManager"/>
1820
public class PullRequestSessionFile : ReactiveObject, IPullRequestSessionFile
1921
{
22+
readonly Subject<IReadOnlyList<int>> linesChanged = new Subject<IReadOnlyList<int>>();
2023
IReadOnlyList<DiffChunk> diff;
2124
string commitSha;
2225
IReadOnlyList<IInlineCommentThreadModel> inlineCommentThreads;
@@ -53,10 +56,29 @@ public string CommitSha
5356
}
5457

5558
/// <inheritdoc/>
56-
public virtual IReadOnlyList<IInlineCommentThreadModel> InlineCommentThreads
59+
public IReadOnlyList<IInlineCommentThreadModel> InlineCommentThreads
5760
{
5861
get { return inlineCommentThreads; }
59-
internal set { this.RaiseAndSetIfChanged(ref inlineCommentThreads, value); }
62+
internal set
63+
{
64+
var lines = inlineCommentThreads?
65+
.Concat(value ?? Enumerable.Empty<IInlineCommentThreadModel>())
66+
.Select(x => x.LineNumber)
67+
.Where(x => x >= 0)
68+
.Distinct()
69+
.ToList();
70+
inlineCommentThreads = value;
71+
NotifyLinesChanged(lines);
72+
}
6073
}
74+
75+
/// <inheritdoc/>
76+
public IObservable<IReadOnlyList<int>> LinesChanged => linesChanged;
77+
78+
/// <summary>
79+
/// Raises the <see cref="LinesChanged"/> signal.
80+
/// </summary>
81+
/// <param name="lines">The lines that have changed.</param>
82+
public void NotifyLinesChanged(IReadOnlyList<int> lines) => linesChanged.OnNext(lines);
6183
}
6284
}

src/GitHub.InlineReviews/Models/PullRequestSessionLiveFile.cs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ namespace GitHub.InlineReviews.Models
1111
/// A file in a pull request session that tracks editor content.
1212
/// </summary>
1313
/// <remarks>
14-
/// A live session file extends <see cref="IPullRequestSessionFile"/> to update the file's
14+
/// A live session file extends <see cref="PullRequestSessionFile"/> to update the file's
1515
/// review comments in real time, based on the contents of an editor and
1616
/// <see cref="IPullRequestSessionManager.CurrentSession"/>.
1717
/// </remarks>
18-
public sealed class PullRequestSessionLiveFile : PullRequestSessionFile, IPullRequestSessionLiveFile, IDisposable
18+
public sealed class PullRequestSessionLiveFile : PullRequestSessionFile, IDisposable
1919
{
20-
readonly Subject<IReadOnlyList<int>> linesChanged = new Subject<IReadOnlyList<int>>();
21-
2220
public PullRequestSessionLiveFile(
2321
string relativePath,
2422
ITextBuffer textBuffer,
@@ -49,26 +47,6 @@ public PullRequestSessionLiveFile(
4947
/// </summary>
5048
public ISubject<ITextSnapshot, ITextSnapshot> Rebuild { get; }
5149

52-
/// <inheritdoc/>
53-
public IObservable<IReadOnlyList<int>> LinesChanged => linesChanged;
54-
55-
/// <inheritdoc/>
56-
public override IReadOnlyList<IInlineCommentThreadModel> InlineCommentThreads
57-
{
58-
get { return base.InlineCommentThreads; }
59-
internal set
60-
{
61-
var lines = base.InlineCommentThreads?
62-
.Concat(value ?? Enumerable.Empty<IInlineCommentThreadModel>())
63-
.Select(x => x.LineNumber)
64-
.Where(x => x >= 0)
65-
.Distinct()
66-
.ToList();
67-
base.InlineCommentThreads = value;
68-
NotifyLinesChanged(lines);
69-
}
70-
}
71-
7250
/// <summary>
7351
/// Disposes of the resources in <see cref="ToDispose"/>.
7452
/// </summary>
@@ -77,11 +55,5 @@ public void Dispose()
7755
ToDispose?.Dispose();
7856
ToDispose = null;
7957
}
80-
81-
/// <summary>
82-
/// Raises the <see cref="LinesChanged"/> signal.
83-
/// </summary>
84-
/// <param name="lines">The lines that have changed.</param>
85-
public void NotifyLinesChanged(IReadOnlyList<int> lines) => linesChanged.OnNext(lines);
8658
}
8759
}

src/GitHub.InlineReviews/Services/PullRequestSessionManager.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ public IPullRequestSession CurrentSession
7171
private set { this.RaiseAndSetIfChanged(ref currentSession, value); }
7272
}
7373

74-
public async Task<IPullRequestSessionLiveFile> GetLiveFile(
74+
public async Task<IPullRequestSessionFile> GetLiveFile(
7575
string relativePath,
7676
ITextView textView,
7777
ITextBuffer textBuffer)
7878
{
7979
PullRequestSessionLiveFile result;
8080

8181
if (!textBuffer.Properties.TryGetProperty(
82-
typeof(IPullRequestSessionLiveFile),
82+
typeof(IPullRequestSessionFile),
8383
out result))
8484
{
8585
var dispose = new CompositeDisposable();
@@ -90,7 +90,7 @@ public async Task<IPullRequestSessionLiveFile> GetLiveFile(
9090
sessionService.CreateRebuildSignal());
9191

9292
textBuffer.Properties.AddProperty(
93-
typeof(IPullRequestSessionLiveFile),
93+
typeof(IPullRequestSessionFile),
9494
result);
9595

9696
await UpdateLiveFile(result, true);
@@ -408,7 +408,7 @@ private void CloseLiveFiles(ITextBuffer textBuffer)
408408
PullRequestSessionLiveFile file;
409409

410410
if (textBuffer.Properties.TryGetProperty(
411-
typeof(IPullRequestSessionLiveFile),
411+
typeof(IPullRequestSessionFile),
412412
out file))
413413
{
414414
file.Dispose();
@@ -428,7 +428,7 @@ private void CloseLiveFiles(ITextBuffer textBuffer)
428428
void TextBufferChanged(object sender, TextContentChangedEventArgs e)
429429
{
430430
var textBuffer = (ITextBuffer)sender;
431-
var file = textBuffer.Properties.GetProperty<PullRequestSessionLiveFile>(typeof(IPullRequestSessionLiveFile));
431+
var file = textBuffer.Properties.GetProperty<PullRequestSessionLiveFile>(typeof(IPullRequestSessionFile));
432432
InvalidateLiveThreads(file, e.After);
433433
file.Rebuild.OnNext(textBuffer.CurrentSnapshot);
434434
}

src/GitHub.InlineReviews/Tags/InlineCommentTagger.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace GitHub.InlineReviews.Tags
2020
/// <summary>
2121
/// Creates tags in an <see cref="ITextBuffer"/> for inline comment threads.
2222
/// </summary>
23-
sealed class InlineCommentTagger : ITagger<InlineCommentTag>, IDisposable
23+
public sealed class InlineCommentTagger : ITagger<InlineCommentTag>, IDisposable
2424
{
2525
static readonly IReadOnlyList<ITagSpan<InlineCommentTag>> EmptyTags = new ITagSpan<InlineCommentTag>[0];
2626
readonly IGitService gitService;
@@ -29,7 +29,6 @@ sealed class InlineCommentTagger : ITagger<InlineCommentTag>, IDisposable
2929
readonly ITextBuffer buffer;
3030
readonly ITextView view;
3131
readonly IPullRequestSessionManager sessionManager;
32-
readonly IInlineCommentPeekService peekService;
3332
bool needsInitialize = true;
3433
string relativePath;
3534
bool leftHandSide;
@@ -44,23 +43,20 @@ public InlineCommentTagger(
4443
IDiffService diffService,
4544
ITextView view,
4645
ITextBuffer buffer,
47-
IPullRequestSessionManager sessionManager,
48-
IInlineCommentPeekService peekService)
46+
IPullRequestSessionManager sessionManager)
4947
{
5048
Guard.ArgumentNotNull(gitService, nameof(gitService));
5149
Guard.ArgumentNotNull(gitClient, nameof(gitClient));
5250
Guard.ArgumentNotNull(diffService, nameof(diffService));
5351
Guard.ArgumentNotNull(buffer, nameof(buffer));
5452
Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
55-
Guard.ArgumentNotNull(peekService, nameof(peekService));
5653

5754
this.gitService = gitService;
5855
this.gitClient = gitClient;
5956
this.diffService = diffService;
6057
this.buffer = buffer;
6158
this.view = view;
6259
this.sessionManager = sessionManager;
63-
this.peekService = peekService;
6460
}
6561

6662
public bool ShowMargin => file != null;
@@ -155,6 +151,7 @@ async Task Initialize()
155151
session = bufferInfo.Session;
156152
relativePath = bufferInfo.RelativePath;
157153
file = await session.GetFile(relativePath);
154+
fileSubscription = file.LinesChanged.Subscribe(NotifyTagsChanged);
158155
leftHandSide = bufferInfo.IsLeftComparisonBuffer;
159156
NotifyTagsChanged();
160157
}

src/GitHub.InlineReviews/Tags/InlineCommentTaggerProvider.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,22 @@ class InlineCommentTaggerProvider : IViewTaggerProvider
2222
readonly IGitClient gitClient;
2323
readonly IDiffService diffService;
2424
readonly IPullRequestSessionManager sessionManager;
25-
readonly IInlineCommentPeekService peekService;
2625

2726
[ImportingConstructor]
2827
public InlineCommentTaggerProvider(
2928
IGitService gitService,
3029
IGitClient gitClient,
3130
IDiffService diffService,
32-
IPullRequestSessionManager sessionManager,
33-
IInlineCommentPeekService peekService)
31+
IPullRequestSessionManager sessionManager)
3432
{
3533
Guard.ArgumentNotNull(gitService, nameof(gitService));
3634
Guard.ArgumentNotNull(gitClient, nameof(gitClient));
3735
Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
38-
Guard.ArgumentNotNull(peekService, nameof(peekService));
3936

4037
this.gitService = gitService;
4138
this.gitClient = gitClient;
4239
this.diffService = diffService;
4340
this.sessionManager = sessionManager;
44-
this.peekService = peekService;
4541
}
4642

4743
public ITagger<T> CreateTagger<T>(ITextView view, ITextBuffer buffer) where T : ITag
@@ -53,8 +49,7 @@ public ITagger<T> CreateTagger<T>(ITextView view, ITextBuffer buffer) where T :
5349
diffService,
5450
view,
5551
buffer,
56-
sessionManager,
57-
peekService)) as ITagger<T>;
52+
sessionManager)) as ITagger<T>;
5853
}
5954
}
6055
}

test/GitHub.InlineReviews.UnitTests/GitHub.InlineReviews.UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
<Compile Include="Models\DiffUtilitiesTests.cs" />
108108
<Compile Include="Services\PullRequestSessionManagerTests.cs" />
109109
<Compile Include="Services\PullRequestSessionServiceTests.cs" />
110+
<Compile Include="Tags\InlineCommentTaggerTests.cs" />
110111
<Compile Include="TestDoubles\FakeDiffService.cs" />
111112
<Compile Include="Properties\AssemblyInfo.cs" />
112113
<Compile Include="Properties\Resources.Designer.cs">

0 commit comments

Comments
 (0)