提交 0555e55f 编写于 作者: C CyrusNajmabadi

Pass data along in cosntructor.

上级 c12b73d9
......@@ -18,7 +18,6 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.Suggestions
internal sealed class CodeFixSuggestedAction : SuggestedActionWithFlavors, ITelemetryDiagnosticID<string>
{
private readonly CodeFix _fix;
private readonly SuggestedActionSet _fixAllSuggestedActionSet;
public CodeFixSuggestedAction(
Workspace workspace,
......@@ -28,16 +27,14 @@ internal sealed class CodeFixSuggestedAction : SuggestedActionWithFlavors, ITele
CodeFix fix,
CodeAction action,
object provider,
SuggestedActionSet fixAllSuggestedActionSet,
SuggestedActionSet fixAllFlavors,
IAsynchronousOperationListener operationListener)
: base(workspace, subjectBuffer, editHandler, waitIndicator, action, provider, operationListener)
: base(workspace, subjectBuffer, editHandler, waitIndicator,
action, provider, operationListener, fixAllFlavors)
{
_fix = fix;
_fixAllSuggestedActionSet = fixAllSuggestedActionSet;
}
protected override SuggestedActionSet GetAdditionalFlavors() => _fixAllSuggestedActionSet;
public string GetDiagnosticID()
{
var diagnostic = _fix.PrimaryDiagnostic;
......
......@@ -25,15 +25,18 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.Suggestions
/// </summary>
internal abstract partial class SuggestedActionWithFlavors : SuggestedAction, ISuggestedActionWithFlavors
{
private ImmutableArray<SuggestedActionSet> _actionSets;
private readonly SuggestedActionSet _additionalFlavors;
private ImmutableArray<SuggestedActionSet> _allFlavors;
public SuggestedActionWithFlavors(
Workspace workspace, ITextBuffer subjectBuffer, ICodeActionEditHandlerService editHandler,
IWaitIndicator waitIndicator, CodeAction codeAction, object provider,
IAsynchronousOperationListener operationListener)
IAsynchronousOperationListener operationListener,
SuggestedActionSet additionalFlavors = null)
: base(workspace, subjectBuffer, editHandler, waitIndicator, codeAction,
provider, operationListener, actionSets: null)
{
_additionalFlavors = additionalFlavors;
}
/// <summary>
......@@ -41,8 +44,6 @@ internal abstract partial class SuggestedActionWithFlavors : SuggestedAction, IS
/// </summary>
public override bool HasActionSets => true;
protected virtual SuggestedActionSet GetAdditionalFlavors() => null;
public async sealed override Task<IEnumerable<SuggestedActionSet>> GetActionSetsAsync(CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
......@@ -50,21 +51,21 @@ public async sealed override Task<IEnumerable<SuggestedActionSet>> GetActionSets
// Light bulb will always invoke this property on the UI thread.
AssertIsForeground();
if (_actionSets.IsDefault)
if (_allFlavors.IsDefault)
{
var extensionManager = this.Workspace.Services.GetService<IExtensionManager>();
// We use ConfigureAwait(true) to stay on the UI thread.
_actionSets = await extensionManager.PerformFunctionAsync(
Provider, () => CreateFlavors(cancellationToken),
_allFlavors = await extensionManager.PerformFunctionAsync(
Provider, () => CreateAllFlavors(cancellationToken),
defaultValue: ImmutableArray<SuggestedActionSet>.Empty).ConfigureAwait(true);
}
Contract.ThrowIfTrue(_actionSets.IsDefault);
return _actionSets;
Contract.ThrowIfTrue(_allFlavors.IsDefault);
return _allFlavors;
}
private async Task<ImmutableArray<SuggestedActionSet>> CreateFlavors(CancellationToken cancellationToken)
private async Task<ImmutableArray<SuggestedActionSet>> CreateAllFlavors(CancellationToken cancellationToken)
{
var builder = ArrayBuilder<SuggestedActionSet>.GetInstance();
......@@ -75,10 +76,9 @@ private async Task<ImmutableArray<SuggestedActionSet>> CreateFlavors(Cancellatio
builder.Add(previewChangesSuggestedActionSet);
}
var additionalSet = this.GetAdditionalFlavors();
if (additionalSet != null)
if (_additionalFlavors != null)
{
builder.Add(additionalSet);
builder.Add(_additionalFlavors);
}
return builder.ToImmutableAndFree();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册