public override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out IfStatementSyntax ifStatement)) { return; } ifStatement = ifStatement.GetTopmostIf(); CodeAction codeAction = CodeAction.Create( "Remove braces from if-else", cancellationToken => RemoveBracesFromIfElseElseRefactoring.RefactorAsync(context.Document, ifStatement, cancellationToken), GetEquivalenceKey(DiagnosticIdentifiers.RemoveBracesFromIfElse)); context.RegisterCodeFix(codeAction, context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); IfStatementSyntax ifStatement = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <IfStatementSyntax>(); if (ifStatement == null) { return; } ifStatement = IfElseChain.GetTopmostIf(ifStatement); CodeAction codeAction = CodeAction.Create( "Remove braces from if-else", cancellationToken => RemoveBracesFromIfElseElseRefactoring.RefactorAsync(context.Document, ifStatement, cancellationToken), DiagnosticIdentifiers.RemoveBracesFromIfElse + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }