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

Commit 8fb18b4

Browse files
Adding different types of inline tags
1 parent cc4219a commit 8fb18b4

22 files changed

+449
-98
lines changed

src/GitHub.App/ViewModels/GitHubPane/PullRequestFilesViewModel.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ public async Task InitializeAsync(
127127
subscriptions.Add(file.WhenAnyValue(x => x.InlineAnnotations)
128128
.Subscribe(x =>
129129
{
130-
var count = x.Count(model =>
131-
model.Annotation.AnnotationLevel.HasValue && model.Annotation.AnnotationLevel ==
132-
CheckAnnotationLevel.Failure);
130+
var count = x.Count(model => model.AnnotationLevel == CheckAnnotationLevel.Failure);
133131

134132
node.AnnotationErrorCount = count;
135133
node.AnnotationWarningCount = x.Count - count;

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@
55
/// </summary>
66
public interface IInlineAnnotationModel
77
{
8-
/// <summary>
9-
/// Gets the associated check run
10-
/// </summary>
11-
CheckRunModel CheckRun { get; }
12-
13-
/// <summary>
14-
/// Gets the annotation
15-
/// </summary>
16-
CheckRunAnnotationModel Annotation { get; }
8+
int StartLine { get; }
9+
int EndLine { get; }
10+
CheckAnnotationLevel AnnotationLevel { get; }
1711
}
1812
}
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
using GitHub.Models;
1+
using GitHub.Extensions;
22

3-
namespace GitHub.InlineReviews.Services
3+
namespace GitHub.Models
44
{
55
public class InlineAnnotationModel: IInlineAnnotationModel
66
{
7+
private CheckRunModel checkRun;
8+
private CheckRunAnnotationModel annotation;
9+
710
public InlineAnnotationModel(CheckRunModel checkRun, CheckRunAnnotationModel annotation)
811
{
9-
CheckRun = checkRun;
10-
Annotation = annotation;
12+
Guard.ArgumentNotNull(annotation.AnnotationLevel, nameof(annotation.AnnotationLevel));
13+
14+
this.checkRun = checkRun;
15+
this.annotation = annotation;
1116
}
1217

13-
public CheckRunModel CheckRun { get; }
14-
public CheckRunAnnotationModel Annotation { get; }
18+
public int StartLine => annotation.StartLine;
19+
20+
public int EndLine => annotation.EndLine;
21+
22+
public CheckAnnotationLevel AnnotationLevel => annotation.AnnotationLevel.Value;
1523
}
1624
}

src/GitHub.InlineReviews/GitHub.InlineReviews.csproj

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
<Compile Include="Models\PullRequestSessionLiveFile.cs" />
9494
<Compile Include="Models\PullRequestSessionFile.cs" />
9595
<Compile Include="Services\PullRequestStatusBarManager.cs" />
96+
<Compile Include="Tags\InlineAnnotationTag.cs" />
97+
<Compile Include="Tags\InlineTagBase.cs" />
9698
<Compile Include="Tags\MouseEnterAndLeaveEventRouter.cs" />
9799
<Compile Include="Peek\InlineCommentPeekableItem.cs" />
98100
<Compile Include="Peek\InlineCommentPeekableItemSource.cs" />
@@ -111,6 +113,16 @@
111113
<Compile Include="Services\PullRequestSessionManager.cs" />
112114
<Compile Include="Margins\InlineCommentMarginProvider.cs" />
113115
<Compile Include="Services\PullRequestSessionService.cs" />
116+
<Compile Include="Tags\ShowInlineAnnotationWarningGlyph.xaml.cs">
117+
<DependentUpon>ShowInlineAnnotationWarningGlyph.xaml</DependentUpon>
118+
</Compile>
119+
<Compile Include="Tags\ShowInlineAnnotationNoticeGlyph.xaml.cs">
120+
<DependentUpon>ShowInlineAnnotationNoticeGlyph.xaml</DependentUpon>
121+
</Compile>
122+
<Compile Include="Tags\ShowInlineAnnotationTag.cs" />
123+
<Compile Include="Tags\ShowInlineAnnotationFailureGlyph.xaml.cs">
124+
<DependentUpon>ShowInlineAnnotationFailureGlyph.xaml</DependentUpon>
125+
</Compile>
114126
<Compile Include="ViewModels\PullRequestFileMarginViewModel.cs" />
115127
<Compile Include="ViewModels\CommentViewModel.cs" />
116128
<Compile Include="ViewModels\ICommentThreadViewModel.cs" />
@@ -142,7 +154,7 @@
142154
<Compile Include="Tags\InlineCommentGlyphFactory.cs" />
143155
<Compile Include="Tags\InlineCommentTag.cs" />
144156
<Compile Include="Tags\ShowInlineCommentTag.cs" />
145-
<Compile Include="Tags\InlineCommentTagger.cs" />
157+
<Compile Include="Tags\InlineTagger.cs" />
146158
<Compile Include="Tags\InlineCommentTaggerProvider.cs" />
147159
<Compile Include="ViewModels\InlineCommentThreadViewModel.cs" />
148160
<Compile Include="ViewModels\ICommentViewModel.cs" />
@@ -456,6 +468,18 @@
456468
<SubType>Designer</SubType>
457469
<ContainsDesignTimeResources>true</ContainsDesignTimeResources>
458470
</Page>
471+
<Page Include="Tags\ShowInlineAnnotationWarningGlyph.xaml">
472+
<Generator>MSBuild:Compile</Generator>
473+
<SubType>Designer</SubType>
474+
</Page>
475+
<Page Include="Tags\ShowInlineAnnotationNoticeGlyph.xaml">
476+
<Generator>MSBuild:Compile</Generator>
477+
<SubType>Designer</SubType>
478+
</Page>
479+
<Page Include="Tags\ShowInlineAnnotationFailureGlyph.xaml">
480+
<Generator>MSBuild:Compile</Generator>
481+
<SubType>Designer</SubType>
482+
</Page>
459483
<Page Include="Views\PullRequestFileMarginView.xaml">
460484
<SubType>Designer</SubType>
461485
<Generator>MSBuild:Compile</Generator>

src/GitHub.InlineReviews/Models/PullRequestSessionFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public IReadOnlyList<IInlineAnnotationModel> InlineAnnotations
111111
{
112112
var lines = (inlineAnnotations ?? Enumerable.Empty<IInlineAnnotationModel>())?
113113
.Concat(value ?? Enumerable.Empty<IInlineAnnotationModel>())
114-
.Select(x => Tuple.Create(x.Annotation.StartLine, DiffSide.Right))
114+
.Select(x => Tuple.Create(x.StartLine, DiffSide.Right))
115115
.Where(x => x.Item1 >= 0)
116116
.Distinct()
117117
.ToList();

src/GitHub.InlineReviews/Services/PullRequestSessionService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ public IReadOnlyList<IInlineAnnotationModel> BuildAnnotations(
107107
?.SelectMany(checkSuite => checkSuite.CheckRuns)
108108
.SelectMany(checkRun =>
109109
checkRun.Annotations
110-
.Where(model => model.Filename == relativePath)
110+
.Where(annotation => annotation.Filename == relativePath && annotation.AnnotationLevel.HasValue)
111111
.Select(annotation => new InlineAnnotationModel(checkRun, annotation)))
112-
.OrderBy(tuple => tuple.Annotation.StartLine)
112+
.OrderBy(tuple => tuple.StartLine)
113113
.ToArray();
114114
}
115115

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using GitHub.Models;
2+
using GitHub.Services;
3+
4+
namespace GitHub.InlineReviews.Tags
5+
{
6+
/// <summary>
7+
/// Base class for inline annotation tags.
8+
/// </summary>
9+
public abstract class InlineAnnotationTag : InlineTagBase
10+
{
11+
protected InlineAnnotationTag(
12+
IPullRequestSession session,
13+
int lineNumber) : base(session, lineNumber)
14+
{
15+
}
16+
}
17+
}

src/GitHub.InlineReviews/Tags/InlineCommentGlyphFactory.cs

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

1112
namespace GitHub.InlineReviews.Tags
1213
{
@@ -45,23 +46,36 @@ public IEnumerable<Type> GetTagTypes()
4546
}
4647

4748
[SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.String.Format(System.String,System.Object)")]
48-
static UserControl CreateGlyph(InlineCommentTag tag)
49+
static UserControl CreateGlyph(InlineTagBase tag)
4950
{
50-
var addTag = tag as AddInlineCommentTag;
51-
var showTag = tag as ShowInlineCommentTag;
52-
53-
if (addTag != null)
51+
if (tag is AddInlineCommentTag addCommentTag)
5452
{
5553
return new AddInlineCommentGlyph();
5654
}
57-
else if (showTag != null)
55+
56+
if (tag is ShowInlineCommentTag showCommentTag)
5857
{
5958
return new ShowInlineCommentGlyph()
6059
{
61-
Opacity = showTag.Thread.IsStale ? 0.5 : 1,
60+
Opacity = showCommentTag.Thread.IsStale ? 0.5 : 1,
6261
};
6362
}
6463

64+
if (tag is ShowInlineAnnotationTag showAnnotation)
65+
{
66+
switch (showAnnotation.Annotation.AnnotationLevel)
67+
{
68+
case CheckAnnotationLevel.Failure:
69+
return new ShowInlineAnnotationFailureGlyph();
70+
case CheckAnnotationLevel.Notice:
71+
return new ShowInlineAnnotationNoticeGlyph();
72+
case CheckAnnotationLevel.Warning:
73+
return new ShowInlineAnnotationWarningGlyph();
74+
default:
75+
throw new ArgumentOutOfRangeException();
76+
}
77+
}
78+
6579
throw new ArgumentException($"Unknown 'InlineCommentTag' type '{tag}'");
6680
}
6781

src/GitHub.InlineReviews/Tags/InlineCommentTag.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,16 @@ namespace GitHub.InlineReviews.Tags
1010
/// </summary>
1111
/// <seealso cref="AddInlineCommentTag"/>
1212
/// <seealso cref="ShowInlineCommentTag"/>
13-
public abstract class InlineCommentTag : ITag
13+
public abstract class InlineCommentTag : InlineTagBase
1414
{
1515
protected InlineCommentTag(
1616
IPullRequestSession session,
1717
int lineNumber,
18-
DiffChangeType diffChangeType)
18+
DiffChangeType diffChangeType): base(session, lineNumber)
1919
{
20-
Guard.ArgumentNotNull(session, nameof(session));
21-
22-
LineNumber = lineNumber;
23-
Session = session;
2420
DiffChangeType = diffChangeType;
2521
}
2622

27-
public int LineNumber { get; }
28-
public IPullRequestSession Session { get; }
2923
public DiffChangeType DiffChangeType { get; }
3024
}
3125
}

src/GitHub.InlineReviews/Tags/InlineCommentTaggerProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace GitHub.InlineReviews.Tags
1212
{
1313
/// <summary>
14-
/// Factory class for <see cref="InlineCommentTagger"/>s.
14+
/// Factory class for <see cref="InlineTagger"/>s.
1515
/// </summary>
1616
[Export(typeof(IViewTaggerProvider))]
1717
[ContentType("text")]
@@ -32,7 +32,7 @@ public InlineCommentTaggerProvider(
3232
public ITagger<T> CreateTagger<T>(ITextView view, ITextBuffer buffer) where T : ITag
3333
{
3434
return buffer.Properties.GetOrCreateSingletonProperty(() =>
35-
new InlineCommentTagger(
35+
new InlineTagger(
3636
view,
3737
buffer,
3838
sessionManager)) as ITagger<T>;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using GitHub.Extensions;
2+
using GitHub.Services;
3+
using Microsoft.VisualStudio.Text.Tagging;
4+
5+
namespace GitHub.InlineReviews.Tags
6+
{
7+
/// <summary>
8+
/// Base class for inline tags.
9+
/// </summary>
10+
public abstract class InlineTagBase : ITag
11+
{
12+
protected InlineTagBase(
13+
IPullRequestSession session,
14+
int lineNumber)
15+
{
16+
Guard.ArgumentNotNull(session, nameof(session));
17+
18+
LineNumber = lineNumber;
19+
Session = session;
20+
}
21+
22+
public int LineNumber { get; }
23+
public IPullRequestSession Session { get; }
24+
}
25+
}

0 commit comments

Comments
 (0)