Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back OmniSharpInlineHints #59941

Merged
merged 3 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ src/Compilers/**/PublicAPI.Unshipped.txt @dotnet/roslyn-api-owners
src/Workspaces/**/PublicAPI.Unshipped.txt @dotnet/roslyn-api-owners
src/Features/**/PublicAPI.Unshipped.txt @dotnet/roslyn-api-owners
src/EditorFeatures/**/PublicAPI.Unshipped.txt @dotnet/roslyn-api-owners

src/Tools/ExternalAccess/OmniSharp*/ @333fred @joerobich
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.CodeAnalysis.InlineHints;
using Microsoft.CodeAnalysis.LanguageServices;

namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.InlineHints;

internal readonly record struct OmniSharpInlineHintsOptions(
OmniSharpInlineParameterHintsOptions ParameterOptions,
OmniSharpInlineTypeHintsOptions TypeOptions)
{
internal InlineHintsOptions ToInlineHintsOptions()
=> new(ParameterOptions.ToInlineParameterHintsOptions(),
TypeOptions.ToInlineTypeHintsOptions(),
SymbolDescriptionOptions.Default);
}
internal readonly record struct OmniSharpInlineParameterHintsOptions(
bool EnabledForParameters,
bool ForLiteralParameters,
bool ForIndexerParameters,
bool ForObjectCreationParameters,
bool ForOtherParameters,
bool SuppressForParametersThatDifferOnlyBySuffix,
bool SuppressForParametersThatMatchMethodIntent,
bool SuppressForParametersThatMatchArgumentName)
{
internal InlineParameterHintsOptions ToInlineParameterHintsOptions()
=> new(EnabledForParameters, ForLiteralParameters, ForIndexerParameters, ForObjectCreationParameters, ForOtherParameters, SuppressForParametersThatDifferOnlyBySuffix, SuppressForParametersThatMatchMethodIntent, SuppressForParametersThatMatchArgumentName);
}

internal readonly record struct OmniSharpInlineTypeHintsOptions(
bool EnabledForTypes,
bool ForImplicitVariableTypes,
bool ForLambdaParameterTypes,
bool ForImplicitObjectCreation)
{
internal InlineTypeHintsOptions ToInlineTypeHintsOptions()
=> new(EnabledForTypes, ForImplicitVariableTypes, ForLambdaParameterTypes, ForImplicitObjectCreation);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Licensed to the .NET Foundation under one or more agreements.
// 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;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.InlineHints;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.InlineHints;

internal static class OmniSharpInlineHintsService
{
public static async Task<ImmutableArray<OmniSharpInlineHint>> GetInlineHintsAsync(Document document, TextSpan textSpan, OmniSharpInlineHintsOptions options, CancellationToken cancellationToken)
{
var service = document.GetRequiredLanguageService<IInlineHintsService>();
var roslynOptions = options.ToInlineHintsOptions();

var hints = await service.GetInlineHintsAsync(document, textSpan, roslynOptions, cancellationToken).ConfigureAwait(false);
return hints.SelectAsArray(static h => new OmniSharpInlineHint(
h.Span,
h.DisplayParts,
(document, cancellationToken) => h.GetDescriptionAsync(document, cancellationToken)));
}
}

internal readonly struct OmniSharpInlineHint
{
private readonly Func<Document, CancellationToken, Task<ImmutableArray<TaggedText>>> _getDescriptionAsync;

public OmniSharpInlineHint(
TextSpan span,
ImmutableArray<TaggedText> displayParts,
Func<Document, CancellationToken, Task<ImmutableArray<TaggedText>>> getDescriptionAsync)
{
Span = span;
DisplayParts = displayParts;
_getDescriptionAsync = getDescriptionAsync;
}

public readonly TextSpan Span { get; }
public readonly ImmutableArray<TaggedText> DisplayParts { get; }

public Task<ImmutableArray<TaggedText>> GetDescrptionAsync(Document document, CancellationToken cancellationToken)
=> _getDescriptionAsync.Invoke(document, cancellationToken);
}