public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); VariableDeclaratorSyntax declarator = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <VariableDeclaratorSyntax>(); Debug.Assert(declarator != null, $"{nameof(declarator)} is null"); CodeAction codeAction = CodeAction.Create( "Merge local declaration with initialization", cancellationToken => MergeLocalDeclarationWithInitializationRefactoring.RefactorAsync(context.Document, declarator, cancellationToken), DiagnosticIdentifiers.MergeLocalDeclarationWithInitialization + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }
private void AnalyzeLocalDeclarationStatement(SyntaxNodeAnalysisContext context) { var localDeclaration = (LocalDeclarationStatementSyntax)context.Node; MergeLocalDeclarationWithInitializationRefactoring.Analyze(context, localDeclaration); }