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

Commit a9e5e31

Browse files
committed
WIP
1 parent f9d1399 commit a9e5e31

File tree

6 files changed

+54
-17
lines changed

6 files changed

+54
-17
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ namespace GitHub.Models
1616
/// <seealso cref="IPullRequestSessionManager"/>
1717
public interface IPullRequestSessionFile : INotifyPropertyChanged
1818
{
19+
/// <summary>
20+
/// Gets an observable that is raised with a collection of 0-based line numbers when the
21+
/// review comments on the file are changed.
22+
/// </summary>
23+
IObservable<IReadOnlyList<int>> LinesChanged { get; }
24+
1925
/// <summary>
2026
/// Gets the SHA of the base commit of the file in the pull request.
2127
/// </summary>

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,5 @@ namespace GitHub.Models
1414
/// </remarks>
1515
public interface IPullRequestSessionLiveFile : IPullRequestSessionFile
1616
{
17-
/// <summary>
18-
/// Gets an observable that is raised with a collection of 0-based line numbers when the
19-
/// review comments on the file are changed.
20-
/// </summary>
21-
IObservable<IReadOnlyList<int>> LinesChanged { get; }
2217
}
2318
}

src/GitHub.InlineReviews/Models/PullRequestSessionFile.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Reactive.Subjects;
34
using GitHub.Models;
45
using ReactiveUI;
56

@@ -17,6 +18,7 @@ namespace GitHub.InlineReviews.Models
1718
/// <seealso cref="PullRequestSessionManager"/>
1819
public class PullRequestSessionFile : ReactiveObject, IPullRequestSessionFile
1920
{
21+
readonly Subject<IReadOnlyList<int>> linesChanged = new Subject<IReadOnlyList<int>>();
2022
IReadOnlyList<DiffChunk> diff;
2123
string commitSha;
2224
IReadOnlyList<IInlineCommentThreadModel> inlineCommentThreads;
@@ -58,5 +60,14 @@ public virtual IReadOnlyList<IInlineCommentThreadModel> InlineCommentThreads
5860
get { return inlineCommentThreads; }
5961
internal set { this.RaiseAndSetIfChanged(ref inlineCommentThreads, value); }
6062
}
63+
64+
/// <inheritdoc/>
65+
public IObservable<IReadOnlyList<int>> LinesChanged => linesChanged;
66+
67+
/// <summary>
68+
/// Raises the <see cref="LinesChanged"/> signal.
69+
/// </summary>
70+
/// <param name="lines">The lines that have changed.</param>
71+
public void NotifyLinesChanged(IReadOnlyList<int> lines) => linesChanged.OnNext(lines);
6172
}
6273
}

src/GitHub.InlineReviews/Models/PullRequestSessionLiveFile.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ namespace GitHub.InlineReviews.Models
1717
/// </remarks>
1818
public sealed class PullRequestSessionLiveFile : PullRequestSessionFile, IPullRequestSessionLiveFile, IDisposable
1919
{
20-
readonly Subject<IReadOnlyList<int>> linesChanged = new Subject<IReadOnlyList<int>>();
21-
2220
public PullRequestSessionLiveFile(
2321
string relativePath,
2422
ITextBuffer textBuffer,
@@ -49,9 +47,6 @@ public PullRequestSessionLiveFile(
4947
/// </summary>
5048
public ISubject<ITextSnapshot, ITextSnapshot> Rebuild { get; }
5149

52-
/// <inheritdoc/>
53-
public IObservable<IReadOnlyList<int>> LinesChanged => linesChanged;
54-
5550
/// <inheritdoc/>
5651
public override IReadOnlyList<IInlineCommentThreadModel> InlineCommentThreads
5752
{
@@ -77,11 +72,5 @@ public void Dispose()
7772
ToDispose?.Dispose();
7873
ToDispose = null;
7974
}
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);
8675
}
8776
}

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">

test/GitHub.InlineReviews.UnitTests/Tags/InlineCommentTaggerTests.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,29 @@ public void ShouldReturnAddCommentTagForLhs()
131131
Assert.IsType<AddInlineCommentTag>(result[0].Tag);
132132
}
133133

134-
static IPullRequestSessionManager CreateSessionManager(bool leftHandSide)
134+
[Fact]
135+
public void ShouldRaiseTagsChangedOnThreadAddition()
136+
{
137+
var file = CreateSessionFile();
138+
var target = new InlineCommentTagger(
139+
Substitute.For<IGitService>(),
140+
Substitute.For<IGitClient>(),
141+
Substitute.For<IDiffService>(),
142+
Substitute.For<ITextView>(),
143+
Substitute.For<ITextBuffer>(),
144+
CreateSessionManager(file, leftHandSide: false));
145+
146+
var span = CreateSpan(14);
147+
var firstPass = target.GetTags(span);
148+
var result = target.GetTags(span).ToList();
149+
var raised = false;
150+
151+
target.TagsChanged += (s, e) => raised = e.Span.Start == 14;
152+
153+
Assert.True(raised);
154+
}
155+
156+
static IPullRequestSessionFile CreateSessionFile()
135157
{
136158
var diffChunk = new DiffChunk
137159
{
@@ -161,6 +183,19 @@ static IPullRequestSessionManager CreateSessionManager(bool leftHandSide)
161183
file.Diff.Returns(diff);
162184
file.InlineCommentThreads.Returns(threads);
163185

186+
return file;
187+
}
188+
189+
static IPullRequestSessionManager CreateSessionManager(bool leftHandSide)
190+
{
191+
var file = CreateSessionFile();
192+
return CreateSessionManager(file, leftHandSide);
193+
}
194+
195+
static IPullRequestSessionManager CreateSessionManager(
196+
IPullRequestSessionFile file,
197+
bool leftHandSide)
198+
{
164199
var session = Substitute.For<IPullRequestSession>();
165200
session.GetFile("file.cs").Returns(file);
166201

0 commit comments

Comments
 (0)