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

Commit 208710a

Browse files
committed
Move InlineCommentPeekService to GitHub.App.
So that it can be used everywhere. Had to refactor it slightly to remove some dependencies.
1 parent ad7d558 commit 208710a

File tree

8 files changed

+52
-62
lines changed

8 files changed

+52
-62
lines changed

src/GitHub.InlineReviews/Services/InlineCommentPeekService.cs renamed to src/GitHub.App/Services/InlineCommentPeekService.cs

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,25 @@
22
using System.ComponentModel.Composition;
33
using System.Linq;
44
using System.Reactive.Linq;
5-
using System.Threading.Tasks;
6-
using GitHub.Api;
75
using GitHub.Extensions;
8-
using GitHub.Factories;
9-
using GitHub.InlineReviews.Peek;
10-
using GitHub.InlineReviews.Tags;
116
using GitHub.Models;
12-
using GitHub.Primitives;
13-
using GitHub.Services;
7+
using GitHub.ViewModels;
148
using Microsoft.VisualStudio.Language.Intellisense;
159
using Microsoft.VisualStudio.Text;
1610
using Microsoft.VisualStudio.Text.Differencing;
1711
using Microsoft.VisualStudio.Text.Editor;
1812
using Microsoft.VisualStudio.Text.Outlining;
1913
using Microsoft.VisualStudio.Text.Projection;
2014

21-
namespace GitHub.InlineReviews.Services
15+
namespace GitHub.Services
2216
{
2317
/// <summary>
2418
/// Shows inline comments in a peek view.
2519
/// </summary>
2620
[Export(typeof(IInlineCommentPeekService))]
2721
class InlineCommentPeekService : IInlineCommentPeekService
2822
{
23+
const string relationship = "GitHubCodeReview";
2924
readonly IOutliningManagerService outliningService;
3025
readonly IPeekBroker peekBroker;
3126
readonly IUsageTracker usageTracker;
@@ -90,69 +85,46 @@ public void Hide(ITextView textView)
9085
}
9186

9287
/// <inheritdoc/>
93-
public ITrackingPoint Show(ITextView textView, AddInlineCommentTag tag)
88+
public ITrackingPoint Show(ITextView textView, DiffSide side, int lineNumber)
9489
{
95-
Guard.ArgumentNotNull(tag, nameof(tag));
96-
97-
var lineAndtrackingPoint = GetLineAndTrackingPoint(textView, tag);
90+
var lineAndtrackingPoint = GetLineAndTrackingPoint(textView, side, lineNumber);
9891
var line = lineAndtrackingPoint.Item1;
9992
var trackingPoint = lineAndtrackingPoint.Item2;
10093
var options = new PeekSessionCreationOptions(
10194
textView,
102-
InlineCommentPeekRelationship.Instance.Name,
95+
relationship,
10396
trackingPoint,
10497
defaultHeight: 0);
10598

10699
ExpandCollapsedRegions(textView, line.Extent);
107100

108101
var session = peekBroker.TriggerPeekSession(options);
109-
var item = session.PeekableItems.OfType<InlineCommentPeekableItem>().FirstOrDefault();
110-
item?.ViewModel.Close.Take(1).Subscribe(_ => session.Dismiss());
111-
112-
return trackingPoint;
113-
}
114-
115-
/// <inheritdoc/>
116-
public ITrackingPoint Show(ITextView textView, ShowInlineCommentTag tag)
117-
{
118-
Guard.ArgumentNotNull(textView, nameof(textView));
119-
Guard.ArgumentNotNull(tag, nameof(tag));
120-
121-
var lineAndtrackingPoint = GetLineAndTrackingPoint(textView, tag);
122-
var line = lineAndtrackingPoint.Item1;
123-
var trackingPoint = lineAndtrackingPoint.Item2;
124-
var options = new PeekSessionCreationOptions(
125-
textView,
126-
InlineCommentPeekRelationship.Instance.Name,
127-
trackingPoint,
128-
defaultHeight: 0);
129-
130-
ExpandCollapsedRegions(textView, line.Extent);
131-
132-
var session = peekBroker.TriggerPeekSession(options);
133-
var item = session.PeekableItems.OfType<InlineCommentPeekableItem>().FirstOrDefault();
134-
item?.ViewModel.Close.Take(1).Subscribe(_ => session.Dismiss());
135-
102+
var item = session.PeekableItems.OfType<IClosable>().FirstOrDefault();
103+
item?.Closed.Take(1).Subscribe(_ => session.Dismiss());
104+
136105
return trackingPoint;
137106
}
138107

139-
Tuple<ITextSnapshotLine, ITrackingPoint> GetLineAndTrackingPoint(ITextView textView, InlineCommentTag tag)
108+
Tuple<ITextSnapshotLine, ITrackingPoint> GetLineAndTrackingPoint(
109+
ITextView textView,
110+
DiffSide side,
111+
int lineNumber)
140112
{
141113
var diffModel = (textView as IWpfTextView)?.TextViewModel as IDifferenceTextViewModel;
142114
var snapshot = textView.TextSnapshot;
143115

144116
if (diffModel?.ViewType == DifferenceViewType.InlineView)
145117
{
146-
snapshot = tag.DiffChangeType == DiffChangeType.Delete ?
118+
snapshot = side == DiffSide.Left ?
147119
diffModel.Viewer.DifferenceBuffer.LeftBuffer.CurrentSnapshot :
148120
diffModel.Viewer.DifferenceBuffer.RightBuffer.CurrentSnapshot;
149121
}
150122

151-
var line = snapshot.GetLineFromLineNumber(tag.LineNumber);
123+
var line = snapshot.GetLineFromLineNumber(lineNumber);
152124
var trackingPoint = snapshot.CreateTrackingPoint(line.Start.Position, PointTrackingMode.Positive);
153125

154126
ExpandCollapsedRegions(textView, line.Extent);
155-
peekBroker.TriggerPeekSession(textView, trackingPoint, InlineCommentPeekRelationship.Instance.Name);
127+
peekBroker.TriggerPeekSession(textView, trackingPoint, relationship);
156128

157129
usageTracker.IncrementCounter(x => x.NumberOfPRReviewDiffViewInlineCommentOpen).Forget();
158130

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727

2828
<ItemGroup>
2929
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.1" />
30+
<PackageReference Include="Microsoft.VisualStudio.Language.Intellisense" Version="14.3.25407" />
3031
</ItemGroup>
3132
</Project>

src/GitHub.InlineReviews/Services/IInlineCommentPeekService.cs renamed to src/GitHub.Exports.Reactive/Services/IInlineCommentPeekService.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System;
2-
using GitHub.InlineReviews.Tags;
2+
using GitHub.Models;
33
using Microsoft.VisualStudio.Language.Intellisense;
44
using Microsoft.VisualStudio.Text;
55
using Microsoft.VisualStudio.Text.Editor;
66

7-
namespace GitHub.InlineReviews.Services
7+
namespace GitHub.Services
88
{
99
/// <summary>
1010
/// Shows inline comments in a peek view.
@@ -29,17 +29,10 @@ public interface IInlineCommentPeekService
2929
void Hide(ITextView textView);
3030

3131
/// <summary>
32-
/// Shows the peek view for a <see cref="ShowInlineCommentTag"/>.
32+
/// Shows the peek view for on an <see cref="ITextView"/>.
3333
/// </summary>
3434
/// <param name="textView">The text view.</param>
3535
/// <param name="tag">The tag.</param>
36-
ITrackingPoint Show(ITextView textView, ShowInlineCommentTag tag);
37-
38-
/// <summary>
39-
/// Shows the peek view for an <see cref="AddInlineCommentTag"/>.
40-
/// </summary>
41-
/// <param name="textView">The text view.</param>
42-
/// <param name="tag">The tag.</param>
43-
ITrackingPoint Show(ITextView textView, AddInlineCommentTag tag);
36+
ITrackingPoint Show(ITextView textView, DiffSide side, int lineNumber);
4437
}
4538
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Reactive;
3+
4+
namespace GitHub.ViewModels
5+
{
6+
/// <summary>
7+
/// Represents an entity that can be closed.
8+
/// </summary>
9+
public interface IClosable
10+
{
11+
/// <summary>
12+
/// Gets an observable that is fired when the entity is closed.
13+
/// </summary>
14+
IObservable<Unit> Closed { get; }
15+
}
16+
}

src/GitHub.InlineReviews/Commands/InlineCommentNavigationCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using GitHub.InlineReviews.Services;
77
using GitHub.InlineReviews.Tags;
88
using GitHub.Logging;
9+
using GitHub.Models;
910
using GitHub.Services;
1011
using GitHub.Services.Vssdk.Commands;
1112
using Microsoft.VisualStudio;
@@ -236,7 +237,8 @@ protected void ShowPeekComments(
236237
}
237238
}
238239

239-
var point = peekService.Show(textView, tag);
240+
var side = tag.DiffChangeType == DiffChangeType.Delete ? DiffSide.Left : DiffSide.Right;
241+
var point = peekService.Show(textView, side, tag.LineNumber);
240242

241243
if (parameter?.MoveCursor != false)
242244
{

src/GitHub.InlineReviews/GitHub.InlineReviews.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@
8181
<Compile Include="Margins\InlineCommentMargin.cs" />
8282
<Compile Include="Margins\InlineCommentMarginVisible.cs" />
8383
<Compile Include="Margins\InlineCommentMarginEnabled.cs" />
84+
<Compile Include="Peek\InlineCommentPeekableItem.cs" />
8485
<Compile Include="PullRequestStatusBarPackage.cs" />
8586
<Compile Include="InlineReviewsPackage.cs" />
8687
<Compile Include="Models\InlineCommentThreadModel.cs" />
8788
<Compile Include="Models\PullRequestSessionLiveFile.cs" />
8889
<Compile Include="Models\PullRequestSessionFile.cs" />
8990
<Compile Include="Services\PullRequestStatusBarManager.cs" />
9091
<Compile Include="Tags\MouseEnterAndLeaveEventRouter.cs" />
91-
<Compile Include="Peek\InlineCommentPeekableItem.cs" />
9292
<Compile Include="Peek\InlineCommentPeekableItemSource.cs" />
9393
<Compile Include="Peek\InlineCommentPeekableItemSourceProvider.cs" />
9494
<Compile Include="Peek\InlineCommentPeekableResultSource.cs" />
@@ -97,9 +97,7 @@
9797
<Compile Include="Peek\InlineCommentPeekResultPresentation.cs" />
9898
<Compile Include="Peek\InlineCommentPeekResultPresenter.cs" />
9999
<Compile Include="Properties\AssemblyInfo.cs" />
100-
<Compile Include="Services\IInlineCommentPeekService.cs" />
101100
<Compile Include="Services\IPullRequestSessionService.cs" />
102-
<Compile Include="Services\InlineCommentPeekService.cs" />
103101
<Compile Include="Services\PullRequestSession.cs" />
104102
<Compile Include="Services\PullRequestSessionManager.cs" />
105103
<Compile Include="Margins\InlineCommentMarginProvider.cs" />

src/GitHub.InlineReviews/Peek/InlineCommentPeekableItem.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
using System.Collections.Generic;
33
using Microsoft.VisualStudio.Language.Intellisense;
44
using GitHub.InlineReviews.ViewModels;
5+
using GitHub.ViewModels;
6+
using System.Reactive;
57

68
namespace GitHub.InlineReviews.Peek
79
{
8-
class InlineCommentPeekableItem : IPeekableItem
10+
class InlineCommentPeekableItem : IPeekableItem, IClosable
911
{
1012
public InlineCommentPeekableItem(InlineCommentPeekViewModel viewModel)
1113
{
@@ -17,6 +19,8 @@ public InlineCommentPeekableItem(InlineCommentPeekViewModel viewModel)
1719

1820
public IEnumerable<IPeekRelationship> Relationships => new[] { InlineCommentPeekRelationship.Instance };
1921

22+
public IObservable<Unit> Closed => ViewModel.Close;
23+
2024
public IPeekResultSource GetOrCreateResultSource(string relationshipName)
2125
{
2226
return new InlineCommentPeekableResultSource(ViewModel);

src/GitHub.InlineReviews/Tags/InlineCommentGlyphFactory.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
using Microsoft.VisualStudio.Text.Editor;
88
using Microsoft.VisualStudio.Text.Formatting;
99
using GitHub.InlineReviews.Services;
10+
using GitHub.Models;
11+
using GitHub.Services;
1012

1113
namespace GitHub.InlineReviews.Tags
1214
{
@@ -72,12 +74,14 @@ bool OpenThreadView(InlineCommentTag tag)
7274

7375
if (addTag != null)
7476
{
75-
peekService.Show(textView, addTag);
77+
var side = addTag.DiffChangeType == DiffChangeType.Delete ? DiffSide.Left : DiffSide.Right;
78+
peekService.Show(textView, side, addTag.LineNumber);
7679
return true;
7780
}
7881
else if (showTag != null)
7982
{
80-
peekService.Show(textView, showTag);
83+
var side = showTag.DiffChangeType == DiffChangeType.Delete ? DiffSide.Left : DiffSide.Right;
84+
peekService.Show(textView, side, showTag.LineNumber);
8185
return true;
8286
}
8387

0 commit comments

Comments
 (0)