From bc9c7a65b4f14b402bb53d10728974dac5e05616 Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Thu, 3 Mar 2022 16:48:04 -0800 Subject: [PATCH 1/3] Add back OmniSharpInlineHints This was removed in https://github.com/dotnet/roslyn/pull/59567, just before the vscode API went stable and O# could finally take advantage of it. This adds the EA back. I also added Joey and I to the codeowners file so we can be aware of any future changes. --- .github/CODEOWNERS | 2 + .../OmniSharpInlineHintsOptions.cs | 43 ++++++++++++++++ .../OmniSharpInlineHintsService.cs | 49 +++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsOptions.cs create mode 100644 src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsService.cs diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 8be9f768ee90d..942a2b624491e 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -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 diff --git a/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsOptions.cs b/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsOptions.cs new file mode 100644 index 0000000000000..19d4999ca51be --- /dev/null +++ b/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsOptions.cs @@ -0,0 +1,43 @@ +// 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 = false, + bool ForLiteralParameters = true, + bool ForIndexerParameters = true, + bool ForObjectCreationParameters = true, + bool ForOtherParameters = false, + bool SuppressForParametersThatDifferOnlyBySuffix = true, + bool SuppressForParametersThatMatchMethodIntent = true, + bool SuppressForParametersThatMatchArgumentName = true) +{ + internal InlineParameterHintsOptions ToInlineParameterHintsOptions() + => new(EnabledForParameters, ForLiteralParameters, ForIndexerParameters, ForObjectCreationParameters, ForOtherParameters, SuppressForParametersThatDifferOnlyBySuffix, SuppressForParametersThatMatchMethodIntent, SuppressForParametersThatMatchArgumentName); +} + +internal readonly record struct OmniSharpInlineTypeHintsOptions( + bool EnabledForTypes = false, + bool ForImplicitVariableTypes = true, + bool ForLambdaParameterTypes = true, + bool ForImplicitObjectCreation = true) +{ + internal InlineTypeHintsOptions ToInlineTypeHintsOptions() + => new(EnabledForTypes, ForImplicitVariableTypes, ForLambdaParameterTypes, ForImplicitObjectCreation); +} diff --git a/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsService.cs b/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsService.cs new file mode 100644 index 0000000000000..2c8a978788abc --- /dev/null +++ b/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsService.cs @@ -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> GetInlineHintsAsync(Document document, TextSpan textSpan, OmniSharpInlineHintsOptions options, CancellationToken cancellationToken) + { + var service = document.GetRequiredLanguageService(); + 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>> _getDescriptionAsync; + + public OmniSharpInlineHint( + TextSpan span, + ImmutableArray displayParts, + Func>> getDescriptionAsync) + { + Span = span; + DisplayParts = displayParts; + _getDescriptionAsync = getDescriptionAsync; + } + + public readonly TextSpan Span { get; } + public readonly ImmutableArray DisplayParts { get; } + + public Task> GetDescrptionAsync(Document document, CancellationToken cancellationToken) + => _getDescriptionAsync.Invoke(document, cancellationToken); +} From 64236b05c78bed5747af65edaea7df3aeddd0bed Mon Sep 17 00:00:00 2001 From: Fred Silberberg Date: Thu, 3 Mar 2022 18:45:51 -0800 Subject: [PATCH 2/3] Remove extra blank line. Co-authored-by: Joey Robichaud --- .../OmniSharp/InlineHints/OmniSharpInlineHintsOptions.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsOptions.cs b/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsOptions.cs index 19d4999ca51be..715b7ba262f50 100644 --- a/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsOptions.cs +++ b/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsOptions.cs @@ -16,8 +16,6 @@ internal InlineHintsOptions ToInlineHintsOptions() TypeOptions.ToInlineTypeHintsOptions(), SymbolDescriptionOptions.Default); } - - internal readonly record struct OmniSharpInlineParameterHintsOptions( bool EnabledForParameters = false, bool ForLiteralParameters = true, From 27b27f923d3a6acfd8c4d0ebb5cfb963ceaab4fe Mon Sep 17 00:00:00 2001 From: Fred Silberberg Date: Thu, 3 Mar 2022 18:47:09 -0800 Subject: [PATCH 3/3] No defaults --- .../OmniSharpInlineHintsOptions.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsOptions.cs b/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsOptions.cs index 715b7ba262f50..805b1ea94baca 100644 --- a/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsOptions.cs +++ b/src/Tools/ExternalAccess/OmniSharp/InlineHints/OmniSharpInlineHintsOptions.cs @@ -17,24 +17,24 @@ internal InlineHintsOptions ToInlineHintsOptions() SymbolDescriptionOptions.Default); } internal readonly record struct OmniSharpInlineParameterHintsOptions( - bool EnabledForParameters = false, - bool ForLiteralParameters = true, - bool ForIndexerParameters = true, - bool ForObjectCreationParameters = true, - bool ForOtherParameters = false, - bool SuppressForParametersThatDifferOnlyBySuffix = true, - bool SuppressForParametersThatMatchMethodIntent = true, - bool SuppressForParametersThatMatchArgumentName = true) + 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 = false, - bool ForImplicitVariableTypes = true, - bool ForLambdaParameterTypes = true, - bool ForImplicitObjectCreation = true) + bool EnabledForTypes, + bool ForImplicitVariableTypes, + bool ForLambdaParameterTypes, + bool ForImplicitObjectCreation) { internal InlineTypeHintsOptions ToInlineTypeHintsOptions() => new(EnabledForTypes, ForImplicitVariableTypes, ForLambdaParameterTypes, ForImplicitObjectCreation);