Skip to content

Commit a1438f1

Browse files
Make strongly typed
1 parent e5777b3 commit a1438f1

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

src/EditorFeatures/Core.Wpf/InlineHints/CachedAdornmentTagSpan.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ internal partial class InlineHintsTaggerProvider
1212
{
1313
/// <summary>
1414
/// The computed adornment tag for an inline hint, along with information needed to determine if it can be reused.
15-
/// This is created and cached on <see cref="InlineHintDataTag.AdditionalData"/> on demand so that we only create
16-
/// adornment tags once and reuse as long as possible.
15+
/// This is created and cached on <see cref="InlineHintDataTag{TAdditionalInformation}.AdditionalData"/> on demand
16+
/// so that we only create adornment tags once and reuse as long as possible.
1717
/// </summary>
1818
/// <param name="classified">Whether or not the adornment tag was classified. If the option for this changes, this
1919
/// cached tag should not be reused.</param>

src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTagger.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using System.Runtime.CompilerServices;
76
using Microsoft.CodeAnalysis.Collections;
87
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
98
using Microsoft.CodeAnalysis.Editor.Tagging;
@@ -25,13 +24,13 @@ namespace Microsoft.CodeAnalysis.Editor.InlineHints;
2524
internal partial class InlineHintsTaggerProvider
2625
{
2726
/// <summary>
28-
/// The purpose of this tagger is to convert the <see cref="InlineHintDataTag"/> to the <see
27+
/// The purpose of this tagger is to convert the <see cref="InlineHintDataTag{TAdditionalInformation}"/> to the <see
2928
/// cref="InlineHintsTag"/>, which actually creates the UIElement. It reacts to tags changing and updates the
3029
/// adornments accordingly.
3130
/// </summary>
3231
private sealed class InlineHintsTagger : EfficientTagger<IntraTextAdornmentTag>
3332
{
34-
private readonly EfficientTagger<InlineHintDataTag> _underlyingTagger;
33+
private readonly EfficientTagger<InlineHintDataTag<CachedAdornmentTagSpan>> _underlyingTagger;
3534

3635
private readonly IClassificationFormatMap _formatMap;
3736

@@ -50,7 +49,7 @@ public InlineHintsTagger(
5049
InlineHintsTaggerProvider taggerProvider,
5150
IWpfTextView textView,
5251
ITextBuffer subjectBuffer,
53-
EfficientTagger<InlineHintDataTag> tagger)
52+
EfficientTagger<InlineHintDataTag<CachedAdornmentTagSpan>> tagger)
5453
{
5554
_taggerProvider = taggerProvider;
5655

@@ -125,7 +124,7 @@ public override void AddTags(
125124

126125
var colorHints = _taggerProvider.EditorOptionsService.GlobalOptions.GetOption(InlineHintsViewOptionsStorage.ColorHints, document.Project.Language);
127126

128-
using var _1 = SegmentedListPool.GetPooledList<TagSpan<InlineHintDataTag>>(out var dataTagSpans);
127+
using var _1 = SegmentedListPool.GetPooledList<TagSpan<InlineHintDataTag<CachedAdornmentTagSpan>>>(out var dataTagSpans);
129128
_underlyingTagger.AddTags(spans, dataTagSpans);
130129

131130
// Presize so we can add the elements below without continually resizing.
@@ -147,10 +146,10 @@ public override void AddTags(
147146
}
148147

149148
private TagSpan<IntraTextAdornmentTag> GetOrCreateAdornmentTagsSpan(
150-
TagSpan<InlineHintDataTag> dataTagSpan, bool classify, TextFormattingRunProperties format)
149+
TagSpan<InlineHintDataTag<CachedAdornmentTagSpan>> dataTagSpan, bool classify, TextFormattingRunProperties format)
151150
{
152151
// If we've never computed the adornment info, or options have changed, then compute and cache the new information.
153-
var cachedTagInformation = (CachedAdornmentTagSpan?)dataTagSpan.Tag.AdditionalData;
152+
var cachedTagInformation = dataTagSpan.Tag.AdditionalData;
154153
if (cachedTagInformation is null || cachedTagInformation.Classified != classify || cachedTagInformation.Format != format)
155154
{
156155
var adornmentSpan = dataTagSpan.Span;

src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTaggerProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ internal sealed partial class InlineHintsTaggerProvider(
6363
/// its data tags. Then, on demand, we convert and cache those data tags into adornment tags and pass on the
6464
/// results.
6565
/// </summary>
66-
private readonly InlineHintsDataTaggerProvider _dataTaggerProvider = new(taggerHost, inlineHintKeyProcessor);
66+
private readonly InlineHintsDataTaggerProvider<CachedAdornmentTagSpan> _dataTaggerProvider = new(taggerHost, inlineHintKeyProcessor);
6767

6868
public ITagger<T>? CreateTagger<T>(ITextView textView, ITextBuffer subjectBuffer) where T : ITag
6969
{

src/EditorFeatures/Core/InlineHints/InlineHintDataTag.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ namespace Microsoft.CodeAnalysis.Editor.InlineHints;
1616
/// The simple tag that only holds information regarding the associated parameter name
1717
/// for the argument
1818
/// </summary>
19-
internal sealed class InlineHintDataTag(InlineHintsDataTaggerProvider provider, ITextSnapshot snapshot, InlineHint hint) : ITag, IEquatable<InlineHintDataTag>
19+
internal sealed class InlineHintDataTag<TAdditionalInformation>(
20+
InlineHintsDataTaggerProvider<TAdditionalInformation> provider, ITextSnapshot snapshot, InlineHint hint)
21+
: ITag, IEquatable<InlineHintDataTag<TAdditionalInformation>>
22+
where TAdditionalInformation : class
2023
{
21-
private readonly InlineHintsDataTaggerProvider _provider = provider;
24+
private readonly InlineHintsDataTaggerProvider<TAdditionalInformation> _provider = provider;
2225

2326
/// <summary>
2427
/// The snapshot this tag was created against.
@@ -31,17 +34,17 @@ internal sealed class InlineHintDataTag(InlineHintsDataTaggerProvider provider,
3134
/// Additional data that can be attached to the tag. For example, the view tagger uses this to attach the adornment
3235
/// tag information so it can be created and cached on demand.
3336
/// </summary>
34-
public object? AdditionalData;
37+
public TAdditionalInformation? AdditionalData;
3538

3639
// Intentionally throwing, we have never supported this facility, and there is no contract around placing
3740
// these tags in sets or maps.
3841
public override int GetHashCode()
3942
=> throw new NotImplementedException();
4043

4144
public override bool Equals(object? obj)
42-
=> obj is InlineHintDataTag tag && Equals(tag);
45+
=> obj is InlineHintDataTag<TAdditionalInformation> tag && Equals(tag);
4346

44-
public bool Equals(InlineHintDataTag? other)
47+
public bool Equals(InlineHintDataTag<TAdditionalInformation>? other)
4548
{
4649
if (other is null)
4750
return false;

src/EditorFeatures/Core/InlineHints/InlineHintKeyProcessorEventSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Microsoft.CodeAnalysis.Editor.InlineHints;
88

9-
internal partial class InlineHintsDataTaggerProvider
9+
internal partial class InlineHintsDataTaggerProvider<TAdditionalInformation>
1010
{
1111
private sealed class InlineHintKeyProcessorEventSource(IInlineHintKeyProcessor? inlineHintKeyProcessor) : AbstractTaggerEventSource
1212
{

src/EditorFeatures/Core/InlineHints/InlineHintsDataTaggerProvider.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ namespace Microsoft.CodeAnalysis.Editor.InlineHints;
2121
/// <summary>
2222
/// The TaggerProvider that calls upon the service in order to locate the spans and names
2323
/// </summary>
24-
internal sealed partial class InlineHintsDataTaggerProvider(
24+
internal sealed partial class InlineHintsDataTaggerProvider<TAdditionalInformation>(
2525
TaggerHost taggerHost,
2626
IInlineHintKeyProcessor inlineHintKeyProcessor)
27-
: AsynchronousViewportTaggerProvider<InlineHintDataTag>(taggerHost, FeatureAttribute.InlineHints)
27+
: AsynchronousViewportTaggerProvider<InlineHintDataTag<TAdditionalInformation>>(taggerHost, FeatureAttribute.InlineHints)
28+
where TAdditionalInformation : class
2829
{
2930
private readonly IInlineHintKeyProcessor _inlineHintKeyProcessor = inlineHintKeyProcessor;
3031

@@ -63,7 +64,7 @@ protected override ITaggerEventSource CreateEventSource(ITextView textView, ITex
6364
}
6465

6566
protected override async Task ProduceTagsAsync(
66-
TaggerContext<InlineHintDataTag> context,
67+
TaggerContext<InlineHintDataTag<TAdditionalInformation>> context,
6768
DocumentSnapshotSpan spanToTag,
6869
CancellationToken cancellationToken)
6970
{
@@ -95,12 +96,12 @@ protected override async Task ProduceTagsAsync(
9596
if (hint.DisplayParts.Sum(p => p.ToString().Length) == 0)
9697
continue;
9798

98-
context.AddTag(new TagSpan<InlineHintDataTag>(
99+
context.AddTag(new TagSpan<InlineHintDataTag<TAdditionalInformation>>(
99100
hint.Span.ToSnapshotSpan(snapshotSpan.Snapshot),
100-
new InlineHintDataTag(this, snapshotSpan.Snapshot, hint)));
101+
new(this, snapshotSpan.Snapshot, hint)));
101102
}
102103
}
103104

104-
protected override bool TagEquals(InlineHintDataTag tag1, InlineHintDataTag tag2)
105+
protected override bool TagEquals(InlineHintDataTag<TAdditionalInformation> tag1, InlineHintDataTag<TAdditionalInformation> tag2)
105106
=> tag1.Equals(tag2);
106107
}

0 commit comments

Comments
 (0)