Skip to content

Commit

Permalink
Merge pull request #54371 from Cosifne/dev/shech/InheritanceMarginExp…
Browse files Browse the repository at this point in the history
…eriment

Enable experiment for Inheritance Margin
  • Loading branch information
Cosifne authored Jun 28, 2021
2 parents b24e9ad + 4dd5744 commit fdd54dd
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ internal static class FeatureOnOffOptions
nameof(FeatureOnOffOptions), nameof(OfferRemoveUnusedReferences), defaultValue: true,
storageLocations: new RoamingProfileStorageLocation($"TextEditor.{nameof(OfferRemoveUnusedReferences)}"));

public static readonly PerLanguageOption2<bool> ShowInheritanceMargin =
public static readonly PerLanguageOption2<bool?> ShowInheritanceMargin =
new(nameof(FeatureOnOffOptions),
nameof(ShowInheritanceMargin),
defaultValue: false,
defaultValue: null,
new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowInheritanceMargin"));

public static readonly Option2<bool> AutomaticallyCompleteStatementOnSemicolon = new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ public AdvancedOptionPageControl(OptionStore optionStore, IComponentModel compon
BindToOption(ShowHintsForLambdaParameterTypes, InlineHintsOptions.ForLambdaParameterTypes, LanguageNames.CSharp);
BindToOption(ShowHintsForImplicitObjectCreation, InlineHintsOptions.ForImplicitObjectCreation, LanguageNames.CSharp);

BindToOption(ShowInheritanceMargin, FeatureOnOffOptions.ShowInheritanceMargin, LanguageNames.CSharp);
// If the option has not been set by the user, check if the option is enabled from experimentation.
// If so, default to that. Otherwise default to disabled
BindToOption(ShowInheritanceMargin, FeatureOnOffOptions.ShowInheritanceMargin, LanguageNames.CSharp, () =>
experimentationService?.IsExperimentEnabled(WellKnownExperimentNames.InheritanceMargin) ?? false);
}

// Since this dialog is constructed once for the lifetime of the application and VS Theme can be changed after the application has started,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.Experiments;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.InheritanceMargin;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Text;
Expand Down Expand Up @@ -45,6 +47,8 @@ public InheritanceMarginTaggerProvider(

protected override TaggerDelay EventChangeDelay => TaggerDelay.OnIdle;

private bool? _experimentEnabled = null;

protected override ITaggerEventSource CreateEventSource(ITextView textViewOpt, ITextBuffer subjectBuffer)
// Because we use frozen-partial documents for semantic classification, we may end up with incomplete
// semantics (esp. during solution load). Because of this, we also register to hear when the full
Expand Down Expand Up @@ -84,8 +88,16 @@ protected override async Task ProduceTagsAsync(
var cancellationToken = context.CancellationToken;

var options = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);
var featureEnabled = options.GetOption(FeatureOnOffOptions.ShowInheritanceMargin);
if (!featureEnabled)

var optionIsChecked = options.GetOption(FeatureOnOffOptions.ShowInheritanceMargin);
if (_experimentEnabled is null)
{
var experimentationService = document.Project.Solution.Workspace.Services.GetRequiredService<IExperimentationService>();
_experimentEnabled = experimentationService.IsExperimentEnabled(WellKnownExperimentNames.InheritanceMargin);
}

var shouldEnableFeature = optionIsChecked == true || (_experimentEnabled == true && optionIsChecked == null);
if (!shouldEnableFeature)
{
return;
}
Expand All @@ -99,10 +111,14 @@ protected override async Task ProduceTagsAsync(
return;
}

var inheritanceMemberItems = await inheritanceMarginInfoService.GetInheritanceMemberItemsAsync(
var inheritanceMemberItems = ImmutableArray<InheritanceMarginItem>.Empty;
using (Logger.LogBlock(FunctionId.InheritanceMargin_GetInheritanceMemberItems, cancellationToken, LogLevel.Information))
{
inheritanceMemberItems = await inheritanceMarginInfoService.GetInheritanceMemberItemsAsync(
document,
spanToTag.SnapshotSpan.Span.ToTextSpan(),
cancellationToken).ConfigureAwait(false);
}

if (inheritanceMemberItems.IsEmpty)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options
BindToOption(SuppressHintsWhenParameterNameMatchesTheMethodsIntent, InlineHintsOptions.SuppressForParametersThatMatchMethodIntent, LanguageNames.VisualBasic)
BindToOption(SuppressHintsWhenParameterNamesDifferOnlyBySuffix, InlineHintsOptions.SuppressForParametersThatDifferOnlyBySuffix, LanguageNames.VisualBasic)

BindToOption(ShowInheritanceMargin, FeatureOnOffOptions.ShowInheritanceMargin, LanguageNames.VisualBasic)
BindToOption(ShowInheritanceMargin, FeatureOnOffOptions.ShowInheritanceMargin, LanguageNames.VisualBasic,
Function()
' If the option has not been set by the user, check if the option Is enabled from experimentation.
' If so, default to that. Otherwise default to disabled
Return If(experimentationService?.IsExperimentEnabled(WellKnownExperimentNames.InheritanceMargin), False)
End Function)
End Sub

' Since this dialog is constructed once for the lifetime of the application and VS Theme can be changed after the application has started,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ internal static class WellKnownExperimentNames
public const string CloudCache = "Roslyn.CloudCache";
public const string UnnamedSymbolCompletionDisabled = "Roslyn.UnnamedSymbolCompletionDisabled";
public const string RazorLspEditorFeatureFlag = "Razor.LSP.Editor";
public const string InheritanceMargin = "Roslyn.InheritanceMargin";
public const string LspPullDiagnosticsFeatureFlag = "Lsp.PullDiagnostics";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -522,5 +522,7 @@ internal enum FunctionId

ValueTracking_Command = 490,
ValueTracking_TrackValueSource = 491,

InheritanceMargin_GetInheritanceMemberItems = 492,
}
}

0 comments on commit fdd54dd

Please sign in to comment.