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

Commit 0559af1

Browse files
authored
Merge branch 'master' into fixes/culture-null
2 parents 16fbe22 + 7123237 commit 0559af1

23 files changed

+618
-142
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
namespace GitHub.Models
66
{
7+
public enum DiffSide
8+
{
9+
Right,
10+
Left,
11+
}
12+
713
/// <summary>
814
/// Represents a file in a pull request.
915
/// </summary>
@@ -41,5 +47,11 @@ public interface IPullRequestSessionFile : INotifyPropertyChanged
4147
/// Gets the inline comments threads for the file.
4248
/// </summary>
4349
IReadOnlyList<IInlineCommentThreadModel> InlineCommentThreads { get; }
50+
51+
/// <summary>
52+
/// Gets an observable that is raised with a collection of 0-based line numbers when the
53+
/// review comments on the file are changed.
54+
/// </summary>
55+
IObservable<IReadOnlyList<Tuple<int, DiffSide>>> LinesChanged { get; }
4456
}
4557
}

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

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

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@ public class PullRequestTextBufferInfo
1515
/// </summary>
1616
/// <param name="session">The pull request session.</param>
1717
/// <param name="relativePath">The relative path to the file in the repository.</param>
18-
/// <param name="isLeftComparisonBuffer">
19-
/// Whether the buffer represents the left-hand-side of a comparison.
20-
/// </param>
18+
/// <param name="side">Which side of a diff comparision the buffer represents.</param>
2119
public PullRequestTextBufferInfo(
2220
IPullRequestSession session,
2321
string relativePath,
24-
bool isLeftComparisonBuffer)
22+
DiffSide? side)
2523
{
2624
Session = session;
2725
RelativePath = relativePath;
28-
IsLeftComparisonBuffer = isLeftComparisonBuffer;
26+
Side = side;
2927
}
3028

3129
/// <summary>
@@ -39,8 +37,8 @@ public PullRequestTextBufferInfo(
3937
public string RelativePath { get; }
4038

4139
/// <summary>
42-
/// Gets a value indicating whether the buffer represents the left-hand-side of a comparison.
40+
/// Gets a value indicating which side of a diff comparision the buffer represents.
4341
/// </summary>
44-
public bool IsLeftComparisonBuffer { get; }
42+
public DiffSide? Side { get; }
4543
}
4644
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ public interface IPullRequestSession
2525
/// </summary>
2626
IPullRequestModel PullRequest { get; }
2727

28+
/// <summary>
29+
/// Gets an observable that indicates that<see cref="PullRequest"/> has been updated.
30+
/// </summary>
31+
/// <remarks>
32+
/// This notification is different to listening for a PropertyChanged event because the
33+
/// pull request model may be updated in-place which will not result in a PropertyChanged
34+
/// notification.
35+
/// </remarks>
36+
IObservable<IPullRequestModel> PullRequestChanged { get; }
37+
2838
/// <summary>
2939
/// Gets the local repository.
3040
/// </summary>

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<Tuple<int, DiffSide>>> linesChanged = new Subject<IReadOnlyList<Tuple<int, DiffSide>>>();
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+
set
63+
{
64+
var lines = (inlineCommentThreads ?? Enumerable.Empty<IInlineCommentThreadModel>())?
65+
.Concat(value ?? Enumerable.Empty<IInlineCommentThreadModel>())
66+
.Select(x => Tuple.Create(x.LineNumber, x.DiffLineType == DiffChangeType.Delete ? DiffSide.Left : DiffSide.Right))
67+
.Where(x => x.Item1 >= 0)
68+
.Distinct()
69+
.ToList();
70+
inlineCommentThreads = value;
71+
NotifyLinesChanged(lines);
72+
}
6073
}
74+
75+
/// <inheritdoc/>
76+
public IObservable<IReadOnlyList<Tuple<int, DiffSide>>> 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<Tuple<int, DiffSide>> 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/IPullRequestSessionService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ IReadOnlyList<IInlineCommentThreadModel> BuildCommentThreads(
6464
/// <returns>
6565
/// A collection of updated line numbers.
6666
/// </returns>
67-
IReadOnlyList<int> UpdateCommentThreads(
67+
IReadOnlyList<Tuple<int, DiffSide>> UpdateCommentThreads(
6868
IReadOnlyList<IInlineCommentThreadModel> threads,
6969
IReadOnlyList<DiffChunk> diff);
7070

src/GitHub.InlineReviews/Services/PullRequestSession.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using GitHub.Services;
1010
using ReactiveUI;
1111
using System.Threading;
12+
using System.Reactive.Subjects;
1213

1314
namespace GitHub.InlineReviews.Services
1415
{
@@ -30,6 +31,7 @@ public class PullRequestSession : ReactiveObject, IPullRequestSession
3031
string mergeBase;
3132
IReadOnlyList<IPullRequestSessionFile> files;
3233
IPullRequestModel pullRequest;
34+
Subject<IPullRequestModel> pullRequestChanged = new Subject<IPullRequestModel>();
3335

3436
public PullRequestSession(
3537
IPullRequestSessionService service,
@@ -155,6 +157,8 @@ public async Task Update(IPullRequestModel pullRequest)
155157
{
156158
await UpdateFile(file);
157159
}
160+
161+
pullRequestChanged.OnNext(pullRequest);
158162
}
159163

160164
async Task AddComment(IPullRequestReviewCommentModel comment)
@@ -233,6 +237,9 @@ private set
233237
}
234238
}
235239

240+
/// <inheritdoc/>
241+
public IObservable<IPullRequestModel> PullRequestChanged => pullRequestChanged;
242+
236243
/// <inheritdoc/>
237244
public ILocalRepositoryModel LocalRepository { get; }
238245

0 commit comments

Comments
 (0)