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

Merge pull request #14575 from CyrusNajmabadi/removeUnnecessarySuggestedAction

Remove unnecessary type FixMultipleSuggestedAction.
......@@ -279,7 +279,6 @@
<Compile Include="Implementation\Preview\DifferenceViewerPreview.cs" />
<Compile Include="Implementation\Preview\PreviewReferenceHighlightingTaggerProvider.cs" />
<Compile Include="Implementation\Suggestions\FixMultipleOccurrencesService.cs" />
<Compile Include="Implementation\Suggestions\FixMultipleSuggestedAction.cs" />
<Compile Include="Implementation\GoToImplementation\GoToImplementationCommandHandler.cs" />
<Compile Include="Implementation\TodoComment\ITodoListProvider.cs" />
<Compile Include="Implementation\TodoComment\TodoItem.cs" />
......
......@@ -8,9 +8,11 @@
using System.Threading;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Extensions;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.Suggestions
{
......@@ -53,8 +55,10 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
var fixMultipleState = FixAllState.Create(fixAllProvider, diagnosticsToFix, fixProvider, equivalenceKey);
var triggerDiagnostic = diagnosticsToFix.First().Value.First();
var suggestedAction = GetSuggestedAction(fixMultipleState, triggerDiagnostic, workspace, waitDialogTitle, waitDialogMessage, showPreviewChangesDialog: false, cancellationToken: cancellationToken);
return suggestedAction.GetChangedSolution(cancellationToken);
var result = GetFixedSolution(
fixMultipleState, triggerDiagnostic, workspace,
waitDialogTitle, waitDialogMessage, cancellationToken);
return result;
}
public Solution GetFix(
......@@ -70,23 +74,34 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
var fixMultipleState = FixAllState.Create(fixAllProvider, diagnosticsToFix, fixProvider, equivalenceKey);
var triggerDiagnostic = diagnosticsToFix.First().Value.First();
var suggestedAction = GetSuggestedAction(fixMultipleState, triggerDiagnostic, workspace, waitDialogTitle, waitDialogMessage, showPreviewChangesDialog: false, cancellationToken: cancellationToken);
return suggestedAction.GetChangedSolution(cancellationToken);
var result = GetFixedSolution(
fixMultipleState, triggerDiagnostic, workspace,
waitDialogTitle, waitDialogMessage, cancellationToken);
return result;
}
private FixMultipleSuggestedAction GetSuggestedAction(
private Solution GetFixedSolution(
FixAllState fixAllState,
Diagnostic triggerDiagnostic,
Workspace workspace,
string title,
string waitDialogMessage,
bool showPreviewChangesDialog,
CancellationToken cancellationToken)
{
var fixMultipleCodeAction = new FixMultipleCodeAction(fixAllState, triggerDiagnostic, title, waitDialogMessage, showPreviewChangesDialog);
return new FixMultipleSuggestedAction(
_listener, workspace, _editHandler, _waitIndicator,
fixMultipleCodeAction, fixAllState.FixAllProvider);
var fixMultipleCodeAction = new FixMultipleCodeAction(
fixAllState, triggerDiagnostic, title, waitDialogMessage);
Solution newSolution = null;
var extensionManager = workspace.Services.GetService<IExtensionManager>();
extensionManager.PerformAction(fixAllState.FixAllProvider, () =>
{
// We don't need to post process changes here as the inner code action created for Fix multiple code fix already executes.
newSolution = fixMultipleCodeAction.GetChangedSolutionInternalAsync(
postProcessChanges: false, cancellationToken: cancellationToken).WaitAndGetResult(cancellationToken);
});
return newSolution;
}
}
}
// 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.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.VisualStudio.Text;
using Roslyn.Utilities;
using Microsoft.CodeAnalysis.Extensions;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Shared.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.Suggestions
{
/// <summary>
/// Suggested action for fix multiple occurrences code fix.
/// </summary>
internal class FixMultipleSuggestedAction : FixAllSuggestedAction
{
private readonly Document _triggerDocumentOpt;
private readonly string _telemetryId;
internal FixMultipleSuggestedAction(
IAsynchronousOperationListener operationListener,
Workspace workspace,
ICodeActionEditHandlerService editHandler,
IWaitIndicator waitIndicator,
FixMultipleCodeAction codeAction,
FixAllProvider provider,
ITextBuffer subjectBufferOpt = null)
: base(workspace, subjectBufferOpt, editHandler, waitIndicator, codeAction, provider, originalFixedDiagnostic: codeAction.GetTriggerDiagnostic(), operationListener: operationListener)
{
_triggerDocumentOpt = codeAction.FixAllState.Document;
_telemetryId = GetTelemetryId(codeAction.FixAllState.DiagnosticIds);
}
private static string GetTelemetryId(IEnumerable<string> diagnosticIds)
{
// hash all the diagnostic IDs
var hash = 0;
foreach (var diagnosticId in diagnosticIds.Order())
{
hash = Hash.Combine(diagnosticId.GetHashCode(), hash);
}
return hash.ToString(CultureInfo.InvariantCulture);
}
public override string GetDiagnosticID()
{
return _telemetryId;
}
public override bool HasPreview
{
get
{
return false;
}
}
public override Task<object> GetPreviewAsync(CancellationToken cancellationToken)
{
return SpecializedTasks.Default<object>();
}
public Solution GetChangedSolution(CancellationToken cancellationToken)
{
Solution newSolution = null;
var extensionManager = this.Workspace.Services.GetService<IExtensionManager>();
extensionManager.PerformAction(Provider, () =>
{
// We don't need to post process changes here as the inner code action created for Fix multiple code fix already executes.
newSolution = CodeAction.GetChangedSolutionInternalAsync(postProcessChanges: false, cancellationToken: cancellationToken).WaitAndGetResult(cancellationToken);
});
return newSolution;
}
protected override async Task InvokeAsync(
IProgressTracker progressTracker, CancellationToken cancellationToken)
{
using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesSession, cancellationToken))
{
// We might not have an origin subject buffer, for example if we are fixing selected diagnostics in the error list.
if (this.SubjectBuffer != null)
{
await base.InvokeAsync(progressTracker, cancellationToken).ConfigureAwait(true);
}
else
{
Func<Document> getDocument = () => _triggerDocumentOpt;
await InvokeCoreAsync(getDocument, progressTracker, cancellationToken).ConfigureAwait(true);
}
}
}
}
}
......@@ -15,9 +15,8 @@ internal partial class FixMultipleCodeAction : FixAllCodeAction
FixAllState fixAllState,
Diagnostic triggerDiagnostic,
string title,
string computingFixWaitDialogMessage,
bool showPreviewChangesDialog)
: base(fixAllState, showPreviewChangesDialog)
string computingFixWaitDialogMessage)
: base(fixAllState, showPreviewChangesDialog: false)
{
_triggerDiagnostic = triggerDiagnostic;
_title = title;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册