Skip to content

Commit dad454b

Browse files
Improve performance of fix all that only changes syntax (#79108)
2 parents f294360 + b5fdaa6 commit dad454b

File tree

24 files changed

+192
-99
lines changed

24 files changed

+192
-99
lines changed

src/Analyzers/Core/CodeFixes/Formatting/FormattingCodeFixProvider.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ public sealed override ImmutableArray<string> FixableDiagnosticIds
3030

3131
protected abstract ISyntaxFormatting SyntaxFormatting { get; }
3232

33+
#if WORKSPACE
34+
/// <summary>
35+
/// This refactoring provider touches syntax only. So we can speed up fix all by having it only clean syntax
36+
/// and not semantics.
37+
/// </summary>
38+
protected override CodeActionCleanup Cleanup => CodeActionCleanup.SyntaxOnly;
39+
#endif
40+
3341
/// <summary>
3442
/// Fixing formatting is high priority. It's something the user wants to be able to fix quickly, is driven by
3543
/// them acting on an error reported in code, and can be computed fast as it only uses syntax not semantics.

src/Analyzers/Core/CodeFixes/UpgradeProject/AbstractUpgradeProjectCodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ internal sealed class ProjectOptionsChangeAction : SolutionChangeAction
125125
public override ImmutableArray<string> Tags => RequiresNonDocumentChangeTags;
126126

127127
private ProjectOptionsChangeAction(string title, Func<IProgress<CodeAnalysisProgress>, CancellationToken, Task<Solution>> createChangedSolution)
128-
: base(title, createChangedSolution, equivalenceKey: null, priority: CodeActionPriority.Default, createdFromFactoryMethod: true)
128+
: base(title, createChangedSolution, equivalenceKey: null, priority: CodeActionPriority.Default, CodeActionCleanup.Default, createdFromFactoryMethod: true)
129129
{
130130
}
131131

src/EditorFeatures/Core/Suggestions/FixAll/FixMultipleOccurrencesService.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Composition;
1010
using System.Threading;
1111
using System.Threading.Tasks;
12+
using Microsoft.CodeAnalysis.CodeActions;
1213
using Microsoft.CodeAnalysis.CodeFixes;
1314
using Microsoft.CodeAnalysis.Extensions;
1415
using Microsoft.CodeAnalysis.Host.Mef;
@@ -67,16 +68,14 @@ private static async Task<Solution> GetFixedSolutionAsync(
6768
IProgress<CodeAnalysisProgress> progress,
6869
CancellationToken cancellationToken)
6970
{
70-
var fixMultipleCodeAction = new FixMultipleCodeAction(
71-
fixAllState, title, waitDialogMessage);
71+
var fixMultipleCodeAction = new FixMultipleCodeAction(fixAllState, title, waitDialogMessage);
7272

7373
Solution newSolution = null;
7474
var extensionManager = workspace.Services.GetService<IExtensionManager>();
7575
await extensionManager.PerformActionAsync(fixAllState.FixAllProvider, async () =>
7676
{
77-
// We don't need to post process changes here as the inner code action created for Fix multiple code fix already executes.
7877
newSolution = await fixMultipleCodeAction.GetChangedSolutionInternalAsync(
79-
fixAllState.Solution, progress, postProcessChanges: false, cancellationToken).ConfigureAwait(false);
78+
fixAllState.Solution, progress, cancellationToken).ConfigureAwait(false);
8079
}).ConfigureAwait(false);
8180

8281
return newSolution;

src/EditorFeatures/Core/Suggestions/RefineUsingCopilot/RefineUsingCopilotCodeAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected override async Task<ImmutableArray<CodeActionOperation>> ComputeOperat
5959
// Consider if there could be better UX/platform support for such flavored actions
6060
// where clicking on the hyperlink needs to bring up another unrelated UI.
6161

62-
var newSolution = await originalCodeAction.GetChangedSolutionInternalAsync(originalSolution, progress, cancellationToken: cancellationToken).ConfigureAwait(false);
62+
var newSolution = await originalCodeAction.GetChangedSolutionInternalAsync(originalSolution, progress, cancellationToken).ConfigureAwait(false);
6363
if (newSolution == null)
6464
return [];
6565

src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ public async Task TestAdditionalDocumentCodeFixAsync()
874874

875875
// Verify code fix application
876876
var codeAction = txtDocumentCodeFixes.Single(s => s.Fixes.Single().Action.Title == fixer1.Title).Fixes.Single().Action;
877-
var solution = await codeAction.GetChangedSolutionInternalAsync(txtDocument.Project.Solution, CodeAnalysisProgress.None);
877+
var solution = await codeAction.GetChangedSolutionInternalAsync(txtDocument.Project.Solution, CodeAnalysisProgress.None, CancellationToken.None);
878878
var changedtxtDocument = solution!.Projects.Single().AdditionalDocuments.Single(t => t.Id == txtDocument.Id);
879879
Assert.Equal("Additional Document", txtDocument.GetTextSynchronously(CancellationToken.None).ToString());
880880
Assert.Equal($"Additional Document{fixer1.Title}", changedtxtDocument.GetTextSynchronously(CancellationToken.None).ToString());

src/EditorFeatures/Test/CodeRefactorings/CodeRefactoringServiceTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public async Task TestAdditionalDocumentRefactoringAsync()
178178

179179
// Verify code refactoring application
180180
var codeAction = txtRefactorings.Single(s => s.CodeActions.Single().action.Title == refactoring1.Title).CodeActions.Single().action;
181-
var solution = await codeAction.GetChangedSolutionInternalAsync(project.Solution, CodeAnalysisProgress.None);
181+
var solution = await codeAction.GetChangedSolutionInternalAsync(project.Solution, CodeAnalysisProgress.None, CancellationToken.None);
182182
var changedtxtDocument = solution.Projects.Single().AdditionalDocuments.Single(t => t.Id == txtAdditionalDocument.Id);
183183
Assert.Empty(txtAdditionalDocument.GetTextSynchronously(CancellationToken.None).ToString());
184184
Assert.Equal(refactoring1.Title, changedtxtDocument.GetTextSynchronously(CancellationToken.None).ToString());
@@ -217,7 +217,7 @@ public async Task TestAnalyzerConfigDocumentRefactoringAsync()
217217

218218
// Verify code refactoring application
219219
var codeAction = editorConfigRefactorings.Single(s => s.CodeActions.Single().action.Title == refactoring1.Title).CodeActions.Single().action;
220-
var solution = await codeAction.GetChangedSolutionInternalAsync(project.Solution, CodeAnalysisProgress.None);
220+
var solution = await codeAction.GetChangedSolutionInternalAsync(project.Solution, CodeAnalysisProgress.None, CancellationToken.None);
221221
var changedEditorConfig = solution.Projects.Single().AnalyzerConfigDocuments.Single(t => t.Id == editorConfig.Id);
222222
Assert.Empty(editorConfig.GetTextSynchronously(CancellationToken.None).ToString());
223223
Assert.Equal(refactoring1.Title, changedEditorConfig.GetTextSynchronously(CancellationToken.None).ToString());

src/Features/CSharp/Portable/CodeRefactorings/EnableNullable/EnableNullableCodeRefactoringProvider.FixAllProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ private sealed class FixAllCodeAction(Func<CodeActionPurpose, IProgress<CodeAnal
5757
: CodeAction.SolutionChangeAction(
5858
CSharpFeaturesResources.Enable_nullable_reference_types_in_solution,
5959
(progress, cancellationToken) => createChangedSolution(CodeActionPurpose.Apply, progress, cancellationToken),
60-
nameof(CSharpFeaturesResources.Enable_nullable_reference_types_in_solution))
60+
nameof(CSharpFeaturesResources.Enable_nullable_reference_types_in_solution),
61+
CodeActionPriority.Default,
62+
CodeActionCleanup.Default)
6163
{
6264
private readonly Func<CodeActionPurpose, IProgress<CodeAnalysisProgress>, CancellationToken, Task<Solution>> _createChangedSolution = createChangedSolution;
6365

src/Features/CSharp/Portable/CodeRefactorings/EnableNullable/EnableNullableCodeRefactoringProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ private sealed class CustomCodeAction(
267267
: CodeAction.SolutionChangeAction(
268268
CSharpFeaturesResources.Enable_nullable_reference_types_in_project,
269269
(progress, cancellationToken) => createChangedSolution(CodeActionPurpose.Apply, progress, cancellationToken),
270-
nameof(CSharpFeaturesResources.Enable_nullable_reference_types_in_project))
270+
nameof(CSharpFeaturesResources.Enable_nullable_reference_types_in_project),
271+
CodeActionPriority.Default,
272+
CodeActionCleanup.Default)
271273
{
272274
private readonly Func<CodeActionPurpose, IProgress<CodeAnalysisProgress>, CancellationToken, Task<Solution>> _createChangedSolution = createChangedSolution;
273275

src/Features/Core/Portable/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersCodeRefactoringProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using Microsoft.CodeAnalysis.Internal.Log;
1818
using Microsoft.CodeAnalysis.PooledObjects;
1919
using Microsoft.CodeAnalysis.Text;
20-
using Roslyn.Utilities;
2120

2221
namespace Microsoft.CodeAnalysis.AddConstructorParametersFromMembers;
2322

@@ -183,7 +182,7 @@ public async Task<ImmutableArray<IntentProcessorResult>> ComputeIntentAsync(
183182
{
184183
// Intents currently have no way to report progress.
185184
var changedSolution = await action.GetChangedSolutionInternalAsync(
186-
priorDocument.Project.Solution, CodeAnalysisProgress.None, postProcessChanges: true, cancellationToken).ConfigureAwait(false);
185+
priorDocument.Project.Solution, CodeAnalysisProgress.None, cancellationToken).ConfigureAwait(false);
187186
Contract.ThrowIfNull(changedSolution);
188187
var intent = new IntentProcessorResult(changedSolution, [priorDocument.Id], action.Title, action.ActionName);
189188
results.Add(intent);

src/Features/Core/Portable/CodeFixes/FixAllOccurrences/FixMultipleCodeAction.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ internal sealed partial class FixMultipleCodeAction(
1111
string title,
1212
string computingFixWaitDialogMessage) : AbstractFixAllCodeFixCodeAction(fixAllState, showPreviewChangesDialog: false)
1313
{
14-
private readonly string _title = title;
15-
private readonly string _computingFixWaitDialogMessage = computingFixWaitDialogMessage;
14+
public override string Title => title;
1615

17-
public override string Title => _title;
18-
19-
internal override string Message => _computingFixWaitDialogMessage;
16+
internal override string Message => computingFixWaitDialogMessage;
2017
}

0 commit comments

Comments
 (0)