Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Jan 30, 2022
1 parent 6a6ced9 commit c58fa1e
Show file tree
Hide file tree
Showing 17 changed files with 275 additions and 285 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.Options;

namespace Microsoft.CodeAnalysis.Classification
{
internal static class ClassificationOptionsMetadata
{
public static ClassificationOptions GetClassificationOptions(this IGlobalOptionService globalOptions, string language)
=> new(
ClassifyReassignedVariables: globalOptions.GetOption(ClassifyReassignedVariables, language),
ColorizeRegexPatterns: globalOptions.GetOption(ColorizeRegexPatterns, language));

public static PerLanguageOption2<bool> ClassifyReassignedVariables => ClassificationOptions.Metadata.ClassifyReassignedVariables;
public static PerLanguageOption2<bool> ColorizeRegexPatterns => ClassificationOptions.Metadata.ColorizeRegexPatterns;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ protected override ITaggerEventSource CreateEventSource(ITextView textViewOpt, I
TaggerEventSources.OnViewSpanChanged(ThreadingContext, textViewOpt),
TaggerEventSources.OnWorkspaceChanged(subjectBuffer, _listener),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsGlobalStateOption.DisplayAllOverride),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.EnabledForParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.ForLiteralParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.ForIndexerParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.ForObjectCreationParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.ForOtherParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.SuppressForParametersThatMatchMethodIntent),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.SuppressForParametersThatDifferOnlyBySuffix),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineParameterHintsOptions.Metadata.SuppressForParametersThatMatchArgumentName),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineTypeHintsOptions.Metadata.EnabledForTypes),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineTypeHintsOptions.Metadata.ForImplicitVariableTypes),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineTypeHintsOptions.Metadata.ForLambdaParameterTypes),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineTypeHintsOptions.Metadata.ForImplicitObjectCreation));
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.EnabledForParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.ForLiteralParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.ForIndexerParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.ForObjectCreationParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.ForOtherParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.SuppressForParametersThatMatchMethodIntent),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.SuppressForParametersThatDifferOnlyBySuffix),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.SuppressForParametersThatMatchArgumentName),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.EnabledForTypes),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.ForImplicitVariableTypes),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.ForLambdaParameterTypes),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.ForImplicitObjectCreation));
}

protected override IEnumerable<SnapshotSpan> GetSpansToTag(ITextView textView, ITextBuffer subjectBuffer)
Expand Down Expand Up @@ -107,7 +107,7 @@ protected override async Task ProduceTagsAsync(
if (service == null)
return;

var options = InlineHintsOptions.From(document.Project);
var options = GlobalOptions.GetInlineHintsOptions(document.Project.Language);

var snapshotSpan = documentSnapshotSpan.SnapshotSpan;
var hints = await service.GetInlineHintsAsync(document, snapshotSpan.Span.ToTextSpan(), options, cancellationToken).ConfigureAwait(false);
Expand Down
114 changes: 114 additions & 0 deletions src/EditorFeatures/Core/InlineHints/InlineHintsOptionsMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// 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.LanguageServices;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.InlineHints
{
internal static class InlineHintsOptionsMetadata
{
public static InlineHintsOptions GetInlineHintsOptions(this IGlobalOptionService globalOptions, string language)
=> new(
ParameterOptions: globalOptions.GetInlineParameterHintsOptions(language),
TypeOptions: globalOptions.GetInlineTypeHintsOptions(language),
DisplayOptions: globalOptions.GetSymbolDescriptionOptions(language));

public static InlineParameterHintsOptions GetInlineParameterHintsOptions(this IGlobalOptionService globalOptions, string language)
=> new(
EnabledForParameters: globalOptions.GetOption(EnabledForParameters, language),
ForLiteralParameters: globalOptions.GetOption(ForLiteralParameters, language),
ForIndexerParameters: globalOptions.GetOption(ForIndexerParameters, language),
ForObjectCreationParameters: globalOptions.GetOption(ForObjectCreationParameters, language),
ForOtherParameters: globalOptions.GetOption(ForOtherParameters, language),
SuppressForParametersThatDifferOnlyBySuffix: globalOptions.GetOption(SuppressForParametersThatDifferOnlyBySuffix, language),
SuppressForParametersThatMatchMethodIntent: globalOptions.GetOption(SuppressForParametersThatMatchMethodIntent, language),
SuppressForParametersThatMatchArgumentName: globalOptions.GetOption(SuppressForParametersThatMatchArgumentName, language));

public static InlineTypeHintsOptions GetInlineTypeHintsOptions(this IGlobalOptionService globalOptions, string language)
=> new(
EnabledForTypes: globalOptions.GetOption(EnabledForTypes, language),
ForImplicitVariableTypes: globalOptions.GetOption(ForImplicitVariableTypes, language),
ForLambdaParameterTypes: globalOptions.GetOption(ForLambdaParameterTypes, language),
ForImplicitObjectCreation: globalOptions.GetOption(ForImplicitObjectCreation, language));

private const string FeatureName = "InlineHintsOptions";

// Parameter hinds

public static readonly PerLanguageOption2<bool> EnabledForParameters =
new(FeatureName,
nameof(EnabledForParameters),
InlineParameterHintsOptions.Default.EnabledForParameters,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints"));

public static readonly PerLanguageOption2<bool> ForLiteralParameters =
new(FeatureName,
nameof(ForLiteralParameters),
InlineParameterHintsOptions.Default.ForLiteralParameters,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForLiteralParameters"));

public static readonly PerLanguageOption2<bool> ForIndexerParameters =
new(FeatureName,
nameof(ForIndexerParameters),
InlineParameterHintsOptions.Default.ForIndexerParameters,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForArrayIndexers"));

public static readonly PerLanguageOption2<bool> ForObjectCreationParameters =
new(FeatureName,
nameof(ForObjectCreationParameters),
InlineParameterHintsOptions.Default.ForObjectCreationParameters,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForObjectCreationParameters"));

public static readonly PerLanguageOption2<bool> ForOtherParameters =
new(FeatureName,
nameof(ForOtherParameters),
InlineParameterHintsOptions.Default.ForOtherParameters,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.ForOtherParameters"));

public static readonly PerLanguageOption2<bool> SuppressForParametersThatDifferOnlyBySuffix =
new(FeatureName,
nameof(SuppressForParametersThatDifferOnlyBySuffix),
InlineParameterHintsOptions.Default.SuppressForParametersThatDifferOnlyBySuffix,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.SuppressForParametersThatDifferOnlyBySuffix"));

public static readonly PerLanguageOption2<bool> SuppressForParametersThatMatchMethodIntent =
new(FeatureName,
nameof(SuppressForParametersThatMatchMethodIntent),
InlineParameterHintsOptions.Default.SuppressForParametersThatMatchMethodIntent,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.SuppressForParametersThatMatchMethodIntent"));

public static readonly PerLanguageOption2<bool> SuppressForParametersThatMatchArgumentName =
new(FeatureName,
nameof(SuppressForParametersThatMatchArgumentName),
InlineParameterHintsOptions.Default.SuppressForParametersThatMatchArgumentName,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineParameterNameHints.SuppressForParametersThatMatchArgumentName"));

// Type Hints

public static readonly PerLanguageOption2<bool> EnabledForTypes =
new(FeatureName,
nameof(EnabledForTypes),
defaultValue: InlineTypeHintsOptions.Default.EnabledForTypes,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints"));

public static readonly PerLanguageOption2<bool> ForImplicitVariableTypes =
new(FeatureName,
nameof(ForImplicitVariableTypes),
defaultValue: InlineTypeHintsOptions.Default.ForImplicitVariableTypes,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints.ForImplicitVariableTypes"));

public static readonly PerLanguageOption2<bool> ForLambdaParameterTypes =
new(FeatureName,
nameof(ForLambdaParameterTypes),
defaultValue: InlineTypeHintsOptions.Default.ForLambdaParameterTypes,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints.ForLambdaParameterTypes"));

public static readonly PerLanguageOption2<bool> ForImplicitObjectCreation =
new(FeatureName,
nameof(ForImplicitObjectCreation),
defaultValue: InlineTypeHintsOptions.Default.ForImplicitObjectCreation,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.InlineTypeHints.ForImplicitObjectCreation"));
}
}
26 changes: 26 additions & 0 deletions src/EditorFeatures/Core/QuickInfo/QuickInfoOptionsMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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.Options;

namespace Microsoft.CodeAnalysis.QuickInfo
{
internal static class QuickInfoOptionsMetadata
{
public static QuickInfoOptions GetQuickInfoOptions(this IGlobalOptionService globalOptions, string? language)
=> new(
ShowRemarksInQuickInfo: globalOptions.GetOption(ShowRemarksInQuickInfo, language),
IncludeNavigationHintsInQuickInfo: globalOptions.GetOption(IncludeNavigationHintsInQuickInfo));

private const string FeatureName = "QuickInfoOptions";

public static readonly PerLanguageOption2<bool> ShowRemarksInQuickInfo = new(
FeatureName, "ShowRemarksInQuickInfo", QuickInfoOptions.Default.ShowRemarksInQuickInfo,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowRemarks"));

public static readonly Option2<bool> IncludeNavigationHintsInQuickInfo = new(
FeatureName, "IncludeNavigationHintsInQuickInfo", QuickInfoOptions.Default.IncludeNavigationHintsInQuickInfo,
storageLocation: new RoamingProfileStorageLocation("TextEditor.Specific.IncludeNavigationHintsInQuickInfo"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.Classification;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.QuickInfo;

namespace Microsoft.CodeAnalysis.LanguageServices
{
internal static class SymbolDescriptionOptionsMetadata
{
public static SymbolDescriptionOptions GetSymbolDescriptionOptions(this IGlobalOptionService globalOptions, string language)
=> new(
QuickInfoOptions: globalOptions.GetQuickInfoOptions(language),
ClassificationOptions: globalOptions.GetClassificationOptions(language));
}
}
12 changes: 1 addition & 11 deletions src/Features/Core/Portable/InlineHints/InlineHintsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,5 @@ namespace Microsoft.CodeAnalysis.InlineHints
internal readonly record struct InlineHintsOptions(
InlineParameterHintsOptions ParameterOptions,
InlineTypeHintsOptions TypeOptions,
SymbolDescriptionOptions DisplayOptions)
{
public static InlineHintsOptions From(Project project)
=> From(project.Solution.Options, project.Language);

public static InlineHintsOptions From(OptionSet options, string language)
=> new(
ParameterOptions: InlineParameterHintsOptions.From(options, language),
TypeOptions: InlineTypeHintsOptions.From(options, language),
DisplayOptions: SymbolDescriptionOptions.From(options, language));
}
SymbolDescriptionOptions DisplayOptions);
}
Loading

0 comments on commit c58fa1e

Please sign in to comment.