提交 a615d5b0 编写于 作者: C CyrusNajmabadi

Add support for AB testing in Roslyn.

上级 891b7499
......@@ -30,6 +30,7 @@
namespace Microsoft.CodeAnalysis.Editor.Implementation.Suggestions
{
using Microsoft.CodeAnalysis.Experiments;
using CodeFixGroupKey = Tuple<DiagnosticData, CodeActionPriority>;
[Export(typeof(ISuggestedActionsSourceProvider))]
......@@ -626,10 +627,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;
using Microsoft.VisualStudio.Shell.Interop;
namespace Microsoft.Internal.VisualStudio.Shell.Interop
{
[Guid("6F05B225-83BF-40A3-A32A-47FA8443E868")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IVsFlightEvents
{
void OnFlightsChanged();
}
[Guid("61A8FB20-45DF-11E5-A151-FEFF819CDC9F")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IVsExperimentationService
{
[DispId(1610678272)]
Array AllEnabledCachedFlights { get; }
[return: ComAliasName("EnvDTE.ULONG_PTR")]
uint AdviseFlightEvents(IVsFlightEvents flightSink);
bool IsCachedFlightEnabled([ComAliasName("OLE.LPCOLESTR")] string flightName);
IVsTask IsFlightEnabledAsync([ComAliasName("OLE.LPCOLESTR")] string flightName);
void Start();
void UnadviseFlightEvents([ComAliasName("EnvDTE.ULONG_PTR")] uint cookie);
}
[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 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 IVsExperimentationService _experimentationServiceOpt;
[ImportingConstructor]
public VisualStudioExperimentationService(
SVsServiceProvider serviceProvider)
{
try
{
_experimentationServiceOpt = (IVsExperimentationService)serviceProvider.GetService(typeof(SVsServiceProvider));
}
catch
{
}
}
public bool IsExperimentEnabled(string experimentName)
=> _experimentationServiceOpt?.IsCachedFlightEnabled(experimentName) ?? 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.
先完成此消息的编辑!
想要评论请 注册