提交 c598c89b 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #14460 from CyrusNajmabadi/abTestingRC

Add support for AB testing in Roslyn.
......@@ -18,8 +18,8 @@
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Experiments;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
......@@ -626,10 +626,25 @@ public async Task<bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet req
SnapshotSpan range,
CancellationToken cancellationToken)
{
if (!requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring))
{
// See if we should still show the light bulb, even if we weren't explicitly
// asked for refactorings. We'll show the lightbulb if we're currently
// flighting the "Refactoring" A/B test, or if a special option is set
// enabling this internally.
var workspace = document.Project.Solution.Workspace;
var experimentationService = workspace.Services.GetService<IExperimentationService>();
if (!experimentationService.IsExperimentEnabled("Refactoring") &&
!workspace.Options.GetOption(EditorComponentOnOffOptions.ShowCodeRefactoringsWhenQueriedForCodeFixes))
{
return false;
}
}
if (document.Project.Solution.Options.GetOption(EditorComponentOnOffOptions.CodeRefactorings) &&
provider._codeRefactoringService != null &&
supportsFeatureService.SupportsRefactorings(document) &&
requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring))
supportsFeatureService.SupportsRefactorings(document))
{
TextSpan? selection = null;
if (IsForeground())
......
......@@ -22,5 +22,10 @@ internal static class EditorComponentOnOffOptions
[ExportOption]
public static readonly Option<bool> CodeRefactorings = new Option<bool>(nameof(EditorComponentOnOffOptions), nameof(CodeRefactorings), defaultValue: true,
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + "Code Refactorings"));
[ExportOption]
public static readonly Option<bool> ShowCodeRefactoringsWhenQueriedForCodeFixes = new Option<bool>(
nameof(EditorComponentOnOffOptions), nameof(ShowCodeRefactoringsWhenQueriedForCodeFixes), defaultValue: false,
storageLocations: new LocalUserProfileStorageLocation(LocalRegistryPath + nameof(ShowCodeRefactoringsWhenQueriedForCodeFixes)));
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Runtime.InteropServices;
namespace Microsoft.Internal.VisualStudio.Shell.Interop
{
[Guid("DFF66CB5-603C-4716-89BD-24BD0E8C172C")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface SVsExperimentationService
{
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using System.Reflection;
using Microsoft.CodeAnalysis.Experiments;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.Internal.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Shell;
namespace Microsoft.VisualStudio.LanguageServices.Experimentation
{
[ExportWorkspaceService(typeof(IExperimentationService), ServiceLayer.Host), Shared]
internal class VisualStudioExperimentationService : IExperimentationService
{
private readonly object _experimentationServiceOpt;
private readonly MethodInfo _isCachedFlightEnabledInfo;
[ImportingConstructor]
public VisualStudioExperimentationService(
SVsServiceProvider serviceProvider)
{
try
{
_experimentationServiceOpt = serviceProvider.GetService(typeof(SVsExperimentationService));
if (_experimentationServiceOpt != null)
{
_isCachedFlightEnabledInfo = _experimentationServiceOpt.GetType().GetMethod(
"IsCachedFlightEnabled", BindingFlags.Public | BindingFlags.Instance);
}
}
catch
{
}
}
public bool IsExperimentEnabled(string experimentName)
{
if (_isCachedFlightEnabledInfo != null)
{
try
{
return (bool)_isCachedFlightEnabledInfo.Invoke(_experimentationServiceOpt, new object[] { experimentName });
}
catch
{
}
}
return false;
}
}
}
\ No newline at end of file
......@@ -46,6 +46,8 @@
<Compile Include="..\..\..\Compilers\Shared\ShadowCopyAnalyzerAssemblyLoader.cs">
<Link>InternalUtilities\ShadowCopyAnalyzerAssemblyLoader.cs</Link>
</Compile>
<Compile Include="Experimentation\IVsExperimentationService.cs" />
<Compile Include="Experimentation\VisualStudioExperimentationService.cs" />
<Compile Include="Implementation\AnalyzerDependency\AnalyzerDependencyResults.cs" />
<Compile Include="IAnalyzerNodeSetup.cs" />
<Compile Include="Implementation\AnalyzerDependency\AnalyzerDependencyChecker.cs" />
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
namespace Microsoft.CodeAnalysis.Experiments
{
internal interface IExperimentationService : IWorkspaceService
{
bool IsExperimentEnabled(string experimentName);
}
[ExportWorkspaceService(typeof(IExperimentationService)), Shared]
internal class DefaultExperimentationService : IExperimentationService
{
public bool IsExperimentEnabled(string experimentName) => false;
}
}
\ No newline at end of file
......@@ -382,6 +382,7 @@
<Compile Include="Execution\SolutionChecksumObjectInfo.cs" />
<Compile Include="Execution\ChecksumTreeCollection.cs" />
<Compile Include="Execution\SolutionChecksumService.cs" />
<Compile Include="Experiments\IExperimentationService.cs" />
<Compile Include="FindSymbols\IRemoteSymbolFinder.cs" />
<Compile Include="FindSymbols\FindReferences\StreamingFindReferencesProgress.cs" />
<Compile Include="FindSymbols\IStreamingFindReferencesProgress.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册