diff --git a/src/Analyzers/CSharp/CodeFixes/AddBraces/CSharpAddBracesCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AddBraces/CSharpAddBracesCodeFixProvider.cs index dc922f79f679d..ef8087a9916c6 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddBraces/CSharpAddBracesCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddBraces/CSharpAddBracesCodeFixProvider.cs @@ -34,19 +34,13 @@ public override ImmutableArray FixableDiagnosticIds public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix( - CodeAction.Create( - CSharpAnalyzersResources.Add_braces, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(CSharpAnalyzersResources.Add_braces)), - context.Diagnostics); - + RegisterCodeFix(context, CSharpAnalyzersResources.Add_braces, nameof(CSharpAnalyzersResources.Add_braces)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var root = editor.OriginalRoot; foreach (var diagnostic in diagnostics) diff --git a/src/Analyzers/CSharp/CodeFixes/AddInheritdoc/AddInheritdocCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/AddInheritdoc/AddInheritdocCodeFixProvider.cs index 998a76c0142f6..533549c739a90 100644 --- a/src/Analyzers/CSharp/CodeFixes/AddInheritdoc/AddInheritdocCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/AddInheritdoc/AddInheritdocCodeFixProvider.cs @@ -79,14 +79,13 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) if (symbol.IsOverride || symbol.ImplicitInterfaceImplementations().Any()) { - context.RegisterCodeFix(new MyCodeAction(CSharpCodeFixesResources.Explicitly_inherit_documentation, - c => FixAsync(context.Document, diagnostic, c)), context.Diagnostics); + RegisterCodeFix(context, CSharpCodeFixesResources.Explicitly_inherit_documentation, nameof(CSharpCodeFixesResources.Explicitly_inherit_documentation), diagnostic); } } } } - protected override async Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) + protected override async Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { string? newLine = null; SourceText? sourceText = null; @@ -99,11 +98,11 @@ protected override async Task FixAllAsync(Document document, ImmutableArray comment. var xmlSpaceAfterTripleSlash = Token(leading: TriviaList(DocumentationCommentExterior("///")), SyntaxKind.XmlTextLiteralToken, text: " ", valueText: " ", trailing: default); @@ -131,13 +130,5 @@ protected override async Task FixAllAsync(Document document, ImmutableArray> createChangedDocument) - : base(title, createChangedDocument, equivalenceKey: nameof(CSharpCodeFixesResources.Explicitly_inherit_documentation)) - { - } - } } } diff --git a/src/Analyzers/CSharp/CodeFixes/ConvertNamespace/ConvertNamespaceCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConvertNamespace/ConvertNamespaceCodeFixProvider.cs index 2e9d931bd80f0..394a287bc2dee 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConvertNamespace/ConvertNamespaceCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConvertNamespace/ConvertNamespaceCodeFixProvider.cs @@ -56,7 +56,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) }); context.RegisterCodeFix( - CodeAction.Create(title, c => FixAsync(context.Document, diagnostic, c), equivalenceKey), + CodeAction.Create(title, GetDocumentUpdater(context), equivalenceKey), context.Diagnostics); return Task.CompletedTask; @@ -64,7 +64,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var diagnostic = diagnostics.First(); @@ -72,11 +72,11 @@ protected override async Task FixAllAsync( #if CODE_STYLE var configOptions = document.Project.AnalyzerOptions.GetAnalyzerOptionSet(namespaceDecl.SyntaxTree, cancellationToken); - var options = CSharpSyntaxFormattingOptions.Create(configOptions); + var formattingOptions = CSharpSyntaxFormattingOptions.Create(configOptions); #else - var options = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); + var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); #endif - var converted = await ConvertAsync(document, namespaceDecl, options, cancellationToken).ConfigureAwait(false); + var converted = await ConvertAsync(document, namespaceDecl, formattingOptions, cancellationToken).ConfigureAwait(false); editor.ReplaceNode( editor.OriginalRoot, diff --git a/src/Analyzers/CSharp/CodeFixes/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionCodeFixProvider.cs index 24a22fe0acc59..f456b86d1969d 100644 --- a/src/Analyzers/CSharp/CodeFixes/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/ConvertSwitchStatementToExpression/ConvertSwitchStatementToExpressionCodeFixProvider.cs @@ -48,18 +48,13 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) return Task.CompletedTask; } - context.RegisterCodeFix( - CodeAction.Create( - CSharpAnalyzersResources.Convert_switch_statement_to_expression, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(CSharpAnalyzersResources.Convert_switch_statement_to_expression)), - context.Diagnostics); + RegisterCodeFix(context, CSharpAnalyzersResources.Convert_switch_statement_to_expression, nameof(CSharpAnalyzersResources.Convert_switch_statement_to_expression)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { using var spansDisposer = ArrayBuilder.GetInstance(diagnostics.Length, out var spans); foreach (var diagnostic in diagnostics) diff --git a/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs index b0b07ed6768af..5abbd56edc6ef 100644 --- a/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/DisambiguateSameVariable/CSharpDisambiguateSameVariableCodeFixProvider.cs @@ -46,14 +46,9 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) var cancellationToken = context.CancellationToken; var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); - if (CanFix( - semanticModel, diagnostic, cancellationToken, - out _, out _, out var title)) + if (CanFix(semanticModel, diagnostic, cancellationToken, out _, out _, out var title)) { - context.RegisterCodeFix(new MyCodeAction( - title, - c => FixAsync(document, diagnostic, c)), - context.Diagnostics); + RegisterCodeFix(context, title, nameof(CSharpDisambiguateSameVariableCodeFixProvider)); } } @@ -141,7 +136,7 @@ where m.IsAccessibleWithin(enclosingType) protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var syntaxFacts = CSharpSyntaxFacts.Instance; var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); @@ -167,13 +162,5 @@ protected override async Task FixAllAsync( editor.ReplaceNode(nameNode, newExpr); } } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(string title, Func> createChangedDocument) - : base(title, createChangedDocument, nameof(CSharpDisambiguateSameVariableCodeFixProvider)) - { - } - } } } diff --git a/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs index 487b8d79e7544..1e24429946d1c 100644 --- a/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/FixIncorrectConstraint/CSharpFixIncorrectConstraintCodeFixProvider.cs @@ -68,15 +68,12 @@ private static bool TryGetConstraint( public override Task RegisterCodeFixesAsync(CodeFixContext context) { - var document = context.Document; var cancellationToken = context.CancellationToken; var diagnostic = context.Diagnostics.First(); if (TryGetConstraint(diagnostic, cancellationToken, out _, out _)) { - context.RegisterCodeFix( - new MyCodeAction(c => this.FixAsync(document, diagnostic, c)), - diagnostic); + RegisterCodeFix(context, CSharpCodeFixesResources.Fix_constraint, nameof(CSharpFixIncorrectConstraintCodeFixProvider)); } return Task.CompletedTask; @@ -84,7 +81,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var generator = SyntaxGenerator.GetGenerator(document); var compilation = await document.Project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false); @@ -118,14 +115,5 @@ protected override async Task FixAllAsync( } } } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction( - Func> createChangedDocument) - : base(CSharpCodeFixesResources.Fix_constraint, createChangedDocument, nameof(CSharpFixIncorrectConstraintCodeFixProvider)) - { - } - } } } diff --git a/src/Analyzers/CSharp/CodeFixes/FixReturnType/CSharpFixReturnTypeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/FixReturnType/CSharpFixReturnTypeCodeFixProvider.cs index 183e9a4bef38f..8a5090c704316 100644 --- a/src/Analyzers/CSharp/CodeFixes/FixReturnType/CSharpFixReturnTypeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/FixReturnType/CSharpFixReturnTypeCodeFixProvider.cs @@ -56,9 +56,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) return; } - context.RegisterCodeFix( - new MyCodeAction(c => FixAsync(document, diagnostics.First(), c)), - diagnostics); + RegisterCodeFix(context, CSharpCodeFixesResources.Fix_return_type, nameof(CSharpCodeFixesResources.Fix_return_type)); return; @@ -103,7 +101,7 @@ static bool IsVoid(TypeSyntax typeSyntax) return (declarationTypeToFix, fixedDeclaration); } - protected override async Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) + protected override async Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var (declarationTypeToFix, fixedDeclaration) = await TryGetOldAndNewReturnTypeAsync(document, diagnostics, cancellationToken).ConfigureAwait(false); @@ -129,13 +127,5 @@ private static (TypeSyntax type, bool useTask) TryGetDeclarationTypeToFix(Syntax }; } } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(Func> createChangedDocument) - : base(CSharpCodeFixesResources.Fix_return_type, createChangedDocument, nameof(CSharpCodeFixesResources.Fix_return_type)) - { - } - } } } diff --git a/src/Analyzers/CSharp/CodeFixes/InlineDeclaration/CSharpInlineDeclarationCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/InlineDeclaration/CSharpInlineDeclarationCodeFixProvider.cs index 5ab335d2f0a3e..6e0167154e1a3 100644 --- a/src/Analyzers/CSharp/CodeFixes/InlineDeclaration/CSharpInlineDeclarationCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/InlineDeclaration/CSharpInlineDeclarationCodeFixProvider.cs @@ -49,22 +49,18 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - CSharpAnalyzersResources.Inline_variable_declaration, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(CSharpAnalyzersResources.Inline_variable_declaration)), - context.Diagnostics); + RegisterCodeFix(context, CSharpAnalyzersResources.Inline_variable_declaration, nameof(CSharpAnalyzersResources.Inline_variable_declaration)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { #if CODE_STYLE - var options = document.Project.AnalyzerOptions.GetAnalyzerOptionSet(editor.OriginalRoot.SyntaxTree, cancellationToken); + var optionSet = document.Project.AnalyzerOptions.GetAnalyzerOptionSet(editor.OriginalRoot.SyntaxTree, cancellationToken); #else - var options = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); + var optionSet = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); #endif // Gather all statements to be removed @@ -97,7 +93,7 @@ await editor.ApplyExpressionLevelSemanticEditsAsync( (_1, _2, _3) => true, (semanticModel, currentRoot, t, currentNode) => ReplaceIdentifierWithInlineDeclaration( - options, semanticModel, currentRoot, t.declarator, + optionSet, semanticModel, currentRoot, t.declarator, t.identifier, currentNode, declarationsToRemove, document.Project.Solution.Workspace.Services, cancellationToken), cancellationToken).ConfigureAwait(false); diff --git a/src/Analyzers/CSharp/CodeFixes/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.cs index 6ba8d251d6e39..c43abfb8861e8 100644 --- a/src/Analyzers/CSharp/CodeFixes/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/InvokeDelegateWithConditionalAccess/InvokeDelegateWithConditionalAccessCodeFixProvider.cs @@ -40,17 +40,13 @@ protected override bool IncludeDiagnosticDuringFixAll(Diagnostic diagnostic) public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - CSharpAnalyzersResources.Simplify_delegate_invocation, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(CSharpAnalyzersResources.Simplify_delegate_invocation)), - context.Diagnostics); + RegisterCodeFix(context, CSharpAnalyzersResources.Simplify_delegate_invocation, nameof(CSharpAnalyzersResources.Simplify_delegate_invocation)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var diagnostic in diagnostics) { diff --git a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpAddYieldCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpAddYieldCodeFixProvider.cs index a2563be682c9e..447adc71679c2 100644 --- a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpAddYieldCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpAddYieldCodeFixProvider.cs @@ -81,7 +81,11 @@ public override ImmutableArray FixableDiagnosticIds .WithAdditionalAnnotations(Formatter.Annotation); root = root.ReplaceNode(returnStatement, yieldStatement); - return new MyCodeAction(document.WithSyntaxRoot(root)); + + return CodeAction.Create( + CSharpCodeFixesResources.Replace_return_with_yield_return, + _ => Task.FromResult(document.WithSyntaxRoot(root)), + nameof(CSharpCodeFixesResources.Replace_return_with_yield_return)); } private static bool TryGetExpressionType( @@ -219,13 +223,5 @@ protected override bool TryGetNode( node = ancestors.FirstOrDefault(n => n.Span.Contains(span) && n != root && n.IsKind(SyntaxKind.ReturnStatement)); return node != null; } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(Document newDocument) - : base(CSharpCodeFixesResources.Replace_return_with_yield_return, c => Task.FromResult(newDocument), nameof(CSharpCodeFixesResources.Replace_return_with_yield_return)) - { - } - } } } diff --git a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs index 3976f1edfcf3a..2a038c1581ccc 100644 --- a/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/Iterator/CSharpChangeToIEnumerableCodeFixProvider.cs @@ -110,10 +110,11 @@ protected override async Task GetCodeFixAsync(SyntaxNode root, Synta return null; } - return new MyCodeAction( - string.Format(CSharpCodeFixesResources.Change_return_type_from_0_to_1, - type.ToMinimalDisplayString(model, node.SpanStart), - ienumerableGenericSymbol.ToMinimalDisplayString(model, node.SpanStart)), newDocument); + var title = string.Format(CSharpCodeFixesResources.Change_return_type_from_0_to_1, + type.ToMinimalDisplayString(model, node.SpanStart), + ienumerableGenericSymbol.ToMinimalDisplayString(model, node.SpanStart)); + + return CodeAction.Create(title, _ => Task.FromResult(newDocument), title); } private static bool TryGetIEnumerableSymbols(SemanticModel model, out INamedTypeSymbol ienumerableSymbol, out INamedTypeSymbol ienumerableGenericSymbol) @@ -129,13 +130,5 @@ private static bool TryGetIEnumerableSymbols(SemanticModel model, out INamedType return true; } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(string title, Document newDocument) - : base(title, c => Task.FromResult(newDocument), title) - { - } - } } } diff --git a/src/Analyzers/CSharp/CodeFixes/MakeStatementAsynchronous/CSharpMakeStatementAsynchronousCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeStatementAsynchronous/CSharpMakeStatementAsynchronousCodeFixProvider.cs index 5c8a540040101..988594019b8fb 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeStatementAsynchronous/CSharpMakeStatementAsynchronousCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeStatementAsynchronous/CSharpMakeStatementAsynchronousCodeFixProvider.cs @@ -46,14 +46,12 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) return; } - context.RegisterCodeFix(new MyCodeAction( - c => FixAsync(context.Document, diagnostic, c)), - context.Diagnostics); + RegisterCodeFix(context, CSharpCodeFixesResources.Add_await, nameof(CSharpCodeFixesResources.Add_await)); } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var diagnostic in diagnostics) { @@ -114,15 +112,5 @@ private static SyntaxNode TryGetStatementToFix(SyntaxNode node) return null; } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(Func> createChangedDocument) - : base(CSharpCodeFixesResources.Add_await, - createChangedDocument, - CSharpCodeFixesResources.Add_await) - { - } - } } } diff --git a/src/Analyzers/CSharp/CodeFixes/MakeStructFieldsWritable/CSharpMakeStructFieldsWritableCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/MakeStructFieldsWritable/CSharpMakeStructFieldsWritableCodeFixProvider.cs index cb01375c7b4df..4b4aed30248fa 100644 --- a/src/Analyzers/CSharp/CodeFixes/MakeStructFieldsWritable/CSharpMakeStructFieldsWritableCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/MakeStructFieldsWritable/CSharpMakeStructFieldsWritableCodeFixProvider.cs @@ -34,11 +34,7 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - CSharpAnalyzersResources.Make_readonly_fields_writable, - c => FixAsync(context.Document, context.Diagnostics[0], c), - nameof(CSharpAnalyzersResources.Make_readonly_fields_writable)), - context.Diagnostics); + RegisterCodeFix(context, CSharpAnalyzersResources.Make_readonly_fields_writable, nameof(CSharpAnalyzersResources.Make_readonly_fields_writable)); return Task.CompletedTask; } @@ -46,7 +42,7 @@ protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, SyntaxEditor editor, - CancellationToken cancellationToken) + CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var diagnostic in diagnostics) { diff --git a/src/Analyzers/CSharp/CodeFixes/Nullable/CSharpDeclareAsNullableCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/Nullable/CSharpDeclareAsNullableCodeFixProvider.cs index c71147a47d65f..8c63b45286ba7 100644 --- a/src/Analyzers/CSharp/CodeFixes/Nullable/CSharpDeclareAsNullableCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/Nullable/CSharpDeclareAsNullableCodeFixProvider.cs @@ -67,10 +67,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) return; } - context.RegisterCodeFix(new MyCodeAction( - c => FixAsync(context.Document, diagnostic, c), - GetEquivalenceKey(node, model)), - context.Diagnostics); + RegisterCodeFix(context, CSharpCodeFixesResources.Declare_as_nullable, GetEquivalenceKey(node, model)); } private static string GetEquivalenceKey(SyntaxNode node, SemanticModel model) @@ -108,7 +105,7 @@ static bool IsRemoteApiUsage(SyntaxNode node, SemanticModel model) protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { // a method can have multiple `return null;` statements, but we should only fix its return type once using var _ = PooledHashSet.GetInstance(out var alreadyHandled); @@ -380,15 +377,5 @@ private static bool IsExpressionSupported(SyntaxNode node) SyntaxKind.PropertyDeclaration, SyntaxKind.VariableDeclarator); } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(Func> createChangedDocument, string equivalenceKey) - : base(CSharpCodeFixesResources.Declare_as_nullable, - createChangedDocument, - equivalenceKey) - { - } - } } } diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs index 33a9d2b774158..0736cfdc7d8b9 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryCast/CSharpRemoveUnnecessaryCastCodeFixProvider.cs @@ -38,17 +38,13 @@ public CSharpRemoveUnnecessaryCastCodeFixProvider() public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Remove_Unnecessary_Cast, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(AnalyzersResources.Remove_Unnecessary_Cast)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Remove_Unnecessary_Cast, nameof(AnalyzersResources.Remove_Unnecessary_Cast)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var castNodes = diagnostics.SelectAsArray( d => (ExpressionSyntax)d.AdditionalLocations[0].FindNode(getInnermostNodeForTie: true, cancellationToken)); diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryDiscardDesignation/CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryDiscardDesignation/CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider.cs index 7270afc67306b..1a2e69f63da19 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryDiscardDesignation/CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryDiscardDesignation/CSharpRemoveUnnecessaryDiscardDesignationCodeFixProvider.cs @@ -35,20 +35,13 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - var diagnostic = context.Diagnostics.First(); - context.RegisterCodeFix( - CodeAction.Create( - CSharpAnalyzersResources.Remove_unnessary_discard, - c => FixAsync(context.Document, diagnostic, c), - nameof(CSharpAnalyzersResources.Remove_unnessary_discard)), - diagnostic); - + RegisterCodeFix(context, CSharpAnalyzersResources.Remove_unnessary_discard, nameof(CSharpAnalyzersResources.Remove_unnessary_discard)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var generator = editor.Generator; diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryLambdaExpression/CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryLambdaExpression/CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider.cs index a8a691c04ee77..bb2371f504e7c 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryLambdaExpression/CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnnecessaryLambdaExpression/CSharpRemoveUnnecessaryLambdaExpressionCodeFixProvider.cs @@ -36,18 +36,13 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix( - CodeAction.Create( - CSharpAnalyzersResources.Remove_unnecessary_lambda_expression, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(CSharpAnalyzersResources.Remove_unnecessary_lambda_expression)), - context.Diagnostics); + RegisterCodeFix(context, CSharpAnalyzersResources.Remove_unnecessary_lambda_expression, nameof(CSharpAnalyzersResources.Remove_unnecessary_lambda_expression)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var diagnostic in diagnostics) { diff --git a/src/Analyzers/CSharp/CodeFixes/RemoveUnreachableCode/CSharpRemoveUnreachableCodeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/RemoveUnreachableCode/CSharpRemoveUnreachableCodeCodeFixProvider.cs index 5538e6eb7ff66..b1f8a06a2be23 100644 --- a/src/Analyzers/CSharp/CodeFixes/RemoveUnreachableCode/CSharpRemoveUnreachableCodeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/RemoveUnreachableCode/CSharpRemoveUnreachableCodeCodeFixProvider.cs @@ -37,12 +37,6 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) { var diagnostic = context.Diagnostics[0]; -#if CODE_STYLE // 'CodeActionPriority' is not a public API, hence not supported in CodeStyle layer. - // https://github.com/dotnet/roslyn/issues/42431 tracks adding a public API. - var codeAction = new MyCodeAction( - CSharpCodeFixesResources.Remove_unreachable_code, - c => FixAsync(context.Document, diagnostic, c)); -#else // Only the first reported unreacha ble line will have a squiggle. On that line, make the // code action normal priority as the user is likely bringing up the lightbulb to fix the // squiggle. On all the other lines make the code action low priority as it's definitely @@ -51,13 +45,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) ? CodeActionPriority.Low : CodeActionPriority.Medium; - var codeAction = new MyCodeAction( - CSharpCodeFixesResources.Remove_unreachable_code, - c => FixAsync(context.Document, diagnostic, c), - priority); -#endif - - context.RegisterCodeFix(codeAction, diagnostic); + RegisterCodeFix(context, CSharpCodeFixesResources.Remove_unreachable_code, nameof(CSharpCodeFixesResources.Remove_unreachable_code), priority); return Task.CompletedTask; } @@ -72,7 +60,7 @@ protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, SyntaxEditor editor, - CancellationToken cancellationToken) + CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var diagnostic in diagnostics) { @@ -107,29 +95,5 @@ static void RemoveStatement(SyntaxEditor editor, SyntaxNode statement) } } } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { -#if CODE_STYLE // 'CodeActionPriority' is not a public API, hence not supported in CodeStyle layer. - // https://github.com/dotnet/roslyn/issues/42431 tracks adding a public API. - public MyCodeAction( - string title, - Func> createChangedDocument) - : base(title, createChangedDocument, title) - { - } -#else - public MyCodeAction( - string title, - Func> createChangedDocument, - CodeActionPriority priority) - : base(title, createChangedDocument, title) - { - Priority = priority; - } - - internal override CodeActionPriority Priority { get; } -#endif - } } } diff --git a/src/Analyzers/CSharp/CodeFixes/SimplifyPropertyPattern/CSharpSimplifyPropertyPatternCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/SimplifyPropertyPattern/CSharpSimplifyPropertyPatternCodeFixProvider.cs index 7fec44ac563c9..1c308f0a11aea 100644 --- a/src/Analyzers/CSharp/CodeFixes/SimplifyPropertyPattern/CSharpSimplifyPropertyPatternCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/SimplifyPropertyPattern/CSharpSimplifyPropertyPatternCodeFixProvider.cs @@ -36,18 +36,13 @@ public CSharpSimplifyPropertyPatternCodeFixProvider() public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - CSharpAnalyzersResources.Simplify_property_pattern, - c => FixAsync(context.Document, context.Diagnostics[0], c), - nameof(CSharpAnalyzersResources.Simplify_property_pattern)), - context.Diagnostics); - + RegisterCodeFix(context, CSharpAnalyzersResources.Simplify_property_pattern, nameof(CSharpAnalyzersResources.Simplify_property_pattern)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { // Process subpatterns in reverse order so we rewrite from inside-to-outside with nested // patterns. diff --git a/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs index 351b32c138378..b37a34c251bfd 100644 --- a/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/TransposeRecordKeyword/CSharpTransposeRecordKeywordCodeFixProvider.cs @@ -86,19 +86,13 @@ private static bool TryGetTokens( public override Task RegisterCodeFixesAsync(CodeFixContext context) { - var document = context.Document; var cancellationToken = context.CancellationToken; var diagnostic = context.Diagnostics.First(); if (TryGetRecordDeclaration(diagnostic, cancellationToken, out var recordDeclaration) && TryGetTokens(recordDeclaration, out _, out _)) { - context.RegisterCodeFix( - CodeAction.Create( - CSharpCodeFixesResources.Fix_record_declaration, - c => this.FixAsync(document, diagnostic, c), - nameof(CSharpCodeFixesResources.Fix_record_declaration)), - diagnostic); + RegisterCodeFix(context, CSharpCodeFixesResources.Fix_record_declaration, nameof(CSharpCodeFixesResources.Fix_record_declaration)); } return Task.CompletedTask; @@ -106,7 +100,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var diagnostic in diagnostics) { diff --git a/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs index b8e9f53d85f2d..9fb547e882f53 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseCompoundAssignment/CSharpUseCompoundCoalesceAssignmentCodeFixProvider.cs @@ -33,21 +33,13 @@ public CSharpUseCompoundCoalesceAssignmentCodeFixProvider() public override Task RegisterCodeFixesAsync(CodeFixContext context) { - var document = context.Document; - var diagnostic = context.Diagnostics[0]; - - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Use_compound_assignment, - c => FixAsync(document, diagnostic, c), - nameof(AnalyzersResources.Use_compound_assignment)), - context.Diagnostics); - + RegisterCodeFix(context, AnalyzersResources.Use_compound_assignment, nameof(AnalyzersResources.Use_compound_assignment)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs index 327e6fb9f2e12..aef4b6a6b9e2e 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseDeconstruction/CSharpUseDeconstructionCodeFixProvider.cs @@ -36,19 +36,13 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix( - CodeAction.Create( - CSharpAnalyzersResources.Deconstruct_variable_declaration, - c => FixAsync(context.Document, context.Diagnostics[0], c), - nameof(CSharpAnalyzersResources.Deconstruct_variable_declaration)), - context.Diagnostics); - + RegisterCodeFix(context, CSharpAnalyzersResources.Deconstruct_variable_declaration, nameof(CSharpAnalyzersResources.Deconstruct_variable_declaration)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var nodesToProcess = diagnostics.SelectAsArray(d => d.Location.FindToken(cancellationToken).Parent); diff --git a/src/Analyzers/CSharp/CodeFixes/UseDefaultLiteral/CSharpUseDefaultLiteralCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseDefaultLiteral/CSharpUseDefaultLiteralCodeFixProvider.cs index 8aca1035b89c6..f5685c6cad970 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseDefaultLiteral/CSharpUseDefaultLiteralCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseDefaultLiteral/CSharpUseDefaultLiteralCodeFixProvider.cs @@ -37,17 +37,13 @@ public CSharpUseDefaultLiteralCodeFixProvider() public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - CSharpAnalyzersResources.Simplify_default_expression, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(CSharpAnalyzersResources.Simplify_default_expression)), - context.Diagnostics); + RegisterCodeFix(context, CSharpAnalyzersResources.Simplify_default_expression, nameof(CSharpAnalyzersResources.Simplify_default_expression)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { // Fix-All for this feature is somewhat complicated. Each time we fix one case, it // may make the next case unfixable. For example: diff --git a/src/Analyzers/CSharp/CodeFixes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs index d84665dbaeb8b..fea3e43e4faf0 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseExpressionBody/UseExpressionBodyCodeFixProvider.cs @@ -38,29 +38,23 @@ protected override bool IncludeDiagnosticDuringFixAll(Diagnostic diagnostic) => !diagnostic.IsSuppressed || diagnostic.Properties.ContainsKey(UseExpressionBodyDiagnosticAnalyzer.FixesError); - public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) + public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) { var diagnostic = context.Diagnostics.First(); - var documentOptionSet = await context.Document.GetOptionsAsync(context.CancellationToken).ConfigureAwait(false); -#if CODE_STYLE // 'CodeActionPriority' is not a public API, hence not supported in CodeStyle layer. - var codeAction = new MyCodeAction(diagnostic.GetMessage(), c => FixAsync(context.Document, diagnostic, c)); -#else var priority = diagnostic.Severity == DiagnosticSeverity.Hidden ? CodeActionPriority.Low : CodeActionPriority.Medium; - var codeAction = new MyCodeAction(diagnostic.GetMessage(), priority, c => FixAsync(context.Document, diagnostic, c)); -#endif + var title = diagnostic.GetMessage(); - context.RegisterCodeFix( - codeAction, - diagnostic); + RegisterCodeFix(context, title, title, priority); + return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); @@ -100,23 +94,5 @@ private static void AddEdits( accessorLists.Add(accessorList); } } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { -#if CODE_STYLE // 'CodeActionPriority' is not a public API, hence not supported in CodeStyle layer. - public MyCodeAction(string title, Func> createChangedDocument) - : base(title, createChangedDocument, title) - { - } -#else - internal override CodeActionPriority Priority { get; } - - public MyCodeAction(string title, CodeActionPriority priority, Func> createChangedDocument) - : base(title, createChangedDocument, title) - { - Priority = priority; - } -#endif - } } } diff --git a/src/Analyzers/CSharp/CodeFixes/UseImplicitObjectCreation/CSharpUseImplicitObjectCreationCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseImplicitObjectCreation/CSharpUseImplicitObjectCreationCodeFixProvider.cs index f648d20534010..5ae843e2cd98f 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseImplicitObjectCreation/CSharpUseImplicitObjectCreationCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseImplicitObjectCreation/CSharpUseImplicitObjectCreationCodeFixProvider.cs @@ -38,18 +38,13 @@ protected override bool IncludeDiagnosticDuringFixAll(Diagnostic diagnostic) public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix( - CodeAction.Create( - CSharpAnalyzersResources.Use_new, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(CSharpAnalyzersResources.Use_new)), - context.Diagnostics); + RegisterCodeFix(context, CSharpAnalyzersResources.Use_new, nameof(CSharpAnalyzersResources.Use_new)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { // process from inside->out so that outer rewrites see the effects of inner changes. foreach (var diagnostic in diagnostics.OrderBy(d => d.Location.SourceSpan.End)) diff --git a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs index d7648163fc1c7..1a4ef403931a2 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseExplicitTypeCodeFixProvider.cs @@ -37,18 +37,13 @@ public UseExplicitTypeCodeFixProvider() public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - CSharpAnalyzersResources.Use_explicit_type_instead_of_var, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(CSharpAnalyzersResources.Use_explicit_type_instead_of_var)), - context.Diagnostics); - + RegisterCodeFix(context, CSharpAnalyzersResources.Use_explicit_type_instead_of_var, nameof(CSharpAnalyzersResources.Use_explicit_type_instead_of_var)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var root = editor.OriginalRoot; diff --git a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs index 0076a21aa33ee..5a42122b6dddc 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseImplicitOrExplicitType/UseImplicitTypeCodeFixProvider.cs @@ -35,19 +35,13 @@ public UseImplicitTypeCodeFixProvider() public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix( - CodeAction.Create( - CSharpAnalyzersResources.use_var_instead_of_explicit_type, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(CSharpAnalyzersResources.use_var_instead_of_explicit_type)), - context.Diagnostics); - + RegisterCodeFix(context, CSharpAnalyzersResources.use_var_instead_of_explicit_type, nameof(CSharpAnalyzersResources.use_var_instead_of_explicit_type)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var root = editor.OriginalRoot; diff --git a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs index ed3589b9a0d07..08a3c0a4f017a 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseIndexOperatorCodeFixProvider.cs @@ -36,18 +36,13 @@ public CSharpUseIndexOperatorCodeFixProvider() public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - CSharpAnalyzersResources.Use_index_operator, - c => FixAsync(context.Document, context.Diagnostics[0], c), - nameof(CSharpAnalyzersResources.Use_index_operator)), - context.Diagnostics); - + RegisterCodeFix(context, CSharpAnalyzersResources.Use_index_operator, nameof(CSharpAnalyzersResources.Use_index_operator)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { // Process diagnostics from innermost to outermost in case any are nested. foreach (var diagnostic in diagnostics.OrderByDescending(d => d.Location.SourceSpan.Start)) diff --git a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseRangeOperatorCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseRangeOperatorCodeFixProvider.cs index 177a9bb272b1d..465e9a65e287f 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseRangeOperatorCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIndexOrRangeOperator/CSharpUseRangeOperatorCodeFixProvider.cs @@ -41,18 +41,13 @@ public CSharpUseRangeOperatorCodeFixProvider() public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - CSharpAnalyzersResources.Use_range_operator, - c => FixAsync(context.Document, context.Diagnostics[0], c), - nameof(CSharpAnalyzersResources.Use_range_operator)), - context.Diagnostics); - + RegisterCodeFix(context, CSharpAnalyzersResources.Use_range_operator, nameof(CSharpAnalyzersResources.Use_range_operator)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var invocationNodes = diagnostics.Select(d => GetInvocationExpression(d, cancellationToken)) .OrderByDescending(i => i.SpanStart) diff --git a/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs index 586642043b3ea..e92d7c5bd7657 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseInterpolatedVerbatimString/CSharpUseInterpolatedVerbatimStringCodeFixProvider.cs @@ -39,15 +39,13 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(new MyCodeAction( - c => FixAsync(context.Document, context.Diagnostics.First(), c)), - context.Diagnostics); + RegisterCodeFix(context, CSharpCodeFixesResources.Use_interpolated_verbatim_string, nameof(CSharpCodeFixesResources.Use_interpolated_verbatim_string)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var diagnostic in diagnostics) { @@ -74,13 +72,5 @@ private static void AddEdits( editor.ReplaceNode(verbatimInterpolated, interpolatedVerbatim); } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(Func> createChangedDocument) - : base(CSharpCodeFixesResources.Use_interpolated_verbatim_string, createChangedDocument, nameof(CSharpCodeFixesResources.Use_interpolated_verbatim_string)) - { - } - } } } diff --git a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs index 46344e04300a7..0c5db8fc077df 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseIsNullCheckForCastAndEqualityOperatorCodeFixProvider.cs @@ -47,7 +47,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) var title = GetTitle(negated, diagnostic.Location.SourceTree!.Options); context.RegisterCodeFix( - CodeAction.Create(title, c => FixAsync(context.Document, diagnostic, c), title), + CodeAction.Create(title, GetDocumentUpdater(context), title), context.Diagnostics); } @@ -56,7 +56,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var diagnostic in diagnostics) { diff --git a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseNullCheckOverTypeCheckCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseNullCheckOverTypeCheckCodeFixProvider.cs index 354beb592db11..220cd2ea5aee6 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseNullCheckOverTypeCheckCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseIsNullCheck/CSharpUseNullCheckOverTypeCheckCodeFixProvider.cs @@ -37,20 +37,13 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - var diagnostic = context.Diagnostics.First(); - context.RegisterCodeFix( - CodeAction.Create( - CSharpAnalyzersResources.Prefer_null_check_over_type_check, - c => FixAsync(context.Document, diagnostic, c), - nameof(CSharpAnalyzersResources.Prefer_null_check_over_type_check)), - context.Diagnostics); - + RegisterCodeFix(context, CSharpAnalyzersResources.Prefer_null_check_over_type_check, nameof(CSharpAnalyzersResources.Prefer_null_check_over_type_check)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var diagnostic in diagnostics) { diff --git a/src/Analyzers/CSharp/CodeFixes/UseParameterNullChecking/CSharpUseParameterNullCheckingCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseParameterNullChecking/CSharpUseParameterNullCheckingCodeFixProvider.cs index 2223988c12c77..134b6b59cbdf0 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseParameterNullChecking/CSharpUseParameterNullCheckingCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseParameterNullChecking/CSharpUseParameterNullCheckingCodeFixProvider.cs @@ -35,19 +35,13 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - var diagnostic = context.Diagnostics[0]; - context.RegisterCodeFix( - CodeAction.Create( - CSharpAnalyzersResources.Use_parameter_null_checking, - c => FixAsync(context.Document, diagnostic, c), - nameof(CSharpAnalyzersResources.Use_parameter_null_checking)), - context.Diagnostics); + RegisterCodeFix(context, CSharpAnalyzersResources.Use_parameter_null_checking, nameof(CSharpAnalyzersResources.Use_parameter_null_checking)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { // Tracking parameters which have already been fixed by a fix-all operation. // This avoids crashing the fixer when the same parameter is null-tested multiple times. diff --git a/src/Analyzers/CSharp/CodeFixes/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs index 21c3a8aeecd19..c4613d1df86cf 100644 --- a/src/Analyzers/CSharp/CodeFixes/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs @@ -66,19 +66,18 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) var diagnostic = context.Diagnostics.First(); var isSafe = CSharpUsePatternCombinatorsDiagnosticAnalyzer.IsSafe(diagnostic); - context.RegisterCodeFix( - new MyCodeAction( - isSafe ? CSharpAnalyzersResources.Use_pattern_matching : CSharpAnalyzersResources.Use_pattern_matching_may_change_code_meaning, - c => FixAsync(context.Document, diagnostic, c), - isSafe ? SafeEquivalenceKey : UnsafeEquivalenceKey), - context.Diagnostics); + RegisterCodeFix( + context, + isSafe ? CSharpAnalyzersResources.Use_pattern_matching : CSharpAnalyzersResources.Use_pattern_matching_may_change_code_meaning, + isSafe ? SafeEquivalenceKey : UnsafeEquivalenceKey, + CodeActionPriority.Low); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); foreach (var diagnostic in diagnostics) @@ -138,17 +137,5 @@ private static ExpressionSyntax AsExpressionSyntax(ExpressionSyntax expr, Analyz return expr.Parenthesize(); } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(string title, Func> createChangedDocument, string equivalenceKey) - : base(title, createChangedDocument, equivalenceKey) - { - } - -#if !CODE_STYLE // 'CodeActionPriority' is not a public API, hence not supported in CodeStyle layer. - internal override CodeActionPriority Priority => CodeActionPriority.Low; -#endif - } } } diff --git a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndNullCheckCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndNullCheckCodeFixProvider.cs index 0008363b4161c..0f5cf6adbf982 100644 --- a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndNullCheckCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpAsAndNullCheckCodeFixProvider.cs @@ -37,17 +37,13 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - CSharpAnalyzersResources.Use_pattern_matching, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(CSharpAnalyzersResources.Use_pattern_matching)), - context.Diagnostics); + RegisterCodeFix(context, CSharpAnalyzersResources.Use_pattern_matching, nameof(CSharpAnalyzersResources.Use_pattern_matching)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { using var _1 = PooledHashSet.GetInstance(out var declaratorLocations); using var _2 = PooledHashSet.GetInstance(out var statementParentScopes); diff --git a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpIsAndCastCheckCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpIsAndCastCheckCodeFixProvider.cs index 4b1213926ef9f..60fb0aa6f33f3 100644 --- a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpIsAndCastCheckCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpIsAndCastCheckCodeFixProvider.cs @@ -37,17 +37,13 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - CSharpAnalyzersResources.Use_pattern_matching, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(CSharpAnalyzersResources.Use_pattern_matching)), - context.Diagnostics); + RegisterCodeFix(context, CSharpAnalyzersResources.Use_pattern_matching, nameof(CSharpAnalyzersResources.Use_pattern_matching)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var diagnostic in diagnostics) { diff --git a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpUseNotPatternCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpUseNotPatternCodeFixProvider.cs index 3b8187308085c..86cc5985645d3 100644 --- a/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpUseNotPatternCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UsePatternMatching/CSharpUseNotPatternCodeFixProvider.cs @@ -34,17 +34,13 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - CSharpAnalyzersResources.Use_pattern_matching, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(CSharpAnalyzersResources.Use_pattern_matching)), - context.Diagnostics); + RegisterCodeFix(context, CSharpAnalyzersResources.Use_pattern_matching, nameof(CSharpAnalyzersResources.Use_pattern_matching)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); foreach (var diagnostic in diagnostics) diff --git a/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs index e94443b463cdd..f0598429dce0e 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseSimpleUsingStatement/UseSimpleUsingStatementCodeFixProvider.cs @@ -41,18 +41,13 @@ public UseSimpleUsingStatementCodeFixProvider() public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - CSharpAnalyzersResources.Use_simple_using_statement, - c => FixAsync(context.Document, context.Diagnostics[0], c), - nameof(CSharpAnalyzersResources.Use_simple_using_statement)), - context.Diagnostics); - + RegisterCodeFix(context, CSharpAnalyzersResources.Use_simple_using_statement, nameof(CSharpAnalyzersResources.Use_simple_using_statement)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var topmostUsingStatements = diagnostics.Select(d => (UsingStatementSyntax)d.AdditionalLocations[0].FindNode(cancellationToken)).ToSet(); var blocks = topmostUsingStatements.Select(u => (BlockSyntax)u.Parent); diff --git a/src/Analyzers/CSharp/CodeFixes/UseTupleSwap/CSharpUseTupleSwapCodeFixProvider.cs b/src/Analyzers/CSharp/CodeFixes/UseTupleSwap/CSharpUseTupleSwapCodeFixProvider.cs index fee98bf57f5af..8eb90156835fe 100644 --- a/src/Analyzers/CSharp/CodeFixes/UseTupleSwap/CSharpUseTupleSwapCodeFixProvider.cs +++ b/src/Analyzers/CSharp/CodeFixes/UseTupleSwap/CSharpUseTupleSwapCodeFixProvider.cs @@ -37,17 +37,13 @@ public CSharpUseTupleSwapCodeFixProvider() public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - CSharpAnalyzersResources.Use_tuple_to_swap_values, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(CSharpAnalyzersResources.Use_tuple_to_swap_values)), - context.Diagnostics); + RegisterCodeFix(context, CSharpAnalyzersResources.Use_tuple_to_swap_values, nameof(CSharpAnalyzersResources.Use_tuple_to_swap_values)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var diagnostic in diagnostics) FixOne(editor, diagnostic, cancellationToken); diff --git a/src/Analyzers/Core/CodeFixes/AddAccessibilityModifiers/AbstractAddAccessibilityModifiersCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/AddAccessibilityModifiers/AbstractAddAccessibilityModifiersCodeFixProvider.cs index e78fa1d48c6d9..fd8a03df386ad 100644 --- a/src/Analyzers/Core/CodeFixes/AddAccessibilityModifiers/AbstractAddAccessibilityModifiersCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/AddAccessibilityModifiers/AbstractAddAccessibilityModifiersCodeFixProvider.cs @@ -27,23 +27,18 @@ public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) { var diagnostic = context.Diagnostics.First(); -#if CODE_STYLE // 'CodeActionPriority' is not a public API, hence not supported in CodeStyle layer. - var codeAction = new MyCodeAction(c => FixAsync(context.Document, context.Diagnostics.First(), c)); -#else var priority = diagnostic.Severity == DiagnosticSeverity.Hidden ? CodeActionPriority.Low : CodeActionPriority.Medium; - var codeAction = new MyCodeAction(priority, c => FixAsync(context.Document, context.Diagnostics.First(), c)); -#endif - context.RegisterCodeFix( - codeAction, - context.Diagnostics); + + RegisterCodeFix(context, AnalyzersResources.Add_accessibility_modifiers, nameof(AnalyzersResources.Add_accessibility_modifiers), priority); + return Task.CompletedTask; } protected sealed override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); @@ -56,23 +51,5 @@ protected sealed override async Task FixAllAsync( AddAccessibilityModifiersHelpers.UpdateDeclaration(editor, symbol, declaration); } } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { -#if CODE_STYLE // 'CodeActionPriority' is not a public API, hence not supported in CodeStyle layer. - public MyCodeAction(Func> createChangedDocument) - : base(AnalyzersResources.Add_accessibility_modifiers, createChangedDocument, AnalyzersResources.Add_accessibility_modifiers) - { - } -#else - public MyCodeAction(CodeActionPriority priority, Func> createChangedDocument) - : base(AnalyzersResources.Add_accessibility_modifiers, createChangedDocument, AnalyzersResources.Add_accessibility_modifiers) - { - Priority = priority; - } - - internal override CodeActionPriority Priority { get; } -#endif - } } } diff --git a/src/Analyzers/Core/CodeFixes/AddExplicitCast/AbstractAddExplicitCastCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/AddExplicitCast/AbstractAddExplicitCastCodeFixProvider.cs index 4106d0c9f5a75..1f0a14c500007 100644 --- a/src/Analyzers/Core/CodeFixes/AddExplicitCast/AbstractAddExplicitCastCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/AddExplicitCast/AbstractAddExplicitCastCodeFixProvider.cs @@ -79,10 +79,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) if (potentialConversionTypes.Length == 1) { - context.RegisterCodeFix(new MyCodeAction( - CodeFixesResources.Add_explicit_cast, - c => FixAsync(context.Document, context.Diagnostics.First(), c)), - context.Diagnostics); + RegisterCodeFix(context, CodeFixesResources.Add_explicit_cast, nameof(CodeFixesResources.Add_explicit_cast)); return; } @@ -93,14 +90,13 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var targetNode = potentialConversionTypes[i].node; var conversionType = potentialConversionTypes[i].type; - actions.Add(new MyCodeAction( - GetSubItemName(semanticModel, targetNode.SpanStart, conversionType), - _ => Task.FromResult(document.WithSyntaxRoot(ApplyFix(root, targetNode, conversionType))))); + var title = GetSubItemName(semanticModel, targetNode.SpanStart, conversionType); + + actions.Add(CodeAction.Create(title, _ => Task.FromResult(document.WithSyntaxRoot(ApplyFix(root, targetNode, conversionType))), title)); } - context.RegisterCodeFix(CodeAction.Create( - CodeFixesResources.Add_explicit_cast, - actions.ToImmutable(), isInlinable: false), + context.RegisterCodeFix( + CodeAction.Create(CodeFixesResources.Add_explicit_cast, actions.ToImmutable(), isInlinable: false), context.Diagnostics); } @@ -153,7 +149,7 @@ protected static bool FindCorrespondingParameterByName( protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var spanNodes = diagnostics.SelectAsArray( @@ -177,13 +173,5 @@ await editor.ApplyExpressionLevelSemanticEditsAsync( }, cancellationToken).ConfigureAwait(false); } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(string title, Func> createChangedDocument) - : base(title, createChangedDocument, equivalenceKey: title) - { - } - } } } diff --git a/src/Analyzers/Core/CodeFixes/AddObsoleteAttribute/AbstractAddObsoleteAttributeCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/AddObsoleteAttribute/AbstractAddObsoleteAttributeCodeFixProvider.cs index 3c1f829ebacc3..49dd2d95100dd 100644 --- a/src/Analyzers/Core/CodeFixes/AddObsoleteAttribute/AbstractAddObsoleteAttributeCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/AddObsoleteAttribute/AbstractAddObsoleteAttributeCodeFixProvider.cs @@ -43,8 +43,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); - var diagnotic = context.Diagnostics[0]; - var node = diagnotic.Location.FindNode(cancellationToken); + var node = context.Diagnostics[0].Location.FindNode(cancellationToken); var container = GetContainer(root, node); @@ -53,11 +52,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) return; } - context.RegisterCodeFix( - new MyCodeAction( - _title, - c => FixAsync(document, diagnotic, c)), - context.Diagnostics); + RegisterCodeFix(context, _title, _title); } private static async Task GetObsoleteAttributeAsync(Document document, CancellationToken cancellationToken) @@ -75,7 +70,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var obsoleteAttribute = await GetObsoleteAttributeAsync(document, cancellationToken).ConfigureAwait(false); @@ -95,13 +90,5 @@ protected override async Task FixAllAsync( generator.Attribute(editor.Generator.TypeExpression(obsoleteAttribute))); } } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(string title, Func> createChangedDocument) - : base(title, createChangedDocument, title) - { - } - } } } diff --git a/src/Analyzers/Core/CodeFixes/AddRequiredParentheses/AddRequiredParenthesesCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/AddRequiredParentheses/AddRequiredParenthesesCodeFixProvider.cs index 56443cecd718e..b600acfcc305e 100644 --- a/src/Analyzers/Core/CodeFixes/AddRequiredParentheses/AddRequiredParenthesesCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/AddRequiredParentheses/AddRequiredParenthesesCodeFixProvider.cs @@ -38,7 +38,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) context.RegisterCodeFix( CodeAction.Create( AnalyzersResources.Add_parentheses_for_clarity, - c => FixAsync(context.Document, firstDiagnostic, c), + GetDocumentUpdater(context), firstDiagnostic.Properties[AddRequiredParenthesesConstants.EquivalenceKey]!), context.Diagnostics); return Task.CompletedTask; @@ -46,7 +46,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var generator = document.GetRequiredLanguageService(); diff --git a/src/Analyzers/Core/CodeFixes/AliasAmbiguousType/AbstractAliasAmbiguousTypeCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/AliasAmbiguousType/AbstractAliasAmbiguousTypeCodeFixProvider.cs index 415701df3c126..5e5da1d11d964 100644 --- a/src/Analyzers/Core/CodeFixes/AliasAmbiguousType/AbstractAliasAmbiguousTypeCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/AliasAmbiguousType/AbstractAliasAmbiguousTypeCodeFixProvider.cs @@ -50,13 +50,17 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) foreach (var symbol in symbolInfo.CandidateSymbols.Cast()) { var typeName = symbol.Name; - var codeActionPreviewText = GetTextPreviewOfChange(typeName, symbol); - codeActionsBuilder.Add(new MyCodeAction(codeActionPreviewText, c => + var title = GetTextPreviewOfChange(typeName, symbol); + + codeActionsBuilder.Add(CodeAction.Create( + title, + cancellationToken => { var aliasDirective = syntaxGenerator.AliasImportDeclaration(typeName, symbol); var newRoot = addImportService.AddImport(compilation, root, diagnosticNode, aliasDirective, syntaxGenerator, options, cancellationToken); return Task.FromResult(document.WithSyntaxRoot(newRoot)); - })); + }, + title)); } var groupingTitle = string.Format(CodeFixesResources.Alias_ambiguous_type_0, diagnosticNode.ToString()); @@ -72,13 +76,5 @@ private static bool SymbolCandidatesContainsSupportedSymbols(SymbolInfo symbolIn // It is unlikely that the user wants that and so generic types are not supported. symbolInfo.CandidateSymbols.All(symbol => symbol.IsKind(SymbolKind.NamedType) && symbol.GetArity() == 0); - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(string title, Func> createChangedDocument) - : base(title, createChangedDocument, equivalenceKey: title) - { - } - } } } diff --git a/src/Analyzers/Core/CodeFixes/ConvertTypeOfToNameOf/AbstractConvertTypeOfToNameOfCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/ConvertTypeOfToNameOf/AbstractConvertTypeOfToNameOfCodeFixProvider.cs index 9823450c46a1d..fda837462a8f4 100644 --- a/src/Analyzers/Core/CodeFixes/ConvertTypeOfToNameOf/AbstractConvertTypeOfToNameOfCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/ConvertTypeOfToNameOf/AbstractConvertTypeOfToNameOfCodeFixProvider.cs @@ -24,17 +24,13 @@ public sealed override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { var title = GetCodeFixTitle(); - context.RegisterCodeFix(CodeAction.Create( - title, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - title), - context.Diagnostics); + RegisterCodeFix(context, title, title); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); foreach (var diagnostic in diagnostics) diff --git a/src/Analyzers/Core/CodeFixes/FileHeaders/AbstractFileHeaderCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/FileHeaders/AbstractFileHeaderCodeFixProvider.cs index 3511c26f0ac44..46e253db0c7c7 100644 --- a/src/Analyzers/Core/CodeFixes/FileHeaders/AbstractFileHeaderCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/FileHeaders/AbstractFileHeaderCodeFixProvider.cs @@ -32,7 +32,10 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) foreach (var diagnostic in context.Diagnostics) { context.RegisterCodeFix( - new MyCodeAction(cancellationToken => GetTransformedDocumentAsync(context.Document, cancellationToken)), + CodeAction.Create( + CodeFixesResources.Add_file_header, + cancellationToken => GetTransformedDocumentAsync(context.Document, cancellationToken), + nameof(AbstractFileHeaderCodeFixProvider)), diagnostic); } @@ -229,14 +232,6 @@ private static string GetCopyrightText(string prefixWithLeadingSpaces, string co })); } - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(Func> createChangedDocument) - : base(CodeFixesResources.Add_file_header, createChangedDocument, nameof(AbstractFileHeaderCodeFixProvider)) - { - } - } - public override FixAllProvider GetFixAllProvider() => FixAllProvider.Create(async (context, document, diagnostics) => { diff --git a/src/Analyzers/Core/CodeFixes/ForEachCast/AbstractForEachCastCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/ForEachCast/AbstractForEachCastCodeFixProvider.cs index 3939f0f7aa54d..8a4ea7c389213 100644 --- a/src/Analyzers/Core/CodeFixes/ForEachCast/AbstractForEachCastCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/ForEachCast/AbstractForEachCastCodeFixProvider.cs @@ -31,9 +31,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) { if (context.Diagnostics.First().Properties.ContainsKey(ForEachCastHelpers.IsFixable)) { - context.RegisterCodeFix( - new MyCodeAction(c => FixAsync(context.Document, context.Diagnostics.First(), c)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Add_explicit_cast, nameof(AbstractForEachCastCodeFixProvider)); } return Task.CompletedTask; @@ -44,7 +42,7 @@ protected override bool IncludeDiagnosticDuringFixAll(Diagnostic diagnostic) protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var syntaxFacts = document.GetRequiredLanguageService(); var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); @@ -113,13 +111,5 @@ private SyntaxNode GetRewrittenCollection( generator.ConvertExpression(iterationVariableType, generator.IdentifierName("v")))); } } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(Func> createChangedDocument) - : base(AnalyzersResources.Add_explicit_cast, createChangedDocument, nameof(AbstractForEachCastCodeFixProvider)) - { - } - } } } diff --git a/src/Analyzers/Core/CodeFixes/Formatting/FormattingCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/Formatting/FormattingCodeFixProvider.cs index 63db16e24582c..ab823537ee676 100644 --- a/src/Analyzers/Core/CodeFixes/Formatting/FormattingCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/Formatting/FormattingCodeFixProvider.cs @@ -53,10 +53,10 @@ private async Task GetOptionsAsync(Document document, C return this.SyntaxFormatting.GetFormattingOptions(analyzerConfigOptions); } - protected override async Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) + protected override async Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { - var options = await GetOptionsAsync(document, cancellationToken).ConfigureAwait(false); - var updatedRoot = Formatter.Format(editor.OriginalRoot, SyntaxFormatting, options, cancellationToken); + var formattingOptions = await GetOptionsAsync(document, cancellationToken).ConfigureAwait(false); + var updatedRoot = Formatter.Format(editor.OriginalRoot, SyntaxFormatting, formattingOptions, cancellationToken); editor.ReplaceNode(editor.OriginalRoot, updatedRoot); } } diff --git a/src/Analyzers/Core/CodeFixes/MakeFieldReadonly/AbstractMakeFieldReadonlyCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/MakeFieldReadonly/AbstractMakeFieldReadonlyCodeFixProvider.cs index 34efa72253992..585148d8e5855 100644 --- a/src/Analyzers/Core/CodeFixes/MakeFieldReadonly/AbstractMakeFieldReadonlyCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/MakeFieldReadonly/AbstractMakeFieldReadonlyCodeFixProvider.cs @@ -31,11 +31,7 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Add_readonly_modifier, - c => FixAsync(context.Document, context.Diagnostics[0], c), - nameof(AnalyzersResources.Add_readonly_modifier)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Add_readonly_modifier, nameof(AnalyzersResources.Add_readonly_modifier)); return Task.CompletedTask; } @@ -43,7 +39,7 @@ protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, SyntaxEditor editor, - CancellationToken cancellationToken) + CodeActionOptionsProvider options, CancellationToken cancellationToken) { var declarators = new List(); var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/Analyzers/Core/CodeFixes/MakeMemberStatic/AbstractMakeMemberStaticCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/MakeMemberStatic/AbstractMakeMemberStaticCodeFixProvider.cs index f6c1a5274e06b..ccdfd0820eed2 100644 --- a/src/Analyzers/Core/CodeFixes/MakeMemberStatic/AbstractMakeMemberStaticCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/MakeMemberStatic/AbstractMakeMemberStaticCodeFixProvider.cs @@ -23,16 +23,14 @@ public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) if (context.Diagnostics.Length == 1 && TryGetMemberDeclaration(context.Diagnostics[0].Location.FindNode(context.CancellationToken), out _)) { - context.RegisterCodeFix( - new MyCodeAction(c => FixAsync(context.Document, context.Diagnostics[0], c)), - context.Diagnostics); + RegisterCodeFix(context, CodeFixesResources.Make_member_static, nameof(AbstractMakeMemberStaticCodeFixProvider)); } return Task.CompletedTask; } protected sealed override Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, - CancellationToken cancellationToken) + CodeActionOptionsProvider options, CancellationToken cancellationToken) { for (var i = 0; i < diagnostics.Length; i++) { @@ -48,13 +46,5 @@ protected sealed override Task FixAllAsync(Document document, ImmutableArray> createChangedDocument) - : base(CodeFixesResources.Make_member_static, createChangedDocument, nameof(AbstractMakeMemberStaticCodeFixProvider)) - { - } - } } } diff --git a/src/Analyzers/Core/CodeFixes/MakeTypeAbstract/AbstractMakeTypeAbstractCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/MakeTypeAbstract/AbstractMakeTypeAbstractCodeFixProvider.cs index 018df44b1963e..4c6606105d78c 100644 --- a/src/Analyzers/Core/CodeFixes/MakeTypeAbstract/AbstractMakeTypeAbstractCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/MakeTypeAbstract/AbstractMakeTypeAbstractCodeFixProvider.cs @@ -23,16 +23,14 @@ public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) { if (IsValidRefactoringContext(context.Diagnostics[0].Location?.FindNode(context.CancellationToken), out _)) { - context.RegisterCodeFix( - new MyCodeAction(c => FixAsync(context.Document, context.Diagnostics[0], c)), - context.Diagnostics); + RegisterCodeFix(context, CodeFixesResources.Make_class_abstract, CodeFixesResources.Make_class_abstract); } return Task.CompletedTask; } protected sealed override Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, - CancellationToken cancellationToken) + CodeActionOptionsProvider options, CancellationToken cancellationToken) { for (var i = 0; i < diagnostics.Length; i++) { @@ -45,13 +43,5 @@ protected sealed override Task FixAllAsync(Document document, ImmutableArray> createChangedDocument) - : base(CodeFixesResources.Make_class_abstract, createChangedDocument, CodeFixesResources.Make_class_abstract) - { - } - } } } diff --git a/src/Analyzers/Core/CodeFixes/OrderModifiers/AbstractOrderModifiersCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/OrderModifiers/AbstractOrderModifiersCodeFixProvider.cs index 5735859aa0ed1..6501c4e91dde2 100644 --- a/src/Analyzers/Core/CodeFixes/OrderModifiers/AbstractOrderModifiersCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/OrderModifiers/AbstractOrderModifiersCodeFixProvider.cs @@ -47,17 +47,12 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) if (_syntaxFacts.GetModifiers(syntaxNode) != default) { - context.RegisterCodeFix( - CodeAction.Create( - AnalyzersResources.Order_modifiers, - c => FixAsync(context.Document, context.Diagnostics[0], c), - nameof(AnalyzersResources.Order_modifiers)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Order_modifiers, nameof(AnalyzersResources.Order_modifiers)); } } protected override async Task FixAllAsync( - Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) + Document document, ImmutableArray diagnostics, SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var tree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var option = document.Project.AnalyzerOptions.GetOption(_option, tree, cancellationToken); diff --git a/src/Analyzers/Core/CodeFixes/PopulateSwitch/AbstractPopulateSwitchCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/PopulateSwitch/AbstractPopulateSwitchCodeFixProvider.cs index 038ed1a403f0a..801c1db714d71 100644 --- a/src/Analyzers/Core/CodeFixes/PopulateSwitch/AbstractPopulateSwitchCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/PopulateSwitch/AbstractPopulateSwitchCodeFixProvider.cs @@ -208,7 +208,7 @@ protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, SyntaxEditor editor, - CancellationToken cancellationToken) + CodeActionOptionsProvider options, CancellationToken cancellationToken) { // If the user is performing a fix-all, then fix up all the issues we see. i.e. // add missing cases and missing 'default' cases for any switches we reported an diff --git a/src/Analyzers/Core/CodeFixes/QualifyMemberAccess/AbstractQualifyMemberAccessCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/QualifyMemberAccess/AbstractQualifyMemberAccessCodeFixProvider.cs index 33e79e73ada4e..30b912a1be580 100644 --- a/src/Analyzers/Core/CodeFixes/QualifyMemberAccess/AbstractQualifyMemberAccessCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/QualifyMemberAccess/AbstractQualifyMemberAccessCodeFixProvider.cs @@ -27,17 +27,13 @@ public sealed override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { var title = GetTitle(); - context.RegisterCodeFix(CodeAction.Create( - title, - c => FixAsync(context.Document, context.Diagnostics[0], c), - title), - context.Diagnostics); + RegisterCodeFix(context, title, title); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var generator = document.GetRequiredLanguageService(); diff --git a/src/Analyzers/Core/CodeFixes/RemoveRedundantEquality/RemoveRedundantEqualityCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/RemoveRedundantEquality/RemoveRedundantEqualityCodeFixProvider.cs index 474df681d96a5..e97f725038fcf 100644 --- a/src/Analyzers/Core/CodeFixes/RemoveRedundantEquality/RemoveRedundantEqualityCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/RemoveRedundantEquality/RemoveRedundantEqualityCodeFixProvider.cs @@ -34,17 +34,13 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) { foreach (var diagnostic in context.Diagnostics) { - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Remove_redundant_equality, - c => FixAsync(context.Document, diagnostic, c), - nameof(AnalyzersResources.Remove_redundant_equality)), - diagnostic); + RegisterCodeFix(context, AnalyzersResources.Remove_redundant_equality, nameof(AnalyzersResources.Remove_redundant_equality), diagnostic); } return Task.CompletedTask; } - protected override async Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) + protected override async Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var syntaxFacts = document.GetRequiredLanguageService(); diff --git a/src/Analyzers/Core/CodeFixes/RemoveUnnecessaryParentheses/AbstractRemoveUnnecessaryParenthesesCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/RemoveUnnecessaryParentheses/AbstractRemoveUnnecessaryParenthesesCodeFixProvider.cs index 9b41661db9e06..d31e59e35d495 100644 --- a/src/Analyzers/Core/CodeFixes/RemoveUnnecessaryParentheses/AbstractRemoveUnnecessaryParenthesesCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/RemoveUnnecessaryParentheses/AbstractRemoveUnnecessaryParenthesesCodeFixProvider.cs @@ -27,18 +27,13 @@ protected abstract bool CanRemoveParentheses( public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix( - CodeAction.Create( - AnalyzersResources.Remove_unnecessary_parentheses, - c => FixAsync(context.Document, context.Diagnostics[0], c), - nameof(AnalyzersResources.Remove_unnecessary_parentheses)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Remove_unnecessary_parentheses, nameof(AnalyzersResources.Remove_unnecessary_parentheses)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var syntaxFacts = document.GetRequiredLanguageService(); var originalNodes = diagnostics.SelectAsArray( diff --git a/src/Analyzers/Core/CodeFixes/RemoveUnnecessarySuppressions/RemoveUnnecessaryAttributeSuppressionsCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/RemoveUnnecessarySuppressions/RemoveUnnecessaryAttributeSuppressionsCodeFixProvider.cs index fe01682012524..bf5f11a499782 100644 --- a/src/Analyzers/Core/CodeFixes/RemoveUnnecessarySuppressions/RemoveUnnecessaryAttributeSuppressionsCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/RemoveUnnecessarySuppressions/RemoveUnnecessaryAttributeSuppressionsCodeFixProvider.cs @@ -36,17 +36,12 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) // Register code fix with a defensive check if (root.FindNode(diagnostic.Location.SourceSpan) != null) { - context.RegisterCodeFix( - CodeAction.Create( - AnalyzersResources.Remove_unnecessary_suppression, - c => FixAsync(context.Document, diagnostic, c), - nameof(AnalyzersResources.Remove_unnecessary_suppression)), - diagnostic); + RegisterCodeFix(context, AnalyzersResources.Remove_unnecessary_suppression, nameof(AnalyzersResources.Remove_unnecessary_suppression)); } } } - protected override Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) + protected override Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var diagnostic in diagnostics) { diff --git a/src/Analyzers/Core/CodeFixes/RemoveUnnecessarySuppressions/RemoveUnnecessaryPragmaSuppressionsCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/RemoveUnnecessarySuppressions/RemoveUnnecessaryPragmaSuppressionsCodeFixProvider.cs index fa6d04b3c766a..afc5940528cd8 100644 --- a/src/Analyzers/Core/CodeFixes/RemoveUnnecessarySuppressions/RemoveUnnecessaryPragmaSuppressionsCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/RemoveUnnecessarySuppressions/RemoveUnnecessaryPragmaSuppressionsCodeFixProvider.cs @@ -43,17 +43,12 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) if (root.FindNode(diagnostic.Location.SourceSpan) is { } node && syntaxFacts.IsAttribute(node) || root.FindTrivia(diagnostic.Location.SourceSpan.Start).HasStructure) { - context.RegisterCodeFix( - CodeAction.Create( - AnalyzersResources.Remove_unnecessary_suppression, - c => FixAsync(context.Document, diagnostic, c), - nameof(AnalyzersResources.Remove_unnecessary_suppression)), - diagnostic); + RegisterCodeFix(context, AnalyzersResources.Remove_unnecessary_suppression, nameof(AnalyzersResources.Remove_unnecessary_suppression)); } } } - protected override Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) + protected override Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { // We need to track unique set of processed nodes when removing the nodes. // This is because we generate an unnecessary pragma suppression diagnostic at both the pragma disable and matching pragma restore location diff --git a/src/Analyzers/Core/CodeFixes/RemoveUnusedMembers/AbstractRemoveUnusedMembersCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/RemoveUnusedMembers/AbstractRemoveUnusedMembersCodeFixProvider.cs index 4d0c70b9a05a2..8854e4f26e2c7 100644 --- a/src/Analyzers/Core/CodeFixes/RemoveUnusedMembers/AbstractRemoveUnusedMembersCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/RemoveUnusedMembers/AbstractRemoveUnusedMembersCodeFixProvider.cs @@ -35,11 +35,7 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Remove_unused_member, - c => FixAsync(context.Document, context.Diagnostics[0], c), - nameof(AnalyzersResources.Remove_unused_member)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Remove_unused_member, nameof(AnalyzersResources.Remove_unused_member)); return Task.CompletedTask; } @@ -47,7 +43,7 @@ protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, SyntaxEditor editor, - CancellationToken cancellationToken) + CodeActionOptionsProvider options, CancellationToken cancellationToken) { var declarators = new HashSet(); var fieldDeclarators = new HashSet(); diff --git a/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs index 43e8ff775663b..eb3891c59ccd2 100644 --- a/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/RemoveUnusedParametersAndValues/AbstractRemoveUnusedValuesCodeFixProvider.cs @@ -173,13 +173,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) } } - context.RegisterCodeFix( - CodeAction.Create( - title, - c => FixAsync(context.Document, diagnostic, c), - equivalenceKey: GetEquivalenceKey(preference, isRemovableAssignment)), - diagnostic); - + RegisterCodeFix(context, title, GetEquivalenceKey(preference, isRemovableAssignment)); return; } @@ -264,17 +258,17 @@ private static async Task PreprocessDocumentAsync(Document document, I return document.WithSyntaxRoot(root); } - protected sealed override async Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) + protected sealed override async Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { #if CODE_STYLE var provider = GetSyntaxFormatting(); - var options = provider.GetFormattingOptions(document.Project.AnalyzerOptions.GetAnalyzerOptionSet(editor.OriginalRoot.SyntaxTree, cancellationToken)); + var formattingOptions = provider.GetFormattingOptions(document.Project.AnalyzerOptions.GetAnalyzerOptionSet(editor.OriginalRoot.SyntaxTree, cancellationToken)); #else var provider = document.Project.Solution.Workspace.Services; - var options = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); + var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); #endif var preprocessedDocument = await PreprocessDocumentAsync(document, diagnostics, cancellationToken).ConfigureAwait(false); - var newRoot = await GetNewRootAsync(preprocessedDocument, options, diagnostics, cancellationToken).ConfigureAwait(false); + var newRoot = await GetNewRootAsync(preprocessedDocument, formattingOptions, diagnostics, cancellationToken).ConfigureAwait(false); editor.ReplaceNode(editor.OriginalRoot, newRoot); } diff --git a/src/Analyzers/Core/CodeFixes/SimplifyBooleanExpression/SimplifyConditionalCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/SimplifyBooleanExpression/SimplifyConditionalCodeFixProvider.cs index 6fe02c126c449..ce1432994f4c6 100644 --- a/src/Analyzers/Core/CodeFixes/SimplifyBooleanExpression/SimplifyConditionalCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/SimplifyBooleanExpression/SimplifyConditionalCodeFixProvider.cs @@ -34,18 +34,13 @@ public SimplifyConditionalCodeFixProvider() public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Simplify_conditional_expression, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(AnalyzersResources.Simplify_conditional_expression)), - context.Diagnostics); - + RegisterCodeFix(context, AnalyzersResources.Simplify_conditional_expression, nameof(AnalyzersResources.Simplify_conditional_expression)); return Task.CompletedTask; } protected sealed override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var generator = SyntaxGenerator.GetGenerator(document); var generatorInternal = document.GetRequiredLanguageService(); diff --git a/src/Analyzers/Core/CodeFixes/SimplifyInterpolation/AbstractSimplifyInterpolationCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/SimplifyInterpolation/AbstractSimplifyInterpolationCodeFixProvider.cs index ad547210dd073..ba31f41c825b6 100644 --- a/src/Analyzers/Core/CodeFixes/SimplifyInterpolation/AbstractSimplifyInterpolationCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/SimplifyInterpolation/AbstractSimplifyInterpolationCodeFixProvider.cs @@ -42,17 +42,13 @@ internal abstract class AbstractSimplifyInterpolationCodeFixProvider< public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Simplify_interpolation, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(AnalyzersResources.Simplify_interpolation)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Simplify_interpolation, nameof(AnalyzersResources.Simplify_interpolation)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); var generator = editor.Generator; diff --git a/src/Analyzers/Core/CodeFixes/SimplifyLinqExpression/AbstractSimplifyLinqExpressionCodeFixProvider`3.cs b/src/Analyzers/Core/CodeFixes/SimplifyLinqExpression/AbstractSimplifyLinqExpressionCodeFixProvider`3.cs index d805ed1b800c2..48b7e91a31f1e 100644 --- a/src/Analyzers/Core/CodeFixes/SimplifyLinqExpression/AbstractSimplifyLinqExpressionCodeFixProvider`3.cs +++ b/src/Analyzers/Core/CodeFixes/SimplifyLinqExpression/AbstractSimplifyLinqExpressionCodeFixProvider`3.cs @@ -27,18 +27,14 @@ public sealed override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Simplify_LINQ_expression, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(AnalyzersResources.Simplify_LINQ_expression)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Simplify_LINQ_expression, nameof(AnalyzersResources.Simplify_LINQ_expression)); return Task.CompletedTask; } protected override Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, - CancellationToken cancellationToken) + CodeActionOptionsProvider options, CancellationToken cancellationToken) { var root = editor.OriginalRoot; var expressionsToReWrite = diagnostics.Select(d => GetInvocation(root, d)).OrderByDescending(i => i.SpanStart); diff --git a/src/Analyzers/Core/CodeFixes/UpdateLegacySuppressions/UpdateLegacySuppressionsCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UpdateLegacySuppressions/UpdateLegacySuppressionsCodeFixProvider.cs index fd66179626dda..36e571d9f14f0 100644 --- a/src/Analyzers/Core/CodeFixes/UpdateLegacySuppressions/UpdateLegacySuppressionsCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UpdateLegacySuppressions/UpdateLegacySuppressionsCodeFixProvider.cs @@ -37,17 +37,12 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) if (diagnostic.Properties?.ContainsKey(AbstractRemoveUnnecessaryAttributeSuppressionsDiagnosticAnalyzer.DocCommentIdKey) == true && root.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie: true) != null) { - context.RegisterCodeFix( - CodeAction.Create( - CodeFixesResources.Update_suppression_format, - c => FixAsync(context.Document, diagnostic, c), - nameof(CodeFixesResources.Update_suppression_format)), - diagnostic); + RegisterCodeFix(context, CodeFixesResources.Update_suppression_format, nameof(CodeFixesResources.Update_suppression_format)); } } } - protected override Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) + protected override Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var diagnostic in diagnostics) { diff --git a/src/Analyzers/Core/CodeFixes/UseCoalesceExpression/UseCoalesceExpressionCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseCoalesceExpression/UseCoalesceExpressionCodeFixProvider.cs index 0689afde32485..cb0a931b132d3 100644 --- a/src/Analyzers/Core/CodeFixes/UseCoalesceExpression/UseCoalesceExpressionCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseCoalesceExpression/UseCoalesceExpressionCodeFixProvider.cs @@ -35,17 +35,13 @@ protected override bool IncludeDiagnosticDuringFixAll(Diagnostic diagnostic) public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Use_coalesce_expression, - c => FixAsync(context.Document, context.Diagnostics[0], c), - nameof(AnalyzersResources.Use_coalesce_expression)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Use_coalesce_expression, nameof(AnalyzersResources.Use_coalesce_expression)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); var expressionTypeOpt = semanticModel.Compilation.ExpressionOfTType(); diff --git a/src/Analyzers/Core/CodeFixes/UseCoalesceExpression/UseCoalesceExpressionForNullableCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseCoalesceExpression/UseCoalesceExpressionForNullableCodeFixProvider.cs index 5b06b8388e778..512d34cc9b2f1 100644 --- a/src/Analyzers/Core/CodeFixes/UseCoalesceExpression/UseCoalesceExpressionForNullableCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseCoalesceExpression/UseCoalesceExpressionForNullableCodeFixProvider.cs @@ -34,17 +34,13 @@ protected override bool IncludeDiagnosticDuringFixAll(Diagnostic diagnostic) public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Use_coalesce_expression, - c => FixAsync(context.Document, context.Diagnostics[0], c), - nameof(AnalyzersResources.Use_coalesce_expression)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Use_coalesce_expression, nameof(AnalyzersResources.Use_coalesce_expression)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); var expressionTypeOpt = semanticModel.Compilation.ExpressionOfTType(); diff --git a/src/Analyzers/Core/CodeFixes/UseCollectionInitializer/AbstractUseCollectionInitializerCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseCollectionInitializer/AbstractUseCollectionInitializerCodeFixProvider.cs index 02bb361d6cb05..7b22d9c6de012 100644 --- a/src/Analyzers/Core/CodeFixes/UseCollectionInitializer/AbstractUseCollectionInitializerCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseCollectionInitializer/AbstractUseCollectionInitializerCodeFixProvider.cs @@ -46,18 +46,13 @@ protected override bool IncludeDiagnosticDuringFixAll(Diagnostic diagnostic) public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix( - CodeAction.Create( - AnalyzersResources.Collection_initialization_can_be_simplified, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(AnalyzersResources.Collection_initialization_can_be_simplified)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Collection_initialization_can_be_simplified, nameof(AnalyzersResources.Collection_initialization_can_be_simplified)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { // Fix-All for this feature is somewhat complicated. As Collection-Initializers // could be arbitrarily nested, we have to make sure that any edits we make diff --git a/src/Analyzers/Core/CodeFixes/UseCompoundAssignment/AbstractUseCompoundAssignmentCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseCompoundAssignment/AbstractUseCompoundAssignmentCodeFixProvider.cs index aef3555b02d3d..c2c0f73f918cc 100644 --- a/src/Analyzers/Core/CodeFixes/UseCompoundAssignment/AbstractUseCompoundAssignmentCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseCompoundAssignment/AbstractUseCompoundAssignmentCodeFixProvider.cs @@ -45,21 +45,13 @@ protected abstract TAssignmentSyntax Assignment( public override Task RegisterCodeFixesAsync(CodeFixContext context) { - var document = context.Document; - var diagnostic = context.Diagnostics[0]; - - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Use_compound_assignment, - c => FixAsync(document, diagnostic, c), - nameof(AnalyzersResources.Use_compound_assignment)), - context.Diagnostics); - + RegisterCodeFix(context, AnalyzersResources.Use_compound_assignment, nameof(AnalyzersResources.Use_compound_assignment)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var syntaxFacts = document.GetRequiredLanguageService(); var syntaxKinds = syntaxFacts.SyntaxKinds; diff --git a/src/Analyzers/Core/CodeFixes/UseConditionalExpression/AbstractUseConditionalExpressionCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseConditionalExpression/AbstractUseConditionalExpressionCodeFixProvider.cs index 4732c77cee13d..8c9923bfb14d1 100644 --- a/src/Analyzers/Core/CodeFixes/UseConditionalExpression/AbstractUseConditionalExpressionCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseConditionalExpression/AbstractUseConditionalExpressionCodeFixProvider.cs @@ -6,6 +6,7 @@ using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; +using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editing; @@ -51,7 +52,7 @@ protected abstract Task FixOneAsync( protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, SyntaxEditor editor, - CancellationToken cancellationToken) + CodeActionOptionsProvider options, CancellationToken cancellationToken) { var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); @@ -76,12 +77,12 @@ await FixOneAsync( #if CODE_STYLE var provider = GetSyntaxFormatting(); - var options = provider.GetFormattingOptions(document.Project.AnalyzerOptions.GetAnalyzerOptionSet(root.SyntaxTree, cancellationToken)); + var formattingOptions = provider.GetFormattingOptions(document.Project.AnalyzerOptions.GetAnalyzerOptionSet(root.SyntaxTree, cancellationToken)); #else var provider = document.Project.Solution.Workspace.Services; - var options = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); + var formattingOptions = await SyntaxFormattingOptions.FromDocumentAsync(document, cancellationToken).ConfigureAwait(false); #endif - var formattedRoot = Formatter.Format(changedRoot, SpecializedFormattingAnnotation, provider, options, rules, cancellationToken); + var formattedRoot = Formatter.Format(changedRoot, SpecializedFormattingAnnotation, provider, formattingOptions, rules, cancellationToken); changedRoot = formattedRoot; diff --git a/src/Analyzers/Core/CodeFixes/UseConditionalExpression/ForAssignment/AbstractUseConditionalExpressionForAssignmentCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseConditionalExpression/ForAssignment/AbstractUseConditionalExpressionForAssignmentCodeFixProvider.cs index f3f6fec3ca341..b6384b2fb5506 100644 --- a/src/Analyzers/Core/CodeFixes/UseConditionalExpression/ForAssignment/AbstractUseConditionalExpressionForAssignmentCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseConditionalExpression/ForAssignment/AbstractUseConditionalExpressionForAssignmentCodeFixProvider.cs @@ -45,12 +45,7 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix( - CodeAction.Create( - AnalyzersResources.Convert_to_conditional_expression, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(AnalyzersResources.Convert_to_conditional_expression)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Convert_to_conditional_expression, nameof(AnalyzersResources.Convert_to_conditional_expression)); return Task.CompletedTask; } diff --git a/src/Analyzers/Core/CodeFixes/UseConditionalExpression/ForReturn/AbstractUseConditionalExpressionForReturnCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseConditionalExpression/ForReturn/AbstractUseConditionalExpressionForReturnCodeFixProvider.cs index 562e575fd11e2..8996271183b81 100644 --- a/src/Analyzers/Core/CodeFixes/UseConditionalExpression/ForReturn/AbstractUseConditionalExpressionForReturnCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseConditionalExpression/ForReturn/AbstractUseConditionalExpressionForReturnCodeFixProvider.cs @@ -35,12 +35,7 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix( - CodeAction.Create( - AnalyzersResources.Convert_to_conditional_expression, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(AnalyzersResources.Convert_to_conditional_expression)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Convert_to_conditional_expression, nameof(AnalyzersResources.Convert_to_conditional_expression)); return Task.CompletedTask; } diff --git a/src/Analyzers/Core/CodeFixes/UseExplicitTupleName/UseExplicitTupleNameCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseExplicitTupleName/UseExplicitTupleNameCodeFixProvider.cs index 219d6bca92b9b..31d939e193ae5 100644 --- a/src/Analyzers/Core/CodeFixes/UseExplicitTupleName/UseExplicitTupleNameCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseExplicitTupleName/UseExplicitTupleNameCodeFixProvider.cs @@ -31,17 +31,13 @@ public UseExplicitTupleNameCodeFixProvider() public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Use_explicitly_provided_tuple_name, - c => FixAsync(context.Document, context.Diagnostics[0], c), - nameof(AnalyzersResources.Use_explicitly_provided_tuple_name)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Use_explicitly_provided_tuple_name, nameof(AnalyzersResources.Use_explicitly_provided_tuple_name)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var generator = editor.Generator; diff --git a/src/Analyzers/Core/CodeFixes/UseInferredMemberName/AbstractUseInferredMemberNameCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseInferredMemberName/AbstractUseInferredMemberNameCodeFixProvider.cs index aaaff6fb33f22..476fdab92796b 100644 --- a/src/Analyzers/Core/CodeFixes/UseInferredMemberName/AbstractUseInferredMemberNameCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseInferredMemberName/AbstractUseInferredMemberNameCodeFixProvider.cs @@ -24,18 +24,13 @@ internal abstract class AbstractUseInferredMemberNameCodeFixProvider : SyntaxEdi public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Use_inferred_member_name, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(AnalyzersResources.Use_inferred_member_name)), - context.Diagnostics); - + RegisterCodeFix(context, AnalyzersResources.Use_inferred_member_name, nameof(AnalyzersResources.Use_inferred_member_name)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var root = editor.OriginalRoot; diff --git a/src/Analyzers/Core/CodeFixes/UseIsNullCheck/AbstractUseIsNullForReferenceEqualsCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseIsNullCheck/AbstractUseIsNullForReferenceEqualsCodeFixProvider.cs index fab044b1c660a..a924d28920048 100644 --- a/src/Analyzers/Core/CodeFixes/UseIsNullCheck/AbstractUseIsNullForReferenceEqualsCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseIsNullCheck/AbstractUseIsNullForReferenceEqualsCodeFixProvider.cs @@ -40,7 +40,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) var negated = diagnostic.Properties.ContainsKey(UseIsNullConstants.Negated); var title = GetTitle(negated, diagnostic.Location.SourceTree!.Options); context.RegisterCodeFix( - CodeAction.Create(title, c => FixAsync(context.Document, diagnostic, c), title), + CodeAction.Create(title, GetDocumentUpdater(context), title), context.Diagnostics); } @@ -49,7 +49,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var syntaxFacts = document.GetRequiredLanguageService(); diff --git a/src/Analyzers/Core/CodeFixes/UseNullPropagation/AbstractUseNullPropagationCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseNullPropagation/AbstractUseNullPropagationCodeFixProvider.cs index 978708bd76f77..baf49b9c707d8 100644 --- a/src/Analyzers/Core/CodeFixes/UseNullPropagation/AbstractUseNullPropagationCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseNullPropagation/AbstractUseNullPropagationCodeFixProvider.cs @@ -50,17 +50,13 @@ protected override bool IncludeDiagnosticDuringFixAll(Diagnostic diagnostic) public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Use_null_propagation, - c => FixAsync(context.Document, context.Diagnostics[0], c), - nameof(AnalyzersResources.Use_null_propagation)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Use_null_propagation, nameof(AnalyzersResources.Use_null_propagation)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var syntaxFacts = document.GetRequiredLanguageService(); var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/Analyzers/Core/CodeFixes/UseObjectInitializer/AbstractUseObjectInitializerCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseObjectInitializer/AbstractUseObjectInitializerCodeFixProvider.cs index 995d11fe20ff0..f9d0f000f87a2 100644 --- a/src/Analyzers/Core/CodeFixes/UseObjectInitializer/AbstractUseObjectInitializerCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseObjectInitializer/AbstractUseObjectInitializerCodeFixProvider.cs @@ -44,18 +44,13 @@ protected override bool IncludeDiagnosticDuringFixAll(Diagnostic diagnostic) public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix( - CodeAction.Create( - AnalyzersResources.Object_initialization_can_be_simplified, - c => FixAsync(context.Document, context.Diagnostics.First(), c), - nameof(AnalyzersResources.Object_initialization_can_be_simplified)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Object_initialization_can_be_simplified, nameof(AnalyzersResources.Object_initialization_can_be_simplified)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { // Fix-All for this feature is somewhat complicated. As Object-Initializers // could be arbitrarily nested, we have to make sure that any edits we make diff --git a/src/Analyzers/Core/CodeFixes/UseSystemHashCode/UseSystemHashCodeCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseSystemHashCode/UseSystemHashCodeCodeFixProvider.cs index f66e81ab9ce90..ed5c7b1cb0854 100644 --- a/src/Analyzers/Core/CodeFixes/UseSystemHashCode/UseSystemHashCodeCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseSystemHashCode/UseSystemHashCodeCodeFixProvider.cs @@ -32,20 +32,13 @@ public UseSystemHashCodeCodeFixProvider() public override Task RegisterCodeFixesAsync(CodeFixContext context) { - var document = context.Document; - var diagnostic = context.Diagnostics[0]; - - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Use_System_HashCode, - c => FixAsync(document, diagnostic, c), - nameof(AnalyzersResources.Use_System_HashCode)), - context.Diagnostics); + RegisterCodeFix(context, AnalyzersResources.Use_System_HashCode, nameof(AnalyzersResources.Use_System_HashCode)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var generator = SyntaxGenerator.GetGenerator(document); var generatorInternal = document.GetRequiredLanguageService(); diff --git a/src/Analyzers/Core/CodeFixes/UseThrowExpression/UseThrowExpressionCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/UseThrowExpression/UseThrowExpressionCodeFixProvider.cs index 6a2389942d921..8a1ded51783ad 100644 --- a/src/Analyzers/Core/CodeFixes/UseThrowExpression/UseThrowExpressionCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/UseThrowExpression/UseThrowExpressionCodeFixProvider.cs @@ -36,20 +36,13 @@ protected override bool IncludeDiagnosticDuringFixAll(Diagnostic diagnostic) public override Task RegisterCodeFixesAsync(CodeFixContext context) { - var diagnostic = context.Diagnostics.First(); - context.RegisterCodeFix( - CodeAction.Create( - AnalyzersResources.Use_throw_expression, - c => FixAsync(context.Document, diagnostic, c), - nameof(AnalyzersResources.Use_throw_expression)), - diagnostic); - + RegisterCodeFix(context, AnalyzersResources.Use_throw_expression, nameof(AnalyzersResources.Use_throw_expression)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var generator = editor.Generator; var root = editor.OriginalRoot; diff --git a/src/Analyzers/VisualBasic/CodeFixes/Iterator/VisualBasicChangeToYieldCodeFixProvider.vb b/src/Analyzers/VisualBasic/CodeFixes/Iterator/VisualBasicChangeToYieldCodeFixProvider.vb index 17be22a9ab349..16e5d989aaebc 100644 --- a/src/Analyzers/VisualBasic/CodeFixes/Iterator/VisualBasicChangeToYieldCodeFixProvider.vb +++ b/src/Analyzers/VisualBasic/CodeFixes/Iterator/VisualBasicChangeToYieldCodeFixProvider.vb @@ -43,16 +43,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.Iterator root = root.ReplaceNode(returnStatement, yieldStatement) - Return Task.FromResult(Of CodeAction)(New MyCodeAction(document.WithSyntaxRoot(root))) + Return Task.FromResult( + CodeAction.Create( + VisualBasicCodeFixesResources.Replace_Return_with_Yield, + Function(c) Task.FromResult(document.WithSyntaxRoot(root)), + NameOf(VisualBasicCodeFixesResources.Replace_Return_with_Yield))) End Function - - Private Class MyCodeAction - Inherits CustomCodeActions.DocumentChangeAction - - Public Sub New(newDocument As Document) - MyBase.New(VisualBasicCodeFixesResources.Replace_Return_with_Yield, Function(c) Task.FromResult(newDocument), NameOf(VisualBasicCodeFixesResources.Replace_Return_with_Yield)) - End Sub - End Class End Class End Namespace diff --git a/src/Analyzers/VisualBasic/CodeFixes/Iterator/VisualBasicConvertToIteratorCodeFixProvider.vb b/src/Analyzers/VisualBasic/CodeFixes/Iterator/VisualBasicConvertToIteratorCodeFixProvider.vb index 25db980a3388e..8186d643a3ccc 100644 --- a/src/Analyzers/VisualBasic/CodeFixes/Iterator/VisualBasicConvertToIteratorCodeFixProvider.vb +++ b/src/Analyzers/VisualBasic/CodeFixes/Iterator/VisualBasicConvertToIteratorCodeFixProvider.vb @@ -90,17 +90,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.Iterator Dim methodStatementNode = TryCast(methodNode, MethodStatementSyntax) If methodStatementNode IsNot Nothing AndAlso Not methodStatementNode.Modifiers.Any(SyntaxKind.IteratorKeyword) Then root = AddIteratorKeywordToMethod(root, methodStatementNode) - Return New MyCodeAction( - String.Format(VisualBasicCodeFixesResources.Convert_0_to_Iterator, methodStatementNode.Identifier), - document.WithSyntaxRoot(root)) + + Dim title = String.Format(VisualBasicCodeFixesResources.Convert_0_to_Iterator, methodStatementNode.Identifier) + Return CodeAction.Create(title, Function(c) Task.FromResult(document.WithSyntaxRoot(root)), title) End If Case SyntaxKind.MultiLineFunctionLambdaExpression Dim lambdaNode = TryCast(methodNode, LambdaExpressionSyntax) If lambdaNode IsNot Nothing AndAlso Not lambdaNode.SubOrFunctionHeader.Modifiers.Any(SyntaxKind.IteratorKeyword) Then root = AddIteratorKeywordToLambda(root, lambdaNode) - Return New MyCodeAction( - String.Format(VisualBasicCodeFixesResources.Convert_0_to_Iterator, lambdaNode.SubOrFunctionHeader.GetTypeDisplayName()), - document.WithSyntaxRoot(root)) + Dim title = String.Format(VisualBasicCodeFixesResources.Convert_0_to_Iterator, lambdaNode.SubOrFunctionHeader.GetTypeDisplayName()) + + Return CodeAction.Create(title, Function(c) Task.FromResult(document.WithSyntaxRoot(root)), title) End If Case Else End Select @@ -135,14 +135,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.Iterator Return root.ReplaceNode(lambdaNode.SubOrFunctionHeader, newHeader) End Function - - Private Class MyCodeAction - Inherits CustomCodeActions.DocumentChangeAction - - Public Sub New(title As String, newDocument As Document) - MyBase.New(title, Function(c) Task.FromResult(newDocument), title) - End Sub - End Class End Class End Namespace diff --git a/src/Analyzers/VisualBasic/CodeFixes/RemoveUnnecessaryByVal/VisualBasicRemoveUnnecessaryByValCodeFixProvider.vb b/src/Analyzers/VisualBasic/CodeFixes/RemoveUnnecessaryByVal/VisualBasicRemoveUnnecessaryByValCodeFixProvider.vb index eeedb4434f1b4..a2d4b37e95ffa 100644 --- a/src/Analyzers/VisualBasic/CodeFixes/RemoveUnnecessaryByVal/VisualBasicRemoveUnnecessaryByValCodeFixProvider.vb +++ b/src/Analyzers/VisualBasic/CodeFixes/RemoveUnnecessaryByVal/VisualBasicRemoveUnnecessaryByValCodeFixProvider.vb @@ -28,17 +28,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveUnnecessaryByVal Public Overrides Function RegisterCodeFixesAsync(context As CodeFixContext) As Task For Each diagnostic In context.Diagnostics - context.RegisterCodeFix(CodeAction.Create( - VisualBasicAnalyzersResources.Remove_ByVal, - Function(ct) FixAsync(context.Document, diagnostic, ct), - NameOf(VisualBasicAnalyzersResources.Remove_ByVal)), - diagnostic) + RegisterCodeFix(context, VisualBasicAnalyzersResources.Remove_ByVal, NameOf(VisualBasicAnalyzersResources.Remove_ByVal), diagnostic) Next Return Task.CompletedTask End Function - Protected Overrides Async Function FixAllAsync(document As Document, diagnostics As ImmutableArray(Of Diagnostic), editor As SyntaxEditor, cancellationToken As CancellationToken) As Task + Protected Overrides Async Function FixAllAsync(document As Document, diagnostics As ImmutableArray(Of Diagnostic), editor As SyntaxEditor, options As CodeActionOptionsProvider, cancellationToken As CancellationToken) As Task Dim root = Await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(False) For Each diagnostic In diagnostics Dim node = DirectCast(root.FindNode(diagnostic.AdditionalLocations(0).SourceSpan), ParameterSyntax) diff --git a/src/Analyzers/VisualBasic/CodeFixes/RemoveUnnecessaryCast/VisualBasicRemoveUnnecessaryCastCodeFixProvider.vb b/src/Analyzers/VisualBasic/CodeFixes/RemoveUnnecessaryCast/VisualBasicRemoveUnnecessaryCastCodeFixProvider.vb index cac1c5ffb91ce..e547d816a8909 100644 --- a/src/Analyzers/VisualBasic/CodeFixes/RemoveUnnecessaryCast/VisualBasicRemoveUnnecessaryCastCodeFixProvider.vb +++ b/src/Analyzers/VisualBasic/CodeFixes/RemoveUnnecessaryCast/VisualBasicRemoveUnnecessaryCastCodeFixProvider.vb @@ -31,11 +31,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveUnnecessaryCast ImmutableArray.Create(IDEDiagnosticIds.RemoveUnnecessaryCastDiagnosticId) Public Overrides Function RegisterCodeFixesAsync(context As CodeFixContext) As Task - context.RegisterCodeFix(CodeAction.Create( - AnalyzersResources.Remove_Unnecessary_Cast, - Function(c) FixAsync(context.Document, context.Diagnostics.First(), c), - NameOf(AnalyzersResources.Remove_Unnecessary_Cast)), - context.Diagnostics) + RegisterCodeFix(context, AnalyzersResources.Remove_Unnecessary_Cast, NameOf(AnalyzersResources.Remove_Unnecessary_Cast)) Return Task.CompletedTask End Function @@ -54,8 +50,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveUnnecessaryCast End Function Protected Overrides Async Function FixAllAsync( - document As Document, diagnostics As ImmutableArray(Of Diagnostic), - editor As SyntaxEditor, cancellationToken As CancellationToken) As Task + document As Document, + diagnostics As ImmutableArray(Of Diagnostic), + editor As SyntaxEditor, + options As CodeActionOptionsProvider, + cancellationToken As CancellationToken) As Task ' VB parsing is extremely hairy. Unlike C#, it can be very dangerous to go and remove a ' cast. For example, if the cast is at the statement level, it may contain an diff --git a/src/Analyzers/VisualBasic/CodeFixes/SimplifyObjectCreation/VisualBasicSimplifyObjectCreationCodeFixProvider.vb b/src/Analyzers/VisualBasic/CodeFixes/SimplifyObjectCreation/VisualBasicSimplifyObjectCreationCodeFixProvider.vb index 9d9eec48bc5a4..9fb8536da5b15 100644 --- a/src/Analyzers/VisualBasic/CodeFixes/SimplifyObjectCreation/VisualBasicSimplifyObjectCreationCodeFixProvider.vb +++ b/src/Analyzers/VisualBasic/CodeFixes/SimplifyObjectCreation/VisualBasicSimplifyObjectCreationCodeFixProvider.vb @@ -26,17 +26,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.SimplifyObjectCreation Public Overrides Function RegisterCodeFixesAsync(context As CodeFixContext) As Task For Each diagnostic In context.Diagnostics - context.RegisterCodeFix(CodeAction.Create( - VisualBasicCodeFixesResources.Simplify_object_creation, - Function(ct) FixAsync(context.Document, diagnostic, ct), - NameOf(VisualBasicCodeFixesResources.Simplify_object_creation)), - diagnostic) + RegisterCodeFix(context, VisualBasicCodeFixesResources.Simplify_object_creation, NameOf(VisualBasicCodeFixesResources.Simplify_object_creation), diagnostic) Next Return Task.CompletedTask End Function - Protected Overrides Async Function FixAllAsync(document As Document, diagnostics As ImmutableArray(Of Diagnostic), editor As SyntaxEditor, cancellationToken As CancellationToken) As Task + Protected Overrides Async Function FixAllAsync(document As Document, diagnostics As ImmutableArray(Of Diagnostic), editor As SyntaxEditor, options As CodeActionOptionsProvider, cancellationToken As CancellationToken) As Task Dim root = Await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(False) For Each diagnostic In diagnostics Dim node = DirectCast(root.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie:=True), VariableDeclaratorSyntax) diff --git a/src/Analyzers/VisualBasic/CodeFixes/UseIsNotExpression/VisualBasicUseIsNotExpressionCodeFixProvider.vb b/src/Analyzers/VisualBasic/CodeFixes/UseIsNotExpression/VisualBasicUseIsNotExpressionCodeFixProvider.vb index 511485ff99336..b8d8996068040 100644 --- a/src/Analyzers/VisualBasic/CodeFixes/UseIsNotExpression/VisualBasicUseIsNotExpressionCodeFixProvider.vb +++ b/src/Analyzers/VisualBasic/CodeFixes/UseIsNotExpression/VisualBasicUseIsNotExpressionCodeFixProvider.vb @@ -26,11 +26,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UseIsNotExpression Public Overrides ReadOnly Property FixableDiagnosticIds As ImmutableArray(Of String) = ImmutableArray.Create(IDEDiagnosticIds.UseIsNotExpressionDiagnosticId) Public Overrides Function RegisterCodeFixesAsync(context As CodeFixContext) As Task - context.RegisterCodeFix(CodeAction.Create( - VisualBasicAnalyzersResources.Use_IsNot_expression, - Function(c) FixAsync(context.Document, context.Diagnostics.First(), c), - NameOf(VisualBasicAnalyzersResources.Use_IsNot_expression)), - context.Diagnostics) + RegisterCodeFix(context, VisualBasicAnalyzersResources.Use_IsNot_expression, NameOf(VisualBasicAnalyzersResources.Use_IsNot_expression)) Return Task.CompletedTask End Function @@ -38,7 +34,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UseIsNotExpression document As Document, diagnostics As ImmutableArray(Of Diagnostic), editor As SyntaxEditor, - cancellationToken As CancellationToken) As Task +options As CodeActionOptionsProvider, cancellationToken As CancellationToken) As Task For Each diagnostic In diagnostics cancellationToken.ThrowIfCancellationRequested() diff --git a/src/Features/CSharp/Portable/AssignOutParameters/AbstractAssignOutParametersCodeFixProvider.cs b/src/Features/CSharp/Portable/AssignOutParameters/AbstractAssignOutParametersCodeFixProvider.cs index 6ed8324636798..203ae97c9a2b7 100644 --- a/src/Features/CSharp/Portable/AssignOutParameters/AbstractAssignOutParametersCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/AssignOutParameters/AbstractAssignOutParametersCodeFixProvider.cs @@ -134,7 +134,7 @@ private static SyntaxNode GetContainer(SyntaxNode node) protected sealed override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var unassignedParameters = await GetUnassignedParametersAsync( document, diagnostics, cancellationToken).ConfigureAwait(false); diff --git a/src/Features/CSharp/Portable/AssignOutParameters/AssignOutParametersAboveReturnCodeFixProvider.cs b/src/Features/CSharp/Portable/AssignOutParameters/AssignOutParametersAboveReturnCodeFixProvider.cs index 5108eb966a6f7..b9dd2b71d89a5 100644 --- a/src/Features/CSharp/Portable/AssignOutParameters/AssignOutParametersAboveReturnCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/AssignOutParameters/AssignOutParametersAboveReturnCodeFixProvider.cs @@ -29,9 +29,7 @@ public AssignOutParametersAboveReturnCodeFixProvider() protected override void TryRegisterFix(CodeFixContext context, Document document, SyntaxNode container, SyntaxNode location) { - context.RegisterCodeFix(new MyCodeAction( - CSharpFeaturesResources.Assign_out_parameters, - c => FixAsync(document, context.Diagnostics[0], c)), context.Diagnostics); + RegisterCodeFix(context, CSharpFeaturesResources.Assign_out_parameters, nameof(CSharpFeaturesResources.Assign_out_parameters)); } protected override void AssignOutParameters( diff --git a/src/Features/CSharp/Portable/AssignOutParameters/AssignOutParametersAtStartCodeFixProvider.cs b/src/Features/CSharp/Portable/AssignOutParameters/AssignOutParametersAtStartCodeFixProvider.cs index 21db87670a340..94c3e91b87e78 100644 --- a/src/Features/CSharp/Portable/AssignOutParameters/AssignOutParametersAtStartCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/AssignOutParameters/AssignOutParametersAtStartCodeFixProvider.cs @@ -49,9 +49,9 @@ statement.Parent is BlockSyntax block && return; } - context.RegisterCodeFix(new MyCodeAction( - CSharpFeaturesResources.Assign_out_parameters_at_start, - c => FixAsync(document, context.Diagnostics[0], c)), context.Diagnostics); + context.RegisterCodeFix( + new MyCodeAction(CSharpFeaturesResources.Assign_out_parameters_at_start, GetDocumentUpdater(context)), + context.Diagnostics); } protected override void AssignOutParameters( diff --git a/src/Features/CSharp/Portable/CodeFixes/RemoveInKeyword/RemoveInKeywordCodeFixProvider.cs b/src/Features/CSharp/Portable/CodeFixes/RemoveInKeyword/RemoveInKeywordCodeFixProvider.cs index 627bbffd08ced..7bcbf1e76969e 100644 --- a/src/Features/CSharp/Portable/CodeFixes/RemoveInKeyword/RemoveInKeywordCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/CodeFixes/RemoveInKeyword/RemoveInKeywordCodeFixProvider.cs @@ -50,7 +50,11 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) return; context.RegisterCodeFix( - new MyCodeAction(ct => FixAsync(context.Document, argumentSyntax, ct)), context.Diagnostics); + CodeAction.Create( + CSharpFeaturesResources.Remove_in_keyword, + ct => FixAsync(context.Document, argumentSyntax, ct), + nameof(CSharpFeaturesResources.Remove_in_keyword)), + context.Diagnostics); } private static async Task FixAsync( @@ -65,15 +69,5 @@ private static async Task FixAsync( argumentSyntax, generator.Argument(generator.SyntaxFacts.GetExpressionOfArgument(argumentSyntax)))); } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(Func> createChangedDocument) - : base(CSharpFeaturesResources.Remove_in_keyword, - createChangedDocument, - CSharpFeaturesResources.Remove_in_keyword) - { - } - } } } diff --git a/src/Features/CSharp/Portable/CodeFixes/RemoveNewModifier/RemoveNewModifierCodeFixProvider.cs b/src/Features/CSharp/Portable/CodeFixes/RemoveNewModifier/RemoveNewModifierCodeFixProvider.cs index d5bf42ef139b1..c3178c21c177f 100644 --- a/src/Features/CSharp/Portable/CodeFixes/RemoveNewModifier/RemoveNewModifierCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/CodeFixes/RemoveNewModifier/RemoveNewModifierCodeFixProvider.cs @@ -53,7 +53,10 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) return; context.RegisterCodeFix( - new MyCodeAction(ct => FixAsync(context.Document, generator, memberDeclarationSyntax, ct)), + CodeAction.Create( + CSharpFeaturesResources.Remove_new_modifier, + ct => FixAsync(context.Document, generator, memberDeclarationSyntax, ct), + nameof(CSharpFeaturesResources.Remove_new_modifier)), context.Diagnostics); } @@ -70,15 +73,5 @@ private static async Task FixAsync( generator.WithModifiers( memberDeclaration, generator.GetModifiers(memberDeclaration).WithIsNew(false)))); } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(Func> createChangedDocument) - : base(CSharpFeaturesResources.Remove_new_modifier, - createChangedDocument, - CSharpFeaturesResources.Remove_new_modifier) - { - } - } } } diff --git a/src/Features/CSharp/Portable/ConvertProgram/ConvertToProgramMainCodeFixProvider.cs b/src/Features/CSharp/Portable/ConvertProgram/ConvertToProgramMainCodeFixProvider.cs index 441b21784ad86..4d5ed4768395f 100644 --- a/src/Features/CSharp/Portable/ConvertProgram/ConvertToProgramMainCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/ConvertProgram/ConvertToProgramMainCodeFixProvider.cs @@ -42,30 +42,16 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) ? CodeActionPriority.Low : CodeActionPriority.Medium; - var diagnostic = context.Diagnostics[0]; - context.RegisterCodeFix( - new MyCodeAction(c => FixAsync(context.Document, diagnostic, c), priority), - context.Diagnostics); + RegisterCodeFix(context, CSharpAnalyzersResources.Convert_to_Program_Main_style_program, nameof(ConvertToProgramMainCodeFixProvider), priority); } protected override async Task FixAllAsync( - Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) + Document document, ImmutableArray diagnostics, SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var fixedDocument = await ConvertToProgramMainAsync(document, cancellationToken).ConfigureAwait(false); var fixedRoot = await fixedDocument.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); editor.ReplaceNode(editor.OriginalRoot, fixedRoot); } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - internal override CodeActionPriority Priority { get; } - - public MyCodeAction(Func> createChangedDocument, CodeActionPriority priority) - : base(CSharpAnalyzersResources.Convert_to_Program_Main_style_program, createChangedDocument, nameof(ConvertToProgramMainCodeFixProvider)) - { - this.Priority = priority; - } - } } } diff --git a/src/Features/CSharp/Portable/ConvertProgram/ConvertToTopLevelStatementsCodeFixProvider.cs b/src/Features/CSharp/Portable/ConvertProgram/ConvertToTopLevelStatementsCodeFixProvider.cs index d10c1287cf23c..ba5b1ffdda08b 100644 --- a/src/Features/CSharp/Portable/ConvertProgram/ConvertToTopLevelStatementsCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/ConvertProgram/ConvertToTopLevelStatementsCodeFixProvider.cs @@ -43,14 +43,11 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) ? CodeActionPriority.Low : CodeActionPriority.Medium; - var diagnostic = context.Diagnostics[0]; - context.RegisterCodeFix( - new MyCodeAction(c => FixAsync(context.Document, diagnostic, c), priority), - context.Diagnostics); + RegisterCodeFix(context, CSharpAnalyzersResources.Convert_to_top_level_statements, nameof(ConvertToTopLevelStatementsCodeFixProvider), priority); } protected override async Task FixAllAsync( - Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) + Document document, ImmutableArray diagnostics, SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var methodDeclaration = (MethodDeclarationSyntax)diagnostics[0].AdditionalLocations[0].FindNode(cancellationToken); @@ -59,16 +56,5 @@ protected override async Task FixAllAsync( editor.ReplaceNode(editor.OriginalRoot, newRoot); } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - internal override CodeActionPriority Priority { get; } - - public MyCodeAction(Func> createChangedDocument, CodeActionPriority priority) - : base(CSharpAnalyzersResources.Convert_to_top_level_statements, createChangedDocument, nameof(ConvertToTopLevelStatementsCodeFixProvider)) - { - this.Priority = priority; - } - } } } diff --git a/src/Features/CSharp/Portable/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeFixProvider.cs b/src/Features/CSharp/Portable/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeFixProvider.cs index d987d0c642bb4..a421d36e7c9c9 100644 --- a/src/Features/CSharp/Portable/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeFixProvider.cs @@ -32,34 +32,21 @@ public MakeLocalFunctionStaticCodeFixProvider() public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(new MyCodeAction( - c => FixAsync(context.Document, context.Diagnostics[0], c)), - context.Diagnostics); - + RegisterCodeFix(context, CSharpAnalyzersResources.Make_local_function_static, nameof(CSharpAnalyzersResources.Make_local_function_static)); return Task.CompletedTask; } protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var localFunctions = diagnostics.SelectAsArray(d => d.AdditionalLocations[0].FindNode(getInnermostNodeForTie: true, cancellationToken)); foreach (var localFunction in localFunctions) { - editor.ReplaceNode( - localFunction, - (current, generator) => MakeLocalFunctionStaticCodeFixHelper.AddStaticModifier(current, generator)); + editor.ReplaceNode(localFunction, MakeLocalFunctionStaticCodeFixHelper.AddStaticModifier); } return Task.CompletedTask; } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(Func> createChangedDocument) - : base(CSharpAnalyzersResources.Make_local_function_static, createChangedDocument, CSharpAnalyzersResources.Make_local_function_static) - { - } - } } } diff --git a/src/Features/CSharp/Portable/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeRefactoringProvider.cs b/src/Features/CSharp/Portable/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeRefactoringProvider.cs index 40b5e172323c3..78b3e3ea78719 100644 --- a/src/Features/CSharp/Portable/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeRefactoringProvider.cs +++ b/src/Features/CSharp/Portable/MakeLocalFunctionStatic/MakeLocalFunctionStaticCodeRefactoringProvider.cs @@ -48,16 +48,10 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte if (MakeLocalFunctionStaticHelper.CanMakeLocalFunctionStaticByRefactoringCaptures(localFunction, semanticModel, out var captures)) { - context.RegisterRefactoring(new MyCodeAction( - c => MakeLocalFunctionStaticCodeFixHelper.MakeLocalFunctionStaticAsync(document, localFunction, captures, c))); - } - } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(Func> createChangedDocument) - : base(CSharpAnalyzersResources.Make_local_function_static, createChangedDocument, nameof(CSharpAnalyzersResources.Make_local_function_static)) - { + context.RegisterRefactoring(CodeAction.Create( + CSharpAnalyzersResources.Make_local_function_static, + c => MakeLocalFunctionStaticCodeFixHelper.MakeLocalFunctionStaticAsync(document, localFunction, captures, c), + nameof(CSharpAnalyzersResources.Make_local_function_static))); } } } diff --git a/src/Features/CSharp/Portable/MakeLocalFunctionStatic/PassInCapturedVariablesAsArgumentsCodeFixProvider.cs b/src/Features/CSharp/Portable/MakeLocalFunctionStatic/PassInCapturedVariablesAsArgumentsCodeFixProvider.cs index 6ab2eb858e8c9..859f5b517927a 100644 --- a/src/Features/CSharp/Portable/MakeLocalFunctionStatic/PassInCapturedVariablesAsArgumentsCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/MakeLocalFunctionStatic/PassInCapturedVariablesAsArgumentsCodeFixProvider.cs @@ -40,11 +40,10 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) (document, localFunction, captures) => { context.RegisterCodeFix( - new MyCodeAction(c => MakeLocalFunctionStaticCodeFixHelper.MakeLocalFunctionStaticAsync( - document, - localFunction, - captures, - c)), + CodeAction.Create( + CSharpCodeFixesResources.Pass_in_captured_variables_as_arguments, + c => MakeLocalFunctionStaticCodeFixHelper.MakeLocalFunctionStaticAsync(document, localFunction, captures, c), + nameof(CSharpCodeFixesResources.Pass_in_captured_variables_as_arguments)), diagnostic); return Task.CompletedTask; @@ -52,7 +51,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) context.CancellationToken); } - protected override Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) + protected override Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) => WrapFixAsync( document, diagnostics, @@ -102,13 +101,5 @@ private static async Task WrapFixAsync( } } } - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(Func> createChangedDocument) - : base(CSharpCodeFixesResources.Pass_in_captured_variables_as_arguments, createChangedDocument, CSharpCodeFixesResources.Pass_in_captured_variables_as_arguments) - { - } - } } } diff --git a/src/Features/CSharp/Portable/RemoveUnusedLocalFunction/CSharpRemoveUnusedLocalFunctionCodeFixProvider.cs b/src/Features/CSharp/Portable/RemoveUnusedLocalFunction/CSharpRemoveUnusedLocalFunctionCodeFixProvider.cs index 815fb2eba8d64..e765b6b5cccc4 100644 --- a/src/Features/CSharp/Portable/RemoveUnusedLocalFunction/CSharpRemoveUnusedLocalFunctionCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/RemoveUnusedLocalFunction/CSharpRemoveUnusedLocalFunctionCodeFixProvider.cs @@ -38,14 +38,11 @@ public sealed override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix( - new MyCodeAction(c => FixAsync(context.Document, context.Diagnostics.First(), c)), - context.Diagnostics); - + context.RegisterCodeFix(new MyCodeAction(GetDocumentUpdater(context)), context.Diagnostics); return Task.CompletedTask; } - protected override Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) + protected override Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var root = editor.OriginalRoot; diff --git a/src/Features/CSharp/Portable/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs b/src/Features/CSharp/Portable/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs index 501ca38ca08b1..574ccaa092f41 100644 --- a/src/Features/CSharp/Portable/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/UseLocalFunction/CSharpUseLocalFunctionCodeFixProvider.cs @@ -46,15 +46,13 @@ protected override bool IncludeDiagnosticDuringFixAll(Diagnostic diagnostic) public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix( - new MyCodeAction(c => FixAsync(context.Document, context.Diagnostics.First(), c)), - context.Diagnostics); + RegisterCodeFix(context, CSharpAnalyzersResources.Use_local_function, nameof(CSharpAnalyzersResources.Use_local_function)); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); @@ -87,10 +85,10 @@ protected override async Task FixAllAsync( var root = editor.OriginalRoot; var currentRoot = root.TrackNodes(nodesToTrack); - var options = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); + var optionSet = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); var languageVersion = semanticModel.SyntaxTree.Options.LanguageVersion(); var makeStaticIfPossible = languageVersion >= LanguageVersion.CSharp8 && - options.GetOption(CSharpCodeStyleOptions.PreferStaticLocalFunction).Value; + optionSet.GetOption(CSharpCodeStyleOptions.PreferStaticLocalFunction).Value; // Process declarations in reverse order so that we see the effects of nested // declarations befor processing the outer decls. @@ -312,13 +310,5 @@ private static int TryDetermineParameterIndex(NameColonSyntax argumentNameColon, private static EqualsValueClauseSyntax GetDefaultValue(IParameterSymbol parameter) => SyntaxFactory.EqualsValueClause(ExpressionGenerator.GenerateExpression(parameter.Type, parameter.ExplicitDefaultValue, canUseFieldReference: true)); - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(Func> createChangedDocument) - : base(CSharpAnalyzersResources.Use_local_function, createChangedDocument, CSharpAnalyzersResources.Use_local_function) - { - } - } } } diff --git a/src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameCodeFixProvider.cs b/src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameCodeFixProvider.cs index a1364f058ddfd..4a7e5a8381eee 100644 --- a/src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckWithoutNameCodeFixProvider.cs @@ -37,15 +37,13 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix( - new MyCodeAction(c => FixAsync(context.Document, context.Diagnostics.First(), c)), - context.Diagnostics); + context.RegisterCodeFix(new MyCodeAction(GetDocumentUpdater(context)), context.Diagnostics); return Task.CompletedTask; } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { Debug.Assert(diagnostics.Length == 1); var location = diagnostics[0].Location; diff --git a/src/Features/Core/Portable/AddAnonymousTypeMemberName/AbstractAddAnonymousTypeMemberNameCodeFixProvider.cs b/src/Features/Core/Portable/AddAnonymousTypeMemberName/AbstractAddAnonymousTypeMemberNameCodeFixProvider.cs index 3e521d5bc1001..40d3072f29da7 100644 --- a/src/Features/Core/Portable/AddAnonymousTypeMemberName/AbstractAddAnonymousTypeMemberNameCodeFixProvider.cs +++ b/src/Features/Core/Portable/AddAnonymousTypeMemberName/AbstractAddAnonymousTypeMemberNameCodeFixProvider.cs @@ -46,9 +46,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) return; } - context.RegisterCodeFix( - new MyCodeAction(c => FixAsync(document, diagnostic, c)), - context.Diagnostics); + context.RegisterCodeFix(new MyCodeAction(GetDocumentUpdater(context)), context.Diagnostics); } private async Task GetMemberDeclaratorAsync( @@ -83,7 +81,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { // If we're only introducing one name, then add the rename annotation to // it so the user can pick a better name if they want. diff --git a/src/Features/Core/Portable/CodeStyle/AbstractCodeStyleProvider.Fixing.cs b/src/Features/Core/Portable/CodeStyle/AbstractCodeStyleProvider.Fixing.cs index cfe719b06103c..2e7a7e1a1b9b8 100644 --- a/src/Features/Core/Portable/CodeStyle/AbstractCodeStyleProvider.Fixing.cs +++ b/src/Features/Core/Portable/CodeStyle/AbstractCodeStyleProvider.Fixing.cs @@ -7,6 +7,7 @@ using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; +using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Editing; @@ -45,7 +46,7 @@ protected CodeFixProvider() public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) => _codeStyleProvider.RegisterCodeFixesAsync(context); - protected sealed override Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken) + protected sealed override Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) => _codeStyleProvider.FixAllAsync(document, diagnostics, editor, cancellationToken); } } diff --git a/src/Features/Core/Portable/ConvertAnonymousType/AbstractConvertAnonymousTypeToTupleCodeRefactoringProvider.cs b/src/Features/Core/Portable/ConvertAnonymousType/AbstractConvertAnonymousTypeToTupleCodeRefactoringProvider.cs index 1d8c234f1f29d..2dded37589372 100644 --- a/src/Features/Core/Portable/ConvertAnonymousType/AbstractConvertAnonymousTypeToTupleCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/ConvertAnonymousType/AbstractConvertAnonymousTypeToTupleCodeRefactoringProvider.cs @@ -51,19 +51,20 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte // anonymous type, and one to fixup all anonymous types. if (allAnonymousNodes.Any(t => !anonymousType.Equals(t.symbol, SymbolEqualityComparer.Default))) { - context.RegisterRefactoring(CodeAction.CodeActionWithNestedActions.Create( - FeaturesResources.Convert_to_tuple, - ImmutableArray.Create( - new MyCodeAction(FeaturesResources.just_this_anonymous_type, c => FixInCurrentMemberAsync(document, anonymousNode, anonymousType, allAnonymousTypes: false, c)), - new MyCodeAction(FeaturesResources.all_anonymous_types_in_container, c => FixInCurrentMemberAsync(document, anonymousNode, anonymousType, allAnonymousTypes: true, c))), - isInlinable: false), + context.RegisterRefactoring( + CodeAction.CodeActionWithNestedActions.Create( + FeaturesResources.Convert_to_tuple, + ImmutableArray.Create( + CodeAction.Create(FeaturesResources.just_this_anonymous_type, c => FixInCurrentMemberAsync(document, anonymousNode, anonymousType, allAnonymousTypes: false, c), nameof(FeaturesResources.just_this_anonymous_type)), + CodeAction.Create(FeaturesResources.all_anonymous_types_in_container, c => FixInCurrentMemberAsync(document, anonymousNode, anonymousType, allAnonymousTypes: true, c), nameof(FeaturesResources.all_anonymous_types_in_container))), + isInlinable: false), span); } else { // otherwise, just offer the change to the single tuple type. context.RegisterRefactoring( - new MyCodeAction(FeaturesResources.Convert_to_tuple, c => FixInCurrentMemberAsync(document, anonymousNode, anonymousType, allAnonymousTypes: false, c)), + CodeAction.Create(FeaturesResources.Convert_to_tuple, c => FixInCurrentMemberAsync(document, anonymousNode, anonymousType, allAnonymousTypes: false, c), nameof(FeaturesResources.Convert_to_tuple)), span); } } @@ -128,13 +129,5 @@ private void ReplaceWithTuple(SyntaxEditor editor, TAnonymousObjectCreationExpre return ConvertToTuple(anonCreation).WithAdditionalAnnotations(Formatter.Annotation); }); - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(string title, Func> createChangedDocument) - : base(title, createChangedDocument, title) - { - } - } } } diff --git a/src/Features/Core/Portable/EmbeddedLanguages/Json/LanguageServices/AbstractJsonDetectionCodeFixProvider.cs b/src/Features/Core/Portable/EmbeddedLanguages/Json/LanguageServices/AbstractJsonDetectionCodeFixProvider.cs index c71a6e87c5218..63150fd9141a5 100644 --- a/src/Features/Core/Portable/EmbeddedLanguages/Json/LanguageServices/AbstractJsonDetectionCodeFixProvider.cs +++ b/src/Features/Core/Portable/EmbeddedLanguages/Json/LanguageServices/AbstractJsonDetectionCodeFixProvider.cs @@ -35,10 +35,7 @@ public override ImmutableArray FixableDiagnosticIds public override Task RegisterCodeFixesAsync(CodeFixContext context) { - context.RegisterCodeFix(new MyCodeAction( - c => FixAsync(context.Document, context.Diagnostics[0], c)), - context.Diagnostics); - + context.RegisterCodeFix(new MyCodeAction(GetDocumentUpdater(context)), context.Diagnostics); return Task.CompletedTask; } @@ -56,7 +53,7 @@ public void Fix(SyntaxEditor editor, Diagnostic diagnostic, CancellationToken ca protected override Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { foreach (var diagnostic in diagnostics) Fix(editor, diagnostic, cancellationToken); diff --git a/src/Features/Core/Portable/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs b/src/Features/Core/Portable/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs index 6c475f8fd7d8d..6ffd69cef3acb 100644 --- a/src/Features/Core/Portable/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs +++ b/src/Features/Core/Portable/ImplementAbstractClass/AbstractImplementAbstractClassCodeFixProvider.cs @@ -49,9 +49,10 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) var abstractClassType = data.AbstractClassType; var id = GetCodeActionId(abstractClassType.ContainingAssembly.Name, abstractClassType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)); context.RegisterCodeFix( - new MyCodeAction( + CodeAction.Create( FeaturesResources.Implement_abstract_class, - c => data.ImplementAbstractClassAsync(throughMember: null, canDelegateAllMembers: null, c), id), + c => data.ImplementAbstractClassAsync(throughMember: null, canDelegateAllMembers: null, c), + id), context.Diagnostics); foreach (var (through, canDelegateAllMembers) in data.GetDelegatableMembers()) @@ -60,23 +61,17 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) abstractClassType.ContainingAssembly.Name, abstractClassType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), through.Name); + context.RegisterCodeFix( - new MyCodeAction( + CodeAction.Create( string.Format(FeaturesResources.Implement_through_0, through.Name), - c => data.ImplementAbstractClassAsync(through, canDelegateAllMembers, c), id), + c => data.ImplementAbstractClassAsync(through, canDelegateAllMembers, c), + id), context.Diagnostics); } } private static string GetCodeActionId(string assemblyName, string abstractTypeFullyQualifiedName, string through = "") => FeaturesResources.Implement_abstract_class + ";" + assemblyName + ";" + abstractTypeFullyQualifiedName + ";" + through; - - private class MyCodeAction : CustomCodeActions.DocumentChangeAction - { - public MyCodeAction(string title, Func> createChangedDocument, string id) - : base(title, createChangedDocument, id) - { - } - } } } diff --git a/src/Features/Core/Portable/PreferFrameworkType/PreferFrameworkTypeCodeFixProvider.cs b/src/Features/Core/Portable/PreferFrameworkType/PreferFrameworkTypeCodeFixProvider.cs index 6824099a1b9cb..8b98a3a4e4f27 100644 --- a/src/Features/Core/Portable/PreferFrameworkType/PreferFrameworkTypeCodeFixProvider.cs +++ b/src/Features/Core/Portable/PreferFrameworkType/PreferFrameworkTypeCodeFixProvider.cs @@ -36,10 +36,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) var diagnostic = context.Diagnostics[0]; if (diagnostic.Properties.ContainsKey(PreferFrameworkTypeConstants.PreferFrameworkType)) { - context.RegisterCodeFix( - new PreferFrameworkTypeCodeAction( - c => FixAsync(context.Document, diagnostic, c)), - context.Diagnostics); + context.RegisterCodeFix(new PreferFrameworkTypeCodeAction(GetDocumentUpdater(context)), context.Diagnostics); } return Task.CompletedTask; @@ -47,7 +44,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context) protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var generator = document.GetLanguageService(); var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/Features/Core/Portable/RemoveAsyncModifier/AbstractRemoveAsyncModifierCodeFixProvider.cs b/src/Features/Core/Portable/RemoveAsyncModifier/AbstractRemoveAsyncModifierCodeFixProvider.cs index 53fa9700d504c..207bf2bc24d73 100644 --- a/src/Features/Core/Portable/RemoveAsyncModifier/AbstractRemoveAsyncModifierCodeFixProvider.cs +++ b/src/Features/Core/Portable/RemoveAsyncModifier/AbstractRemoveAsyncModifierCodeFixProvider.cs @@ -51,15 +51,13 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) if (ShouldOfferFix(methodSymbol.ReturnType, knownTypes)) { - context.RegisterCodeFix( - new MyCodeAction(c => FixAsync(document, diagnostic, c)), - context.Diagnostics); + context.RegisterCodeFix(new MyCodeAction(GetDocumentUpdater(context)), context.Diagnostics); } } protected sealed override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var generator = editor.Generator; var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/Features/Core/Portable/RemoveUnusedVariable/AbstractRemoveUnusedVariableCodeFixProvider.cs b/src/Features/Core/Portable/RemoveUnusedVariable/AbstractRemoveUnusedVariableCodeFixProvider.cs index c095df8244674..cb9d5e1d4fd8d 100644 --- a/src/Features/Core/Portable/RemoveUnusedVariable/AbstractRemoveUnusedVariableCodeFixProvider.cs +++ b/src/Features/Core/Portable/RemoveUnusedVariable/AbstractRemoveUnusedVariableCodeFixProvider.cs @@ -47,10 +47,10 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) var blockFacts = document.GetRequiredLanguageService(); if (ShouldOfferFixForLocalDeclaration(blockFacts, node)) - context.RegisterCodeFix(new MyCodeAction(c => FixAsync(context.Document, diagnostic, c)), diagnostic); + context.RegisterCodeFix(new MyCodeAction(GetDocumentUpdater(context)), diagnostic); } - protected override async Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor syntaxEditor, CancellationToken cancellationToken) + protected override async Task FixAllAsync(Document document, ImmutableArray diagnostics, SyntaxEditor syntaxEditor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var nodesToRemove = new HashSet(); diff --git a/src/Features/Core/Portable/SimplifyThisOrMe/AbstractSimplifyThisOrMeCodeFixProvider.cs b/src/Features/Core/Portable/SimplifyThisOrMe/AbstractSimplifyThisOrMeCodeFixProvider.cs index 3c44c6d15dc40..8a05cc947310f 100644 --- a/src/Features/Core/Portable/SimplifyThisOrMe/AbstractSimplifyThisOrMeCodeFixProvider.cs +++ b/src/Features/Core/Portable/SimplifyThisOrMe/AbstractSimplifyThisOrMeCodeFixProvider.cs @@ -36,12 +36,9 @@ protected AbstractSimplifyThisOrMeCodeFixProvider() public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) { - var document = context.Document; - var diagnostic = context.Diagnostics[0]; - context.RegisterCodeFix(new MyCodeAction( GetTitle(), - c => FixAsync(document, diagnostic, c), + GetDocumentUpdater(context), IDEDiagnosticIds.RemoveQualificationDiagnosticId), context.Diagnostics); return Task.CompletedTask; @@ -49,7 +46,7 @@ public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var documentOptions = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/Features/Core/Portable/SimplifyTypeNames/AbstractSimplifyTypeNamesCodeFixProvider.cs b/src/Features/Core/Portable/SimplifyTypeNames/AbstractSimplifyTypeNamesCodeFixProvider.cs index b44484e27c55c..d8f7c5d6900d8 100644 --- a/src/Features/Core/Portable/SimplifyTypeNames/AbstractSimplifyTypeNamesCodeFixProvider.cs +++ b/src/Features/Core/Portable/SimplifyTypeNames/AbstractSimplifyTypeNamesCodeFixProvider.cs @@ -91,13 +91,13 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) context.RegisterCodeFix(new MyCodeAction( title, - c => FixAsync(context.Document, context.Diagnostics[0], c), + GetDocumentUpdater(context), diagnosticId), context.Diagnostics); } protected override async Task FixAllAsync( Document document, ImmutableArray diagnostics, - SyntaxEditor editor, CancellationToken cancellationToken) + SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken) { var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var model = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); diff --git a/src/Features/VisualBasic/Portable/RemoveSharedFromModuleMembers/VisualBasicRemoveSharedFromModuleMembersCodeFixProvider.vb b/src/Features/VisualBasic/Portable/RemoveSharedFromModuleMembers/VisualBasicRemoveSharedFromModuleMembersCodeFixProvider.vb index de058e88e2974..4b61671b279db 100644 --- a/src/Features/VisualBasic/Portable/RemoveSharedFromModuleMembers/VisualBasicRemoveSharedFromModuleMembersCodeFixProvider.vb +++ b/src/Features/VisualBasic/Portable/RemoveSharedFromModuleMembers/VisualBasicRemoveSharedFromModuleMembersCodeFixProvider.vb @@ -48,15 +48,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveSharedFromModuleMembers Continue For End If - context.RegisterCodeFix( - New MyCodeAction(Function(ct) FixAsync(context.Document, diagnostic, context.CancellationToken)), - diagnostic) + context.RegisterCodeFix(New MyCodeAction(GetDocumentUpdater(context, diagnostic)), diagnostic) Next Return Task.CompletedTask End Function - Protected Overrides Function FixAllAsync(document As Document, diagnostics As ImmutableArray(Of Diagnostic), editor As SyntaxEditor, cancellationToken As CancellationToken) As Task + Protected Overrides Function FixAllAsync(document As Document, diagnostics As ImmutableArray(Of Diagnostic), editor As SyntaxEditor, options As CodeActionOptionsProvider, cancellationToken As CancellationToken) As Task For Each diagnostic In diagnostics Dim node = diagnostic.Location.FindNode(cancellationToken) Dim newNode = GetReplacement(document, node) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/CustomCodeActions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/CustomCodeActions.cs index 82ef62a5f56c7..97b0dcbd89f06 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/CustomCodeActions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/CustomCodeActions.cs @@ -9,6 +9,19 @@ namespace Microsoft.CodeAnalysis.CodeActions { + // Define dummy priority to avoid ifdefs. + // 'CodeActionPriority' is not a public API, hence not supported in CodeStyle layer. + // https://github.com/dotnet/roslyn/issues/42431 tracks adding a public API. +#if CODE_STYLE + internal enum CodeActionPriority + { + Lowest = 0, + Low = 1, + Medium = 2, + High = 3 + } +#endif + internal static class CustomCodeActions { internal abstract class SimpleCodeAction : CodeAction @@ -29,13 +42,21 @@ internal class DocumentChangeAction : SimpleCodeAction { private readonly Func> _createChangedDocument; +#if CODE_STYLE + internal CodeActionPriority Priority { get; } +#else + internal override CodeActionPriority Priority { get; } +#endif + public DocumentChangeAction( string title, Func> createChangedDocument, - string? equivalenceKey) + string? equivalenceKey, + CodeActionPriority priority) : base(title, equivalenceKey) { _createChangedDocument = createChangedDocument; + Priority = priority; } protected sealed override Task GetChangedDocumentAsync(CancellationToken cancellationToken) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/SyntaxEditorBasedCodeFixProvider.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/SyntaxEditorBasedCodeFixProvider.cs index 5152af02245b7..299f2931ad2f8 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/SyntaxEditorBasedCodeFixProvider.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeFixes/SyntaxEditorBasedCodeFixProvider.cs @@ -6,6 +6,7 @@ using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; +using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Shared.Extensions; @@ -17,6 +18,10 @@ internal abstract partial class SyntaxEditorBasedCodeFixProvider : CodeFixProvid ImmutableArray.Create(FixAllScope.Document, FixAllScope.Project, FixAllScope.Solution, FixAllScope.ContainingMember, FixAllScope.ContainingType); +#if CODE_STYLE + private static readonly CodeActionOptionsProvider s_codeStyleOptionsProvider = new(_ => default); +#endif + private readonly bool _supportsFixAll; protected SyntaxEditorBasedCodeFixProvider(bool supportsFixAll = true) @@ -44,22 +49,43 @@ protected SyntaxEditorBasedCodeFixProvider(bool supportsFixAll = true) if (filteredDiagnostics.Length == 0) return document; - return await this.FixAllAsync(document, filteredDiagnostics, fixAllContext.CancellationToken).ConfigureAwait(false); +#if CODE_STYLE + var optionsProvider = s_codeStyleOptionsProvider; +#else + var optionsProvider = fixAllContext.State.CodeActionOptionsProvider; +#endif + return await FixAllAsync(document, filteredDiagnostics, optionsProvider, fixAllContext.CancellationToken).ConfigureAwait(false); }, s_defaultSupportedFixAllScopes); } - protected Task FixAsync( - Document document, Diagnostic diagnostic, CancellationToken cancellationToken) + protected void RegisterCodeFix(CodeFixContext context, string title, string equivalenceKey, Diagnostic? diagnostic = null) + => context.RegisterCodeFix(CodeAction.Create(title, GetDocumentUpdater(context, diagnostic), equivalenceKey), context.Diagnostics); + + protected void RegisterCodeFix(CodeFixContext context, string title, string equivalenceKey, CodeActionPriority priority, Diagnostic? diagnostic = null) + => context.RegisterCodeFix(new CustomCodeActions.DocumentChangeAction(title, GetDocumentUpdater(context, diagnostic), equivalenceKey, priority), context.Diagnostics); + + protected Func> GetDocumentUpdater(CodeFixContext context, Diagnostic? diagnostic = null) { - return FixAllAsync(document, ImmutableArray.Create(diagnostic), cancellationToken); +#if CODE_STYLE + var optionsProvider = s_codeStyleOptionsProvider; +#else + var optionsProvider = new CodeActionOptionsProvider(_ => context.Options); +#endif + var diagnostics = ImmutableArray.Create(diagnostic ?? context.Diagnostics[0]); + + return cancellationToken => FixAllAsync(context.Document, diagnostics, optionsProvider, cancellationToken); } + protected Task FixAsync(Document document, Diagnostic diagnostic, CodeActionOptions options, CancellationToken cancellationToken) + => FixAllAsync(document, ImmutableArray.Create(diagnostic), _ => options, cancellationToken); + private Task FixAllAsync( - Document document, ImmutableArray diagnostics, CancellationToken cancellationToken) + Document document, ImmutableArray diagnostics, CodeActionOptionsProvider options, CancellationToken cancellationToken) { - return FixAllWithEditorAsync(document, - editor => FixAllAsync(document, diagnostics, editor, cancellationToken), + return FixAllWithEditorAsync( + document, + editor => FixAllAsync(document, diagnostics, editor, options, cancellationToken), cancellationToken); } @@ -78,7 +104,7 @@ internal static async Task FixAllWithEditorAsync( } protected abstract Task FixAllAsync( - Document document, ImmutableArray diagnostics, SyntaxEditor editor, CancellationToken cancellationToken); + Document document, ImmutableArray diagnostics, SyntaxEditor editor, CodeActionOptionsProvider options, CancellationToken cancellationToken); /// /// Whether or not this diagnostic should be included when performing a FixAll. This is