Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
#115: Add missing ConfigureAwait(false)
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarypiatek committed Oct 14, 2020
1 parent 7c189a8 commit 59846b6
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,39 +56,39 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)

private async Task<Document> GenerateExplicitConversion(Document document, AssignmentExpressionSyntax assignmentExpression, CancellationToken cancellationToken)
{
var (mappingEngine, semanticModel) = await CreateMappingEngine(document, assignmentExpression, cancellationToken);
var (mappingEngine, semanticModel) = await CreateMappingEngine(document, assignmentExpression, cancellationToken).ConfigureAwait(false);
var sourceType = mappingEngine.GetExpressionTypeInfo(assignmentExpression.Right).GetAnnotatedType();
var destinationType = mappingEngine.GetExpressionTypeInfo(assignmentExpression.Left).GetAnnotatedType();
var mappingExpression = mappingEngine.MapExpression(assignmentExpression.Right.WithoutTrivia(), sourceType, destinationType, new MappingContext(assignmentExpression, semanticModel));
return await ReplaceNode(document, assignmentExpression, assignmentExpression.WithRight(mappingExpression), cancellationToken);
return await ReplaceNode(document, assignmentExpression, assignmentExpression.WithRight(mappingExpression), cancellationToken).ConfigureAwait(false);
}

private static async Task<(MappingEngine, SemanticModel)> CreateMappingEngine(Document document, SyntaxNode node, CancellationToken cancellationToken)
{
var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
var mappingEngine = await MappingEngine.Create(document, cancellationToken);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var mappingEngine = await MappingEngine.Create(document, cancellationToken).ConfigureAwait(false);
return (mappingEngine, semanticModel);
}

private async Task<Document> GenerateExplicitConversion(Document document, ReturnStatementSyntax returnStatement, CancellationToken cancellationToken)
{
var (mappingEngine, semanticModel) = await CreateMappingEngine(document, returnStatement, cancellationToken);
var (mappingEngine, semanticModel) = await CreateMappingEngine(document, returnStatement, cancellationToken).ConfigureAwait(false);
var returnExpressionTypeInfo = mappingEngine.GetExpressionTypeInfo(returnStatement.Expression);
var mappingExpression = mappingEngine.MapExpression(returnStatement.Expression!.WithoutTrivia(), returnExpressionTypeInfo.GetAnnotatedType(), returnExpressionTypeInfo.GetAnnotatedTypeForConverted(), new MappingContext(returnStatement, semanticModel));
return await ReplaceNode(document, returnStatement, returnStatement.WithExpression(mappingExpression), cancellationToken);
return await ReplaceNode(document, returnStatement, returnStatement.WithExpression(mappingExpression), cancellationToken).ConfigureAwait(false);
}

private async Task<Document> GenerateExplicitConversion(Document document, YieldStatementSyntax yieldStatement, CancellationToken cancellationToken)
{
var (mappingEngine, semanticModel) = await CreateMappingEngine(document, yieldStatement, cancellationToken);
var (mappingEngine, semanticModel) = await CreateMappingEngine(document, yieldStatement, cancellationToken).ConfigureAwait(false);
var returnExpressionTypeInfo = mappingEngine.GetExpressionTypeInfo(yieldStatement.Expression);
var mappingExpression = mappingEngine.MapExpression(yieldStatement.Expression!.WithoutTrivia(), returnExpressionTypeInfo.GetAnnotatedType(), returnExpressionTypeInfo.GetAnnotatedTypeForConverted(), new MappingContext(yieldStatement, semanticModel));
return await ReplaceNode(document, yieldStatement, yieldStatement.WithExpression(mappingExpression), cancellationToken);
return await ReplaceNode(document, yieldStatement, yieldStatement.WithExpression(mappingExpression), cancellationToken).ConfigureAwait(false);
}

private static async Task<Document> ReplaceNode(Document document, SyntaxNode oldNode, SyntaxNode newNode, CancellationToken cancellationToken)
{
var root = await document.GetSyntaxRootAsync(cancellationToken);
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var newRoot = root!.ReplaceNode(oldNode, newNode);
return document.WithSyntaxRoot(newRoot);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ private async Task<Document> ScaffoldInvocation(Document document, IInvocation i
CancellationToken cancellationToken)
{
var syntaxGenerator = SyntaxGenerator.GetGenerator(document);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var mappingSourceFinder = new ScaffoldingSourceFinder(syntaxGenerator,document);
return await CodeFixHelper.FixInvocationWithParameters(document, invocation, namedArguments, semanticModel, mappingSourceFinder, cancellationToken);
return await CodeFixHelper.FixInvocationWithParameters(document, invocation, namedArguments, semanticModel, mappingSourceFinder, cancellationToken).ConfigureAwait(false);
}

private static IInvocation GetInvocation(SyntaxNode invocationExpression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)

private async Task<Document> GenerateSplatting(Document document, IInvocation invocation, bool generateNamedParameters, CancellationToken cancellationToken)
{
var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var overloadParameterSets = invocation.GetOverloadParameterSets(semanticModel);
if (overloadParameterSets != null)
{
Expand All @@ -77,7 +77,7 @@ private async Task<Document> GenerateSplatting(Document document, IInvocation in
{

var argumentList = parametersMatch.ToArgumentListSyntax(mappingEngine, mappingContext, generateNamedParameters);
return await document.ReplaceNodes(invocation.SourceNode, invocation.WithArgumentList(argumentList), cancellationToken);
return await document.ReplaceNodes(invocation.SourceNode, invocation.WithArgumentList(argumentList), cancellationToken).ConfigureAwait(false);

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static async Task<Document> FixInvocationWithParameters(Document document
{

var argumentList = parametersMatch.ToArgumentListSyntax(mappingEngine, mappingContext, generateNamedParameters);
return await document.ReplaceNodes(invocation.SourceNode, invocation.WithArgumentList(argumentList), cancellationToken);
return await document.ReplaceNodes(invocation.SourceNode, invocation.WithArgumentList(argumentList), cancellationToken).ConfigureAwait(false);
}
}

Expand Down Expand Up @@ -117,7 +117,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)

private static async Task<Document> CreateMappingLambda(Document document, InvocationExpressionSyntax invocation, CancellationToken cancellationToken)
{
var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var syntaxGenerator = SyntaxGenerator.GetGenerator(document);
var methodInvocationSymbol = semanticModel.GetSymbolInfo(invocation.Expression);
var mappingOverload = methodInvocationSymbol.CandidateSymbols.OfType<IMethodSymbol>().FirstOrDefault(IsMappingMethod);
Expand All @@ -137,7 +137,7 @@ private static async Task<Document> CreateMappingLambda(Document document, Invoc
var mappingEngine = new MappingEngine(semanticModel, syntaxGenerator);
var sourceListElementType = new AnnotatedType(sourceElementType);
var mappingLambda = mappingEngine.CreateMappingLambda("x", sourceListElementType, targetElementType, new MappingPath(), new MappingContext(invocation, semanticModel));
return await document.ReplaceNodes(invocation, invocation.WithArgumentList(SyntaxFactory.ArgumentList().AddArguments(SyntaxFactory.Argument((ExpressionSyntax)mappingLambda))), cancellationToken);
return await document.ReplaceNodes(invocation, invocation.WithArgumentList(SyntaxFactory.ArgumentList().AddArguments(SyntaxFactory.Argument((ExpressionSyntax)mappingLambda))), cancellationToken).ConfigureAwait(false);
}

private static bool IsMappingMethod(IMethodSymbol c)
Expand Down Expand Up @@ -188,9 +188,9 @@ private static AnnotatedType GetExpressionType(SemanticModel semanticModel, Synt

private async Task<Document> UseLocalVariablesAsParameters(Document document, IInvocation invocation, bool generateNamedParameters, CancellationToken cancellationToken)
{
var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var mappingSourceFinder = LocalScopeMappingSourceFinder.FromScope(semanticModel, invocation.SourceNode);
return await CodeFixHelper.FixInvocationWithParameters(document, invocation, generateNamedParameters, semanticModel, mappingSourceFinder, cancellationToken);
return await CodeFixHelper.FixInvocationWithParameters(document, invocation, generateNamedParameters, semanticModel, mappingSourceFinder, cancellationToken).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex

private async Task<Document> InitializeWithLocals(Document document, InitializerExpressionSyntax objectInitializer, CancellationToken cancellationToken)
{
var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var syntaxGenerator= SyntaxGenerator.GetGenerator(document);
var sourceFinders = GetAllPossibleSourceFinders(objectInitializer, semanticModel, syntaxGenerator).ToList();
var mappingMatcher = new BestPossibleMatcher(sourceFinders);
return await ReplaceEmptyInitializationBlock(document, objectInitializer, semanticModel, mappingMatcher, cancellationToken);
return await ReplaceEmptyInitializationBlock(document, objectInitializer, semanticModel, mappingMatcher, cancellationToken).ConfigureAwait(false);
}

private static IEnumerable<IMappingSourceFinder> GetAllPossibleSourceFinders(InitializerExpressionSyntax objectInitializer, SemanticModel semanticModel, SyntaxGenerator syntaxGenerator)
Expand Down Expand Up @@ -128,21 +128,21 @@ private static IMappingSourceFinder GetMappingSourceFindersForQueryExpression(Se

private async Task<Document> InitializeWithLambdaParameter(Document document, LambdaExpressionSyntax lambdaSyntax, InitializerExpressionSyntax objectInitializer, CancellationToken cancellationToken)
{
var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var generator = SyntaxGenerator.GetGenerator(document);

var lambdaSymbol = semanticModel.GetSymbolInfo(lambdaSyntax).Symbol as IMethodSymbol;
var firstArgument = lambdaSymbol.Parameters.First();
var mappingSourceFinder = new ObjectMembersMappingSourceFinder(new AnnotatedType(firstArgument.Type), generator.IdentifierName(firstArgument.Name), generator);
return await ReplaceEmptyInitializationBlock(document, objectInitializer, semanticModel, new SingleSourceMatcher(mappingSourceFinder), cancellationToken);
return await ReplaceEmptyInitializationBlock(document, objectInitializer, semanticModel, new SingleSourceMatcher(mappingSourceFinder), cancellationToken).ConfigureAwait(false);
}

private async Task<Document> InitializeWithDefaults(Document document, InitializerExpressionSyntax objectInitializer, CancellationToken cancellationToken)
{
var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var syntaxGenerator = SyntaxGenerator.GetGenerator(document);
var mappingSourceFinder = new ScaffoldingSourceFinder(syntaxGenerator, document);
return await ReplaceEmptyInitializationBlock(document, objectInitializer, semanticModel, new SingleSourceMatcher(mappingSourceFinder), cancellationToken);
return await ReplaceEmptyInitializationBlock(document, objectInitializer, semanticModel, new SingleSourceMatcher(mappingSourceFinder), cancellationToken).ConfigureAwait(false);
}

private static async Task<Document> ReplaceEmptyInitializationBlock(Document document,
Expand All @@ -151,10 +151,10 @@ private static async Task<Document> ReplaceEmptyInitializationBlock(Document doc
{
var oldObjCreation = objectInitializer.FindContainer<ObjectCreationExpressionSyntax>();
var createdObjectType = ModelExtensions.GetTypeInfo(semanticModel, oldObjCreation).Type;
var mappingEngine = await MappingEngine.Create(document, cancellationToken);
var mappingEngine = await MappingEngine.Create(document, cancellationToken).ConfigureAwait(false);

var newObjectCreation = mappingEngine.AddInitializerWithMapping(oldObjCreation, mappingMatcher, createdObjectType, new MappingContext(objectInitializer, semanticModel ));
return await document.ReplaceNodes(oldObjCreation, newObjectCreation, cancellationToken);
return await document.ReplaceNodes(oldObjCreation, newObjectCreation, cancellationToken).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex
private async Task<Document> ImplementCloneMethodBody(Document document, MethodDeclarationSyntax methodDeclaration, CancellationToken cancellationToken)
{
var generator = SyntaxGenerator.GetGenerator(document);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var methodSymbol = semanticModel.GetDeclaredSymbol(methodDeclaration);
var mappingContext = new MappingContext(methodSymbol.ContainingType);
var cloneExpression = CreateCloneExpression(generator, semanticModel, new AnnotatedType(methodSymbol.ReturnType), mappingContext);
return await document.ReplaceNodes(methodDeclaration.Body, ((BaseMethodDeclarationSyntax) generator.MethodDeclaration(methodSymbol, cloneExpression)).Body, cancellationToken);
return await document.ReplaceNodes(methodDeclaration.Body, ((BaseMethodDeclarationSyntax) generator.MethodDeclaration(methodSymbol, cloneExpression)).Body, cancellationToken).ConfigureAwait(false);
}

private bool IsCandidateForCloneMethod(MethodDeclarationSyntax md)
Expand All @@ -65,7 +65,7 @@ private static TypeDeclarationSyntax FindContainingTypeDeclaration(SyntaxNode no
private async Task<Document> AddCloneImplementation(Document document, TypeDeclarationSyntax typeDeclaration, CancellationToken cancellationToken)
{
var generator = SyntaxGenerator.GetGenerator(document);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
//TODO: If method exists, replace it
var newClassDeclaration = typeDeclaration.AddMethods(new[]
{
Expand All @@ -79,7 +79,7 @@ private async Task<Document> AddCloneImplementation(Document document, TypeDecla
newClassDeclaration = generator.AddInterfaceType(newClassDeclaration, cloneableInterface.WithAdditionalAnnotations(Formatter.Annotation)) as TypeDeclarationSyntax;
}

return await document.ReplaceNodes(typeDeclaration, newClassDeclaration, cancellationToken);
return await document.ReplaceNodes(typeDeclaration, newClassDeclaration, cancellationToken).ConfigureAwait(false);
}

private MethodDeclarationSyntax GenerateCloneMethodStronglyTyped(SyntaxGenerator generator,
Expand Down
Loading

0 comments on commit 59846b6

Please sign in to comment.