private static AnalysisResult HasConfigureAwaitFalse(AwaitExpressionSyntax awaitNode) { InvocationExpressionSyntax configureAwaitExpression = FindConfigureAwaitExpression(awaitNode); bool hasConfigureAwaitFalse = configureAwaitExpression != null && IsExpressionConfigureAwaitFalse(configureAwaitExpression); return(new AnalysisResult(hasConfigureAwaitFalse, awaitNode.GetLocation())); }
public static CheckerResult CheckNode(AwaitExpressionSyntax awaitNode, SemanticModel semanticModel) { var location = awaitNode.GetLocation(); var possibleConfigureAwait = FindExpressionForConfigureAwait(awaitNode); if (possibleConfigureAwait != null && IsConfigureAwait(possibleConfigureAwait.Expression)) { if (HasFalseArgument(possibleConfigureAwait.ArgumentList)) { return(new CheckerResult(CheckerProblem.NoProblem, location)); } else { return(new CheckerResult(CheckerProblem.ConfigureAwaitWithTrue, location)); } } else { var can = CanHaveConfigureAwait(awaitNode.Expression, semanticModel); var problem = can ? CheckerProblem.MissingConfigureAwaitFalse : CheckerProblem.NoProblem; return(new CheckerResult(problem, location)); } }
private static CheckResult CheckNode(AwaitExpressionSyntax awaitNode) { var possibleConfigureAwait = FindExpressionForConfigureAwait(awaitNode); var good = possibleConfigureAwait != null && IsConfigureAwait(possibleConfigureAwait.Expression) && HasFalseArgument(possibleConfigureAwait.ArgumentList); return(new CheckResult(good, awaitNode.GetLocation())); }
public static CheckerResult CheckNode(AwaitExpressionSyntax awaitNode) { var possibleConfigureAwait = FindExpressionForConfigureAwait(awaitNode); var good = possibleConfigureAwait != null && IsProperConfigureAwait(possibleConfigureAwait); return(new CheckerResult(good, awaitNode.GetLocation())); }
private static bool HasPreviousConfigureAwait(SyntaxNodeAnalysisContext context, AwaitExpressionSyntax node) { // Find all previous awaits with ConfiguredAwait(false) // Use context.SemanticModel.AnalyzeControlFlow to check if the current await is accessible from one of the previous await // https://joshvarty.com/2015/03/24/learn-roslyn-now-control-flow-analysis/ var method = node.FirstAncestorOrSelf <MethodDeclarationSyntax>(); if (method != null) { var otherAwaitExpressions = method.DescendantNodes(_ => true).OfType <AwaitExpressionSyntax>(); foreach (var expr in otherAwaitExpressions) { if (HasPreviousConfigureAwait(expr)) { return(true); } bool HasPreviousConfigureAwait(AwaitExpressionSyntax otherAwaitExpression) { if (otherAwaitExpression == node) { return(false); } if (otherAwaitExpression.GetLocation().SourceSpan.Start > node.GetLocation().SourceSpan.Start) { return(false); } if (!IsConfiguredTaskAwaitable(context, otherAwaitExpression)) { return(false); } var nodeStatement = node.FirstAncestorOrSelf <StatementSyntax>(); var parentStatement = otherAwaitExpression.Ancestors().OfType <StatementSyntax>().FirstOrDefault(); while (parentStatement != null && nodeStatement != parentStatement) { if (!IsEndPointReachable(context, parentStatement)) { return(false); } parentStatement = parentStatement.Ancestors().OfType <StatementSyntax>().FirstOrDefault(); } return(true); } } } return(false); }
public static CheckerResult CheckNode(AwaitExpressionSyntax awaitNode, SemanticModel semanticModel) { var possibleConfigureAwait = FindExpressionForConfigureAwait(awaitNode); if (possibleConfigureAwait != null && IsConfigureAwait(possibleConfigureAwait.Expression)) { if (HasFalseArgument(possibleConfigureAwait.ArgumentList)) { return(new CheckerResult(false, awaitNode.GetLocation())); } else { return(new CheckerResult(true, awaitNode.GetLocation())); } } else { var can = CanHaveConfigureAwait(awaitNode.Expression, semanticModel); return(new CheckerResult(can, awaitNode.GetLocation())); } }
public static CheckerResult CheckNode(AwaitExpressionSyntax awaitNode) { var possibleConfigureAwait = FindExpressionForConfigureAwait(awaitNode); var good = possibleConfigureAwait != null && IsProperConfigureAwait(possibleConfigureAwait); return new CheckerResult(good, awaitNode.GetLocation()); }
private Location GetLocationForDiagnostic(AwaitExpressionSyntax awaitExpression) { return(awaitExpression.GetLocation()); }