public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); AwaitExpressionSyntax awaitExpression = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <AwaitExpressionSyntax>(); CodeAction codeAction = CodeAction.Create( "Add 'ConfigureAwait(false)'", cancellationToken => AddConfigureAwaitRefactoring.RefactorAsync(context.Document, awaitExpression, cancellationToken), DiagnosticIdentifiers.AddConfigureAwait + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }
private void AnalyzeAwaitExpression(SyntaxNodeAnalysisContext context) { if (GeneratedCodeAnalyzer?.IsGeneratedCode(context) == true) { return; } var awaitExpression = (AwaitExpressionSyntax)context.Node; if (AddConfigureAwaitRefactoring.CanRefactor(awaitExpression, context.SemanticModel, context.CancellationToken)) { context.ReportDiagnostic( DiagnosticDescriptors.AddConfigureAwait, awaitExpression.Expression.GetLocation()); } }