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

Commit d302713

Browse files
authored
Merge pull request #1230 from github/refactor/pr-sessions-2
Refactoring Pull Request Sessions (again)
2 parents 3a71c8e + 96e7601 commit d302713

31 files changed

+2151
-1164
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
<HintPath>..\..\packages\Microsoft.VisualStudio.Text.Data.14.3.25407\lib\net45\Microsoft.VisualStudio.Text.Data.dll</HintPath>
5555
<Private>True</Private>
5656
</Reference>
57+
<Reference Include="Microsoft.VisualStudio.Text.Logic, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
58+
<HintPath>..\..\packages\Microsoft.VisualStudio.Text.Logic.14.3.25407\lib\net45\Microsoft.VisualStudio.Text.Logic.dll</HintPath>
59+
<Private>True</Private>
60+
</Reference>
61+
<Reference Include="Microsoft.VisualStudio.Text.UI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
62+
<HintPath>..\..\packages\Microsoft.VisualStudio.Text.UI.14.3.25407\lib\net45\Microsoft.VisualStudio.Text.UI.dll</HintPath>
63+
<Private>True</Private>
64+
</Reference>
5765
<Reference Include="PresentationCore" />
5866
<Reference Include="System" />
5967
<Reference Include="System.ComponentModel.Composition" />
@@ -95,8 +103,8 @@
95103
<Compile Include="GlobalSuppressions.cs" />
96104
<Compile Include="Models\IAvatarContainer.cs" />
97105
<Compile Include="Models\IConnectionRepositoryHostMap.cs" />
98-
<Compile Include="Models\IEditorContentSource.cs" />
99106
<Compile Include="Models\IInlineCommentThreadModel.cs" />
107+
<Compile Include="Models\IPullRequestSessionLiveFile.cs" />
100108
<Compile Include="Models\IPullRequestSessionFile.cs" />
101109
<Compile Include="Models\IRepositoryHosts.cs" />
102110
<Compile Include="Models\PullRequestTextBufferInfo.cs" />

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

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

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
4-
using GitHub.Services;
54

65
namespace GitHub.Models
76
{
87
/// <summary>
9-
/// A file in a pull request session.
8+
/// Represents a file in a pull request.
109
/// </summary>
1110
/// <remarks>
12-
/// A pull request session file represents the real-time state of a file in a pull request in
13-
/// the IDE. If the pull request branch is checked out, it represents the state of a file from
14-
/// the pull request model updated to the current state of the code on disk and in the editor.
11+
/// A <see cref="IPullRequestSessionFile"/> holds the review comments for a file in a pull
12+
/// request together with associated information such as the commit SHA of the file and the
13+
/// diff with the file's merge base.
1514
/// </remarks>
1615
/// <seealso cref="IPullRequestSession"/>
1716
/// <seealso cref="IPullRequestSessionManager"/>
1817
public interface IPullRequestSessionFile : INotifyPropertyChanged
1918
{
19+
/// <summary>
20+
/// Gets the SHA of the base commit of the file in the pull request.
21+
/// </summary>
22+
string BaseSha { get; }
23+
2024
/// <summary>
2125
/// Gets the SHA of the current commit of the file, or null if the file has uncommitted
2226
/// changes.
@@ -31,12 +35,7 @@ public interface IPullRequestSessionFile : INotifyPropertyChanged
3135
/// <summary>
3236
/// Gets the diff between the PR merge base and the current state of the file.
3337
/// </summary>
34-
IList<DiffChunk> Diff { get; }
35-
36-
/// <summary>
37-
/// Gets the source for the editor contents for the file.
38-
/// </summary>
39-
IEditorContentSource ContentSource { get; }
38+
IReadOnlyList<DiffChunk> Diff { get; }
4039

4140
/// <summary>
4241
/// Gets the inline comments threads for the file.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using GitHub.Services;
4+
5+
namespace GitHub.Models
6+
{
7+
/// <summary>
8+
/// A file in a pull request session that tracks editor content.
9+
/// </summary>
10+
/// <remarks>
11+
/// A live session file extends <see cref="IPullRequestSessionFile"/> to update the file's
12+
/// review comments in real time, based on the contents of an editor and
13+
/// <see cref="IPullRequestSessionManager.CurrentSession"/>.
14+
/// </remarks>
15+
public interface IPullRequestSessionLiveFile : IPullRequestSessionFile
16+
{
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; }
22+
}
23+
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@ namespace GitHub.Models
55
{
66
/// <summary>
77
/// When attached as a property to a Visual Studio ITextBuffer, informs the inline comment
8-
/// tagger that the buffer represents a buffer opened from a pull request.
8+
/// tagger that the buffer represents a buffer opened from a pull request at the HEAD commit
9+
/// of a pull request.
910
/// </summary>
1011
public class PullRequestTextBufferInfo
1112
{
1213
/// <summary>
1314
/// Initializes a new instance of the <see cref="PullRequestTextBufferInfo"/> class.
1415
/// </summary>
1516
/// <param name="session">The pull request session.</param>
16-
/// <param name="filePath">The full path to the file.</param>
17+
/// <param name="relativePath">The relative path to the file in the repository.</param>
1718
/// <param name="isLeftComparisonBuffer">
1819
/// Whether the buffer represents the left-hand-side of a comparison.
1920
/// </param>
2021
public PullRequestTextBufferInfo(
2122
IPullRequestSession session,
22-
string filePath,
23+
string relativePath,
2324
bool isLeftComparisonBuffer)
2425
{
2526
Session = session;
26-
FilePath = filePath;
27+
RelativePath = relativePath;
2728
IsLeftComparisonBuffer = isLeftComparisonBuffer;
2829
}
2930

@@ -33,9 +34,9 @@ public PullRequestTextBufferInfo(
3334
public IPullRequestSession Session { get; }
3435

3536
/// <summary>
36-
/// Gets the full path to the file.
37+
/// Gets the relative path to the file in the repository.
3738
/// </summary>
38-
public string FilePath { get; }
39+
public string RelativePath { get; }
3940

4041
/// <summary>
4142
/// Gets a value indicating whether the buffer represents the left-hand-side of a comparison.

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

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
44
using GitHub.Models;
5-
using ReactiveUI;
65

76
namespace GitHub.Services
87
{
98
/// <summary>
10-
/// A pull request session used to display inline reviews.
9+
/// A pull request session used to display inline comments.
1110
/// </summary>
12-
/// <remarks>
13-
/// A pull request session represents the real-time state of a pull request in the IDE.
14-
/// It takes the pull request model and updates according to the current state of the
15-
/// repository on disk and in the editor.
16-
/// </remarks>
1711
public interface IPullRequestSession
1812
{
1913
/// <summary>
@@ -65,26 +59,10 @@ public interface IPullRequestSession
6559
Task<IPullRequestSessionFile> GetFile(string relativePath);
6660

6761
/// <summary>
68-
/// Gets a file touched by the pull request.
69-
/// </summary>
70-
/// <param name="relativePath">The relative path to the file.</param>
71-
/// <param name="contentSource">The editor file content source.</param>
72-
/// <returns>
73-
/// A <see cref="IPullRequestSessionFile"/> object or null if the file was not touched by
74-
/// the pull request.
75-
/// </returns>
76-
Task<IPullRequestSessionFile> GetFile(
77-
string relativePath,
78-
IEditorContentSource contentSource);
79-
80-
/// <summary>
81-
/// Converts a path to a path relative to the current repository.
62+
/// Gets the merge base SHA for the pull request.
8263
/// </summary>
83-
/// <param name="path">The path.</param>
84-
/// <returns>
85-
/// The relative path, or null if the specified path is not in the repository.
86-
/// </returns>
87-
string GetRelativePath(string path);
64+
/// <returns>The merge base SHA.</returns>
65+
Task<string> GetMergeBase();
8866

8967
/// <summary>
9068
/// Posts a new PR review comment.
@@ -111,12 +89,5 @@ Task<IPullRequestSessionFile> GetFile(
11189
/// <param name="pullRequest">The new pull request model.</param>
11290
/// <returns>A task which completes when the session has completed updating.</returns>
11391
Task Update(IPullRequestModel pullRequest);
114-
115-
/// <summary>
116-
/// Notifies the session that the contents of a file in the editor have changed.
117-
/// </summary>
118-
/// <param name="relativePath">The relative path to the file.</param>
119-
/// <returns>A task which completes when the session has completed updating.</returns>
120-
Task UpdateEditorContent(string relativePath);
12192
}
12293
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@
33
using System.Threading.Tasks;
44
using GitHub.Models;
55
using Microsoft.VisualStudio.Text;
6+
using Microsoft.VisualStudio.Text.Editor;
67

78
namespace GitHub.Services
89
{
910
/// <summary>
1011
/// Manages pull request sessions.
1112
/// </summary>
13+
/// <remarks>
14+
/// If the currently checked out branch represents a pull request then <see cref="CurrentSession"/>
15+
/// will return an <see cref="IPullRequestSession"/> containing the details of that pull request.
16+
/// A session for any other pull request can also be retrieved by calling
17+
/// <see cref="GetSession(IPullRequestModel)"/>.
18+
///
19+
/// Calling <see cref="GetLiveFile(string, ITextView, ITextBuffer)"/> will return an
20+
/// <see cref="IPullRequestSessionFile"/> which tracks both the contents of a text buffer and the
21+
/// current session, and updates the review comments in real-time.
22+
/// </remarks>
1223
public interface IPullRequestSessionManager : INotifyPropertyChanged
1324
{
1425
/// <summary>
@@ -20,6 +31,28 @@ public interface IPullRequestSessionManager : INotifyPropertyChanged
2031
/// </returns>
2132
IPullRequestSession CurrentSession { get; }
2233

34+
/// <summary>
35+
/// Gets an <see cref="IPullRequestSessionFile"/> that tracks the live state of a document.
36+
/// </summary>
37+
/// <param name="relativePath">The relative path to the file in the repository.</param>
38+
/// <param name="textView">The text view that is showing the file.</param>
39+
/// <param name="textBuffer">The text buffer with the file contents.</param>
40+
/// <returns>An <see cref="IPullRequestSessionLiveFile"/>.</returns>
41+
Task<IPullRequestSessionLiveFile> GetLiveFile(
42+
string relativePath,
43+
ITextView textView,
44+
ITextBuffer textBuffer);
45+
46+
/// <summary>
47+
/// Gets the path of a document displayed in a text buffer, relative to the current
48+
/// repository.
49+
/// </summary>
50+
/// <param name="buffer">The text buffer.</param>
51+
/// <returns>
52+
/// The relative path, or null if the buffer does not represent a file in the repository.
53+
/// </returns>
54+
string GetRelativePath(ITextBuffer buffer);
55+
2356
/// <summary>
2457
/// Gets a pull request session for a pull request that may not be checked out.
2558
/// </summary>

src/GitHub.Exports.Reactive/packages.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<package id="LibGit2Sharp.NativeBinaries" version="1.0.129" targetFramework="net461" />
55
<package id="Microsoft.VisualStudio.CoreUtility" version="14.3.25407" targetFramework="net461" />
66
<package id="Microsoft.VisualStudio.Text.Data" version="14.3.25407" targetFramework="net461" />
7+
<package id="Microsoft.VisualStudio.Text.Logic" version="14.3.25407" targetFramework="net461" />
8+
<package id="Microsoft.VisualStudio.Text.UI" version="14.3.25407" targetFramework="net461" />
79
<package id="Rx-Core" version="2.2.5-custom" targetFramework="net45" />
810
<package id="Rx-Interfaces" version="2.2.5-custom" targetFramework="net45" />
911
<package id="Rx-Linq" version="2.2.5-custom" targetFramework="net45" />

src/GitHub.Exports/Models/DiffUtilities.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static IEnumerable<DiffChunk> ParseFragment(string diff)
1616
{
1717
string line;
1818
DiffChunk chunk = null;
19-
int diffLine = 0;
19+
int diffLine = -1;
2020
int oldLine = -1;
2121
int newLine = -1;
2222

@@ -31,6 +31,8 @@ public static IEnumerable<DiffChunk> ParseFragment(string diff)
3131
yield return chunk;
3232
}
3333

34+
if (diffLine == -1) diffLine = 0;
35+
3436
chunk = new DiffChunk
3537
{
3638
OldLineNumber = oldLine = int.Parse(headerMatch.Groups[1].Value),
@@ -70,7 +72,7 @@ public static IEnumerable<DiffChunk> ParseFragment(string diff)
7072
}
7173
}
7274

73-
++diffLine;
75+
if (diffLine != -1) ++diffLine;
7476
}
7577

7678
if (chunk != null)

src/GitHub.InlineReviews/GitHub.InlineReviews.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<Compile Include="Glyph\IGlyphFactory.cs" />
7676
<Compile Include="InlineReviewsPackage.cs" />
7777
<Compile Include="Models\InlineCommentThreadModel.cs" />
78+
<Compile Include="Models\PullRequestSessionLiveFile.cs" />
7879
<Compile Include="Models\PullRequestSessionFile.cs" />
7980
<Compile Include="Tags\MouseEnterAndLeaveEventRouter.cs" />
8081
<Compile Include="Peek\InlineCommentPeekableItem.cs" />

0 commit comments

Comments
 (0)