public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out EmptyStatementSyntax emptyStatement))
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Remove empty statement",
                cancellationToken => RemoveEmptyStatementRefactoring.RefactorAsync(context.Document, emptyStatement, cancellationToken),
                GetEquivalenceKey(DiagnosticIdentifiers.RemoveEmptyStatement));

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }
Exemplo n.º 2
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            EmptyStatementSyntax emptyStatement = root
                                                  .FindNode(context.Span, getInnermostNodeForTie: true)?
                                                  .FirstAncestorOrSelf <EmptyStatementSyntax>();

            if (emptyStatement == null)
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Remove empty statement",
                cancellationToken => RemoveEmptyStatementRefactoring.RefactorAsync(context.Document, emptyStatement, cancellationToken),
                DiagnosticIdentifiers.RemoveEmptyStatement + EquivalenceKeySuffix);

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }