Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Imports System.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.InlineHints
Imports Microsoft.CodeAnalysis.LanguageService
Imports Microsoft.CodeAnalysis.PooledObjects
Imports Microsoft.CodeAnalysis.Text

Namespace Microsoft.CodeAnalysis.Editor.UnitTests.InlineHints
Expand All @@ -28,8 +29,10 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.InlineHints
Dim tagService = document.GetRequiredLanguageService(Of IInlineParameterNameHintsService)

Dim span = If(hostDocument.SelectedSpans.Any(), hostDocument.SelectedSpans.Single(), New TextSpan(0, snapshot.Length))
Dim inlineHints = Await tagService.GetInlineHintsAsync(
document, span, options, displayOptions, displayAllOverride:=False, CancellationToken.None)
Dim inlineHints = ArrayBuilder(Of InlineHint).GetInstance()

Await tagService.AddInlineHintsAsync(
document, span, options, displayOptions, displayAllOverride:=False, inlineHints, CancellationToken.None)

Dim producedTags = From hint In inlineHints
Select hint.DisplayParts.GetFullText().TrimEnd() + hint.Span.ToString
Expand All @@ -56,7 +59,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.InlineHints
AssertEx.Equal(expectedTags, producedTags)
End Sub

Private Shared Async Function ValidateDoubleClick(document As Document, expectedDocument As Document, inlineHints As ImmutableArray(Of InlineHint)) As Task
Private Shared Async Function ValidateDoubleClick(document As Document, expectedDocument As Document, inlineHints As ArrayBuilder(Of InlineHint)) As Task
Dim textChanges = New List(Of TextChange)
For Each inlineHint In inlineHints
If inlineHint.ReplacementTextChange IsNot Nothing Then
Expand Down Expand Up @@ -88,8 +91,10 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.InlineHints
Dim tagService = document.GetRequiredLanguageService(Of IInlineTypeHintsService)

Dim span = If(hostDocument.SelectedSpans.Any(), hostDocument.SelectedSpans.Single(), New TextSpan(0, snapshot.Length))
Dim typeHints = Await tagService.GetInlineHintsAsync(
document, span, options, displayOptions, displayAllOverride:=ephemeral, CancellationToken.None)
Dim typeHints = ArrayBuilder(Of InlineHint).GetInstance()

Await tagService.AddInlineHintsAsync(
document, span, options, displayOptions, displayAllOverride:=ephemeral, typeHints, CancellationToken.None)

Dim producedTags = From hint In typeHints
Select hint.DisplayParts.GetFullText() + ":" + hint.Span.ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;

Expand All @@ -20,14 +20,19 @@ public async Task<ImmutableArray<InlineHint>> GetInlineHintsAsync(
var inlineParameterService = document.GetLanguageService<IInlineParameterNameHintsService>();
var inlineTypeService = document.GetLanguageService<IInlineTypeHintsService>();

var parameters = inlineParameterService == null
? []
: await inlineParameterService.GetInlineHintsAsync(document, textSpan, options.ParameterOptions, options.DisplayOptions, displayAllOverride, cancellationToken).ConfigureAwait(false);
// Allow large array instances in the pool, as these arrays often exceed the ArrayBuilder reuse size threshold
using var _ = ArrayBuilder<InlineHint>.GetInstance(discardLargeInstances: false, out var result);

var types = inlineTypeService == null
? []
: await inlineTypeService.GetInlineHintsAsync(document, textSpan, options.TypeOptions, options.DisplayOptions, displayAllOverride, cancellationToken).ConfigureAwait(false);
if (inlineParameterService is not null)
{
await inlineParameterService.AddInlineHintsAsync(document, textSpan, options.ParameterOptions, options.DisplayOptions, displayAllOverride, result, cancellationToken).ConfigureAwait(false);
}

return [.. parameters, .. types];
if (inlineTypeService is not null)
{
await inlineTypeService.AddInlineHintsAsync(document, textSpan, options.TypeOptions, options.DisplayOptions, displayAllOverride, result, cancellationToken).ConfigureAwait(false);
}

return result.ToImmutableAndClear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,24 @@ protected abstract void AddAllParameterNameHintLocations(
protected abstract bool IsIndexer(SyntaxNode node, IParameterSymbol parameter);
protected abstract string GetReplacementText(string parameterName);

public async Task<ImmutableArray<InlineHint>> GetInlineHintsAsync(
public async Task AddInlineHintsAsync(
Document document,
TextSpan textSpan,
InlineParameterHintsOptions options,
SymbolDescriptionOptions displayOptions,
bool displayAllOverride,
ArrayBuilder<InlineHint> result,
CancellationToken cancellationToken)
{
var enabledForParameters = displayAllOverride || options.EnabledForParameters;
if (!enabledForParameters)
return [];
return;

var literalParameters = displayAllOverride || options.ForLiteralParameters;
var objectCreationParameters = displayAllOverride || options.ForObjectCreationParameters;
var otherParameters = displayAllOverride || options.ForOtherParameters;
if (!literalParameters && !objectCreationParameters && !otherParameters)
return [];
return;

var indexerParameters = displayAllOverride || options.ForIndexerParameters;
var suppressForParametersThatDifferOnlyBySuffix = !displayAllOverride && options.SuppressForParametersThatDifferOnlyBySuffix;
Expand All @@ -59,8 +60,6 @@ public async Task<ImmutableArray<InlineHint>> GetInlineHintsAsync(
var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var syntaxFacts = document.GetRequiredLanguageService<ISyntaxFactsService>();

// Allow large array instances in the pool, as these arrays often exceed the ArrayBuilder reuse size threshold
using var _1 = ArrayBuilder<InlineHint>.GetInstance(discardLargeInstances: false, out var result);
using var _2 = ArrayBuilder<(int position, SyntaxNode argument, IParameterSymbol? parameter, HintKind kind)>.GetInstance(out var buffer);

foreach (var node in root.DescendantNodes(textSpan, n => n.Span.IntersectsWith(textSpan)))
Expand All @@ -75,7 +74,7 @@ public async Task<ImmutableArray<InlineHint>> GetInlineHintsAsync(
}
}

return result.ToImmutableAndClear();
return;

void AddHintsIfAppropriate(SyntaxNode node)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,30 @@ internal abstract class AbstractInlineTypeHintsService : IInlineTypeHintsService
bool forCollectionExpressions,
CancellationToken cancellationToken);

public async Task<ImmutableArray<InlineHint>> GetInlineHintsAsync(
public async Task AddInlineHintsAsync(
Document document,
TextSpan textSpan,
InlineTypeHintsOptions options,
SymbolDescriptionOptions displayOptions,
bool displayAllOverride,
ArrayBuilder<InlineHint> result,
CancellationToken cancellationToken)
{
var enabledForTypes = options.EnabledForTypes;
if (!enabledForTypes && !displayAllOverride)
return [];
return;

var forImplicitVariableTypes = enabledForTypes && options.ForImplicitVariableTypes;
var forLambdaParameterTypes = enabledForTypes && options.ForLambdaParameterTypes;
var forImplicitObjectCreation = enabledForTypes && options.ForImplicitObjectCreation;
var forCollectionExpressions = enabledForTypes && options.ForCollectionExpressions;
if (!forImplicitVariableTypes && !forLambdaParameterTypes && !forImplicitObjectCreation && !forCollectionExpressions && !displayAllOverride)
return [];
return;

var anonymousTypeService = document.GetRequiredLanguageService<IStructuralTypeDisplayService>();
var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);

using var _1 = ArrayBuilder<InlineHint>.GetInstance(out var result);

foreach (var node in root.DescendantNodes(n => n.Span.IntersectsWith(textSpan)))
{
var hint = TryGetTypeHint(
Expand Down Expand Up @@ -97,8 +96,6 @@ public async Task<ImmutableArray<InlineHint>> GetInlineHintsAsync(
span, taggedText, textChange, ranking: InlineHintsConstants.TypeRanking,
InlineHintHelpers.GetDescriptionFunction(spanStart, type, displayOptions)));
}

return result.ToImmutableAndClear();
}

private static void AddParts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.LanguageService;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.InlineHints;
Expand All @@ -17,11 +17,12 @@ namespace Microsoft.CodeAnalysis.InlineHints;
/// </summary>
internal interface IInlineParameterNameHintsService : ILanguageService
{
Task<ImmutableArray<InlineHint>> GetInlineHintsAsync(
Task AddInlineHintsAsync(
Document document,
TextSpan textSpan,
InlineParameterHintsOptions options,
SymbolDescriptionOptions displayOptions,
bool displayAllOverride,
ArrayBuilder<InlineHint> result,
CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.LanguageService;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.InlineHints;
Expand All @@ -17,11 +17,12 @@ namespace Microsoft.CodeAnalysis.InlineHints;
/// </summary>
internal interface IInlineTypeHintsService : ILanguageService
{
Task<ImmutableArray<InlineHint>> GetInlineHintsAsync(
Task AddInlineHintsAsync(
Document document,
TextSpan textSpan,
InlineTypeHintsOptions options,
SymbolDescriptionOptions displayOptions,
bool displayAllOverride,
ArrayBuilder<InlineHint> result,
CancellationToken cancellationToken);
}
Loading