Skip to content

Commit 7146a57

Browse files
committed
Merge pull request #31 from sharwell/fix-30
Use ConfigureAwait(false) for all await operations in this library
2 parents 7547d65 + 836bf33 commit 7146a57

9 files changed

+24
-24
lines changed

OpenStackNetAnalyzers/OpenStackNetAnalyzers.Test/Helpers/CodeFixVerifier.Helper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static async Task<ImmutableArray<Diagnostic>> GetCompilerDiagnosticsAsyn
9090
private static async Task<string> GetStringFromDocumentAsync(Document document, CancellationToken cancellationToken)
9191
{
9292
var simplifiedDoc = await Simplifier.ReduceAsync(document, Simplifier.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false);
93-
var formatted = await Formatter.FormatAsync(simplifiedDoc, Formatter.Annotation, cancellationToken: cancellationToken);
93+
var formatted = await Formatter.FormatAsync(simplifiedDoc, Formatter.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false);
9494
var sourceText = await formatted.GetTextAsync(cancellationToken).ConfigureAwait(false);
9595
return sourceText.ToString();
9696
}

OpenStackNetAnalyzers/OpenStackNetAnalyzers.Test/Verifiers/CodeFixVerifier.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ protected virtual CodeFixProvider GetBasicCodeFixProvider()
8585
private async Task VerifyFixAsync(string language, DiagnosticAnalyzer analyzer, CodeFixProvider codeFixProvider, string oldSource, string newSource, int? codeFixIndex, bool allowNewCompilerDiagnostics, CancellationToken cancellationToken)
8686
{
8787
var document = CreateDocument(oldSource, language);
88-
var analyzerDiagnostics = await GetSortedDiagnosticsFromDocumentsAsync(analyzer, new[] { document }, cancellationToken);
89-
var compilerDiagnostics = await GetCompilerDiagnosticsAsync(document, cancellationToken);
88+
var analyzerDiagnostics = await GetSortedDiagnosticsFromDocumentsAsync(analyzer, new[] { document }, cancellationToken).ConfigureAwait(false);
89+
var compilerDiagnostics = await GetCompilerDiagnosticsAsync(document, cancellationToken).ConfigureAwait(false);
9090
var attempts = analyzerDiagnostics.Length;
9191

9292
for (int i = 0; i < attempts; ++i)
@@ -107,15 +107,15 @@ private async Task VerifyFixAsync(string language, DiagnosticAnalyzer analyzer,
107107
}
108108

109109
document = await ApplyFixAsync(document, actions.ElementAt(0), cancellationToken).ConfigureAwait(false);
110-
analyzerDiagnostics = await GetSortedDiagnosticsFromDocumentsAsync(analyzer, new[] { document }, cancellationToken);
110+
analyzerDiagnostics = await GetSortedDiagnosticsFromDocumentsAsync(analyzer, new[] { document }, cancellationToken).ConfigureAwait(false);
111111

112112
var newCompilerDiagnostics = GetNewDiagnostics(compilerDiagnostics, await GetCompilerDiagnosticsAsync(document, cancellationToken).ConfigureAwait(false));
113113

114114
//check if applying the code fix introduced any new compiler diagnostics
115115
if (!allowNewCompilerDiagnostics && newCompilerDiagnostics.Any())
116116
{
117117
// Format and get the compiler diagnostics again so that the locations make sense in the output
118-
document = await Formatter.FormatAsync(document, Formatter.Annotation, cancellationToken: cancellationToken);
118+
document = await Formatter.FormatAsync(document, Formatter.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false);
119119
newCompilerDiagnostics = GetNewDiagnostics(compilerDiagnostics, await GetCompilerDiagnosticsAsync(document, cancellationToken).ConfigureAwait(false));
120120

121121
Assert.IsTrue(false,

OpenStackNetAnalyzers/OpenStackNetAnalyzers.Test/Verifiers/DiagnosticVerifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected Task VerifyBasicDiagnosticAsync(string[] sources, DiagnosticResult[] e
112112
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that the task will observe.</param>
113113
private async Task VerifyDiagnosticsAsync(string[] sources, string language, DiagnosticAnalyzer analyzer, DiagnosticResult[] expected, CancellationToken cancellationToken)
114114
{
115-
var diagnostics = await GetSortedDiagnosticsAsync(sources, language, analyzer, cancellationToken);
115+
var diagnostics = await GetSortedDiagnosticsAsync(sources, language, analyzer, cancellationToken).ConfigureAwait(false);
116116
VerifyDiagnosticResults(diagnostics, analyzer, expected);
117117
}
118118

OpenStackNetAnalyzers/OpenStackNetAnalyzers/DocumentDelegatingApiCallCodeFix.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3434
if (!string.Equals(diagnostic.Id, DocumentDelegatingApiCallAnalyzer.DiagnosticId, StringComparison.Ordinal))
3535
continue;
3636

37-
var documentRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken);
37+
var documentRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
3838
SyntaxNode syntax = documentRoot.FindNode(diagnostic.Location.SourceSpan);
3939
if (syntax == null)
4040
continue;
@@ -52,7 +52,7 @@ private async Task<Document> CreateChangedDocument(CodeFixContext context, Class
5252
{
5353
string serviceInterfaceName = "IUnknownService";
5454
string serviceExtensionsClassName = "UnknownServiceExtensions";
55-
INamedTypeSymbol serviceInterface = await GetServiceInterfaceAsync(context, classDeclarationSyntax, cancellationToken);
55+
INamedTypeSymbol serviceInterface = await GetServiceInterfaceAsync(context, classDeclarationSyntax, cancellationToken).ConfigureAwait(false);
5656
if (serviceInterface != null)
5757
{
5858
serviceInterfaceName = serviceInterface.MetadataName;
@@ -72,8 +72,8 @@ private async Task<Document> CreateChangedDocument(CodeFixContext context, Class
7272

7373
ClassDeclarationSyntax newClassDeclaration = classDeclarationSyntax;
7474

75-
ConstructorDeclarationSyntax constructor = await FindApiCallConstructorAsync(context, classDeclarationSyntax, cancellationToken);
76-
ConstructorDeclarationSyntax newConstructor = await DocumentConstructorAsync(context, constructor, cancellationToken);
75+
ConstructorDeclarationSyntax constructor = await FindApiCallConstructorAsync(context, classDeclarationSyntax, cancellationToken).ConfigureAwait(false);
76+
ConstructorDeclarationSyntax newConstructor = await DocumentConstructorAsync(context, constructor, cancellationToken).ConfigureAwait(false);
7777
if (newConstructor != null)
7878
newClassDeclaration = newClassDeclaration.ReplaceNode(constructor, newConstructor);
7979

@@ -97,7 +97,7 @@ private async Task<Document> CreateChangedDocument(CodeFixContext context, Class
9797
SyntaxTrivia documentationTrivia = SyntaxFactory.Trivia(documentationComment);
9898
newClassDeclaration = newClassDeclaration.WithLeadingTrivia(newClassDeclaration.GetLeadingTrivia().Add(documentationTrivia));
9999

100-
SyntaxNode root = await context.Document.GetSyntaxRootAsync(cancellationToken);
100+
SyntaxNode root = await context.Document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
101101
SyntaxNode newRoot = root.ReplaceNode(classDeclarationSyntax, newClassDeclaration);
102102
return context.Document.WithSyntaxRoot(newRoot);
103103
}
@@ -107,7 +107,7 @@ private async Task<ConstructorDeclarationSyntax> DocumentConstructorAsync(CodeFi
107107
if (constructor == null)
108108
return null;
109109

110-
SemanticModel semanticModel = await context.Document.GetSemanticModelAsync(cancellationToken);
110+
SemanticModel semanticModel = await context.Document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
111111
INamedTypeSymbol apiCallClass = semanticModel.GetDeclaredSymbol(constructor.FirstAncestorOrSelf<ClassDeclarationSyntax>(), cancellationToken);
112112
string parameterName = constructor.ParameterList.Parameters[0].Identifier.ValueText;
113113

@@ -163,7 +163,7 @@ private async Task<ConstructorDeclarationSyntax> FindApiCallConstructorAsync(Cod
163163
continue;
164164

165165
if (semanticModel == null)
166-
semanticModel = await context.Document.GetSemanticModelAsync(cancellationToken);
166+
semanticModel = await context.Document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
167167

168168
INamedTypeSymbol symbol = semanticModel.GetSymbolInfo(parameterType, cancellationToken).Symbol as INamedTypeSymbol;
169169
if (symbol == null || !symbol.IsGenericType)
@@ -233,7 +233,7 @@ private string ExtractServiceName(INamedTypeSymbol serviceInterface)
233233

234234
private async Task<INamedTypeSymbol> GetServiceInterfaceAsync(CodeFixContext context, ClassDeclarationSyntax classDeclarationSyntax, CancellationToken cancellationToken)
235235
{
236-
SemanticModel semanticModel = await context.Document.GetSemanticModelAsync(cancellationToken);
236+
SemanticModel semanticModel = await context.Document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
237237
INamedTypeSymbol apiCallSymbol = semanticModel.GetDeclaredSymbol(classDeclarationSyntax, cancellationToken);
238238
foreach (INamedTypeSymbol type in apiCallSymbol.ContainingNamespace.GetTypeMembers())
239239
{

OpenStackNetAnalyzers/OpenStackNetAnalyzers/DocumentValueFromSummaryCodeFix.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3333
if (!string.Equals(diagnostic.Id, DocumentValueFromSummaryAnalyzer.DiagnosticId, StringComparison.Ordinal))
3434
continue;
3535

36-
var documentRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken);
36+
var documentRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
3737
SyntaxNode syntax = documentRoot.FindNode(diagnostic.Location.SourceSpan);
3838
if (syntax == null)
3939
continue;
@@ -103,7 +103,7 @@ private async Task<Document> CreateChangedDocument(CodeFixContext context, Prope
103103
}
104104

105105
string defaultValueToken = "NullIfNotIncluded";
106-
SemanticModel semanticModel = await context.Document.GetSemanticModelAsync(cancellationToken);
106+
SemanticModel semanticModel = await context.Document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
107107
IPropertySymbol propertySymbol = semanticModel.GetDeclaredSymbol(propertyDeclarationSyntax);
108108
if (propertySymbol != null)
109109
{
@@ -138,7 +138,7 @@ private async Task<Document> CreateChangedDocument(CodeFixContext context, Prope
138138
leadingNewLine,
139139
valueElement)));
140140

141-
SyntaxNode root = await context.Document.GetSyntaxRootAsync(cancellationToken);
141+
SyntaxNode root = await context.Document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
142142
SyntaxNode newRoot = root.ReplaceNode(documentationComment, newDocumentationComment);
143143
return context.Document.WithSyntaxRoot(newRoot);
144144
}

OpenStackNetAnalyzers/OpenStackNetAnalyzers/ImplementBuilderPatternCodeFix.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3535
if (!string.Equals(diagnostic.Id, ImplementBuilderPatternAnalyzer.DiagnosticId, StringComparison.Ordinal))
3636
continue;
3737

38-
var documentRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken);
38+
var documentRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
3939
SyntaxNode syntax = documentRoot.FindNode(diagnostic.Location.SourceSpan);
4040
if (syntax == null)
4141
continue;
@@ -95,7 +95,7 @@ private async Task<Solution> CreateChangedSolution(CodeFixContext context, Class
9595
if (extensionsDocument == null)
9696
return solution;
9797

98-
SyntaxNode extensionsRoot = await extensionsDocument.GetSyntaxRootAsync(cancellationToken);
98+
SyntaxNode extensionsRoot = await extensionsDocument.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
9999
ClassDeclarationSyntax extensionsClass = extensionsRoot.FindNode(location.SourceSpan, getInnermostNodeForTie: true).FirstAncestorOrSelf<ClassDeclarationSyntax>();
100100
if (extensionsClass == null)
101101
return solution;

OpenStackNetAnalyzers/OpenStackNetAnalyzers/JsonObjectOptInCodeFix.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3434
if (!string.Equals(diagnostic.Id, JsonObjectOptInAnalyzer.DiagnosticId, StringComparison.Ordinal))
3535
continue;
3636

37-
var documentRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken);
37+
var documentRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
3838
AttributeSyntax syntax = documentRoot.FindNode(diagnostic.Location.SourceSpan) as AttributeSyntax;
3939
if (syntax == null)
4040
continue;
@@ -76,7 +76,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
7676
continue;
7777

7878
if (semanticModel == null)
79-
semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken);
79+
semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
8080

8181
if (IsMemberSerializationArgument(semanticModel, attributeArgument.Expression, context.CancellationToken))
8282
{

OpenStackNetAnalyzers/OpenStackNetAnalyzers/JsonPropertyDefaultValueHandlingCodeFix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3232
if (!string.Equals(diagnostic.Id, JsonPropertyDefaultValueHandlingAnalyzer.DiagnosticId, StringComparison.Ordinal))
3333
continue;
3434

35-
var documentRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken);
35+
var documentRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
3636
AttributeSyntax syntax = documentRoot.FindNode(diagnostic.Location.SourceSpan) as AttributeSyntax;
3737
if (syntax == null)
3838
continue;

OpenStackNetAnalyzers/OpenStackNetAnalyzers/PlaceholderDocumentationCodeFix.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
3232
if (!string.Equals(diagnostic.Id, PlaceholderDocumentationAnalyzer.DiagnosticId, StringComparison.Ordinal))
3333
continue;
3434

35-
var documentRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken);
35+
var documentRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
3636
SyntaxNode syntax = documentRoot.FindNode(diagnostic.Location.SourceSpan, findInsideTrivia: true, getInnermostNodeForTie: true);
3737
if (syntax == null)
3838
continue;
@@ -71,7 +71,7 @@ private async Task<Document> CreateChangedDocument(CodeFixContext context, XmlEl
7171
trailingTrivia = trailingTrivia.AddRange(elementSyntax.EndTag.GetTrailingTrivia());
7272
content = content.Replace(content[content.Count - 1], content[content.Count - 1].WithTrailingTrivia(trailingTrivia));
7373

74-
SyntaxNode root = await context.Document.GetSyntaxRootAsync(cancellationToken);
74+
SyntaxNode root = await context.Document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
7575
SyntaxNode newRoot = root.ReplaceNode(elementSyntax, content);
7676
return context.Document.WithSyntaxRoot(newRoot);
7777
}

0 commit comments

Comments
 (0)