public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out BinaryExpressionSyntax binaryExpression)) { return; } CodeAction codeAction = CodeAction.Create( "Format binary operator on next line", cancellationToken => FormatBinaryOperatorOnNextLineRefactoring.RefactorAsync(context.Document, binaryExpression, cancellationToken), GetEquivalenceKey(DiagnosticIdentifiers.FormatBinaryOperatorOnNextLine)); context.RegisterCodeFix(codeAction, context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); BinaryExpressionSyntax binaryExpression = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <BinaryExpressionSyntax>(); if (binaryExpression == null) { return; } CodeAction codeAction = CodeAction.Create( "Format binary operator on next line", cancellationToken => FormatBinaryOperatorOnNextLineRefactoring.RefactorAsync(context.Document, binaryExpression, cancellationToken), DiagnosticIdentifiers.FormatBinaryOperatorOnNextLine + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }