public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out StatementSyntax statement)) { return; } CodeAction codeAction = CodeAction.Create( "Format statement on a separate line", cancellationToken => FormatEachStatementOnSeparateLineRefactoring.RefactorAsync(context.Document, statement, cancellationToken), GetEquivalenceKey(DiagnosticIdentifiers.FormatEachStatementOnSeparateLine)); context.RegisterCodeFix(codeAction, context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); StatementSyntax statement = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <StatementSyntax>(); if (statement == null) { return; } CodeAction codeAction = CodeAction.Create( "Format embedded statement on a separate line", cancellationToken => FormatEachStatementOnSeparateLineRefactoring.RefactorAsync(context.Document, statement, cancellationToken), DiagnosticIdentifiers.FormatEmbeddedStatementOnSeparateLine + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }