Skip to content

Commit 775fd4a

Browse files
committed
Fix async warnings
1 parent cadb568 commit 775fd4a

File tree

6 files changed

+22
-21
lines changed

6 files changed

+22
-21
lines changed

Roslyn.Testing/Analyzer/DiagnosticVerifier.Helpers.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ protected static Diagnostic[] GetSortedDiagnosticsFromDocuments(ImmutableArray<D
8484

8585
foreach (var project in projects)
8686
{
87-
var compilationWithAnalyzers = project.GetCompilationAsync().Result.WithAnalyzers(analyzers);
88-
var diags = compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().Result;
87+
var compilationWithAnalyzers = project.GetCompilationAsync().GetAwaiter().GetResult().WithAnalyzers(analyzers);
88+
var diags = compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().GetAwaiter().GetResult();
8989

9090
foreach (var diag in diags)
9191
{
@@ -97,7 +97,7 @@ protected static Diagnostic[] GetSortedDiagnosticsFromDocuments(ImmutableArray<D
9797
for (var i = 0; i < documents.Length; i++)
9898
{
9999
var document = documents[i];
100-
var tree = document.GetSyntaxTreeAsync().Result;
100+
var tree = document.GetSyntaxTreeAsync().GetAwaiter().GetResult();
101101

102102
if (tree == diag.Location.SourceTree)
103103
{

Roslyn.Testing/Analyzer/DiagnosticVerifier.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public static Diagnostic[] GetSortedDiagnosticsFromDocuments(this DiagnosticAnal
8585
foreach (var project in projects)
8686
{
8787
var compilationWithAnalyzers =
88-
project.GetCompilationAsync().Result.WithAnalyzers(ImmutableArray.Create(analyzer));
88+
project.GetCompilationAsync().GetAwaiter().GetResult().WithAnalyzers(ImmutableArray.Create(analyzer));
8989

90-
var diags = compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().Result;
90+
var diags = compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().GetAwaiter().GetResult();
9191

9292
foreach (var diag in diags)
9393
{
@@ -98,7 +98,7 @@ public static Diagnostic[] GetSortedDiagnosticsFromDocuments(this DiagnosticAnal
9898
{
9999
foreach (var document in documents)
100100
{
101-
var tree = document.GetSyntaxTreeAsync().Result;
101+
var tree = document.GetSyntaxTreeAsync().GetAwaiter().GetResult();
102102

103103
if (tree == diag.Location.SourceTree)
104104
{

Roslyn.Testing/CodeFix/CodeFixProviderTestExtensions.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal static class CodeFixProviderTestExtensions
2323
/// <returns> A Document with the changes from the CodeAction </returns>
2424
public static Document ApplyFix(this Document document, CodeAction codeAction)
2525
{
26-
var operations = codeAction.GetOperationsAsync(CancellationToken.None).Result;
26+
var operations = codeAction.GetOperationsAsync(CancellationToken.None).GetAwaiter().GetResult();
2727
var solution = operations.OfType<ApplyChangesOperation>().Single().ChangedSolution;
2828

2929
return solution.GetDocument(document.Id);
@@ -81,7 +81,7 @@ public static VerifyCodeFixProviderResult VerifyFix(this CodeFixProvider codeFix
8181
{
8282
var actions = new List<CodeAction>();
8383
var context = new CodeFixContext(document, analyzerDiagnostics[0], (a, d) => actions.Add(a), CancellationToken.None);
84-
codeFixProvider.RegisterCodeFixesAsync(context).Wait();
84+
codeFixProvider.RegisterCodeFixesAsync(context).GetAwaiter().GetResult();
8585

8686
if (!actions.Any())
8787
{
@@ -104,12 +104,12 @@ public static VerifyCodeFixProviderResult VerifyFix(this CodeFixProvider codeFix
104104
if (!allowNewCompilerDiagnostics && newCompilerDiagnostics.Any())
105105
{
106106
// Format and get the compiler diagnostics again so that the locations make sense in the output
107-
document = document.WithSyntaxRoot(Formatter.Format(document.GetSyntaxRootAsync().Result,
107+
document = document.WithSyntaxRoot(Formatter.Format(document.GetSyntaxRootAsync().GetAwaiter().GetResult(),
108108
Formatter.Annotation,
109109
document.Project.Solution.Workspace));
110110

111111
newCompilerDiagnostics = GetNewDiagnostics(compilerDiagnostics, document.GetCompilerDiagnostics());
112-
var msg = GetNewComilerDiagnosticsIntroducedMessage(document, newCompilerDiagnostics);
112+
var msg = GetNewCompilerDiagnosticsIntroducedMessage(document, newCompilerDiagnostics);
113113

114114
return VerifyCodeFixProviderResult.Fail(msg);
115115
}
@@ -129,10 +129,10 @@ public static VerifyCodeFixProviderResult VerifyFix(this CodeFixProvider codeFix
129129
: VerifyCodeFixProviderResult.Fail(newSource, actual);
130130
}
131131

132-
private static string GetNewComilerDiagnosticsIntroducedMessage(Document document, IEnumerable<Diagnostic> newCompilerDiagnostics)
132+
private static string GetNewCompilerDiagnosticsIntroducedMessage(Document document, IEnumerable<Diagnostic> newCompilerDiagnostics)
133133
{
134134
return
135-
$"Fix introduced new compiler diagnostics:{Environment.NewLine}{string.Join("{Environment.NewLine}", newCompilerDiagnostics.Select(d => d.ToString()))}{Environment.NewLine}{Environment.NewLine}New document:{Environment.NewLine}{document.GetSyntaxRootAsync().Result.ToFullString()}{Environment.NewLine}";
135+
$"Fix introduced new compiler diagnostics:{Environment.NewLine}{string.Join("{Environment.NewLine}", newCompilerDiagnostics.Select(d => d.ToString()))}{Environment.NewLine}{Environment.NewLine}New document:{Environment.NewLine}{document.GetSyntaxRootAsync().GetAwaiter().GetResult().ToFullString()}{Environment.NewLine}";
136136
}
137137

138138
/// <summary>
@@ -145,7 +145,7 @@ private static string GetNewComilerDiagnosticsIntroducedMessage(Document documen
145145
/// <returns> The compiler diagnostics that were found in the code </returns>
146146
private static IEnumerable<Diagnostic> GetCompilerDiagnostics(this Document document)
147147
{
148-
return document.GetSemanticModelAsync().Result.GetDiagnostics();
148+
return document.GetSemanticModelAsync().GetAwaiter().GetResult().GetDiagnostics();
149149
}
150150

151151
/// <summary>
@@ -155,8 +155,8 @@ private static IEnumerable<Diagnostic> GetCompilerDiagnostics(this Document docu
155155
/// <returns> A string containing the syntax of the Document after formatting </returns>
156156
public static string GetStringFromDocument(this Document document)
157157
{
158-
var simplifiedDoc = Simplifier.ReduceAsync(document, Simplifier.Annotation).Result;
159-
var root = simplifiedDoc.GetSyntaxRootAsync().Result;
158+
var simplifiedDoc = Simplifier.ReduceAsync(document, Simplifier.Annotation).GetAwaiter().GetResult();
159+
var root = simplifiedDoc.GetSyntaxRootAsync().GetAwaiter().GetResult();
160160
root = Formatter.Format(root, Formatter.Annotation, simplifiedDoc.Project.Solution.Workspace);
161161

162162
return root.GetText().ToString();

Roslyn.Testing/Roslyn.Testing.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<LangVersion>7.2</LangVersion>
5+
<LangVersion>latest</LangVersion>
66
</PropertyGroup>
77

88
<ItemGroup>

System.IO.Abstractions.Analyzers.Tests/System.IO.Abstractions.Analyzers.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>

System.IO.Abstractions.Analyzers/System.IO.Abstractions.Analyzers.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard1.4</TargetFramework>
4+
<TargetFramework>netstandard2.0</TargetFramework>
55
<PackageTargetFallback>portable-net45+win8+wp8+wpa81</PackageTargetFallback>
66
<IncludeBuildOutput>false</IncludeBuildOutput>
77
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
8+
<LangVersion>latest</LangVersion>
89
</PropertyGroup>
910
<PropertyGroup>
1011
<PackageId>Roslyn.System.IO.Abstractions.Analyzers</PackageId>
@@ -32,9 +33,9 @@
3233
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.1" PrivateAssets="all" />
3334
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.7.0" PrivateAssets="all" />
3435
<PackageReference Update="NETStandard.Library" PrivateAssets="all" />
35-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0" PrivateAssets="all" />
36-
<PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="3.3.0" PrivateAssets="all" />
37-
<PackageReference Include="Roslyn.Diagnostics.Analyzers" Version="3.3.0" PrivateAssets="all" />
36+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1" PrivateAssets="all" />
37+
<PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="3.3.1" PrivateAssets="all" />
38+
<PackageReference Include="Roslyn.Diagnostics.Analyzers" Version="3.3.1" PrivateAssets="all" />
3839
</ItemGroup>
3940
<ItemGroup>
4041
<None Update="tools\*.ps1" CopyToOutputDirectory="Always" Pack="true" PackagePath="" />

0 commit comments

Comments
 (0)