diff --git a/src/Sharpen.Engine/DisplayText.cs b/src/Sharpen.Engine/DisplayText.cs index ebe1e9b..ff33bbd 100644 --- a/src/Sharpen.Engine/DisplayText.cs +++ b/src/Sharpen.Engine/DisplayText.cs @@ -1,7 +1,4 @@ -#if DEBUG -using System; -#endif -using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -17,28 +14,15 @@ public static string For(SyntaxNode syntaxNode) case SyntaxKind.ConstructorDeclaration: return For((ConstructorDeclarationSyntax)syntaxNode); case SyntaxKind.PropertyDeclaration: return For((PropertyDeclarationSyntax)syntaxNode); case SyntaxKind.IndexerDeclaration: return For((IndexerDeclarationSyntax)syntaxNode); - case SyntaxKind.ReturnStatement: return syntaxNode.ToString(); - case SyntaxKind.Parameter: return syntaxNode.ToString(); - case SyntaxKind.Argument: return syntaxNode.ToString(); - case SyntaxKind.InvocationExpression: return syntaxNode.ToString(); case SyntaxKind.LocalFunctionStatement: return For((LocalFunctionStatementSyntax)syntaxNode); - case SyntaxKind.ObjectCreationExpression: return syntaxNode.ToString(); - case SyntaxKind.SimpleMemberAccessExpression: return syntaxNode.ToString(); - // In general, we want to have a proper customized representation for each - // of the known nodes. Still, since sometimes we do display arbitrary nodes - // we will need the fallback to generic display in the release build. - // During debugging, let it crash so that we can extend the list with additional - // known cases, even if we will choose that they have a generic display. - #if DEBUG - default: - throw new ArgumentOutOfRangeException - ( - nameof(syntaxNode), - $"Getting the display text for the syntax node of type {syntaxNode.GetType().Name} is currently not supported." - ); - #else + case SyntaxKind.ReturnStatement: + case SyntaxKind.Parameter: + case SyntaxKind.Argument: + case SyntaxKind.InvocationExpression: + case SyntaxKind.ObjectCreationExpression: + case SyntaxKind.SimpleMemberAccessExpression: + case SyntaxKind.EqualsValueClause: return syntaxNode.ToString(); default: return syntaxNode.ToString(); - #endif } } diff --git a/src/Sharpen.Engine/SharpenSuggestions/CSharp50/AsyncAwait/BaseAwaitKnownAsynchronousEquivalentInsteadOfCallingSynchronousMember.cs b/src/Sharpen.Engine/SharpenSuggestions/CSharp50/AsyncAwait/BaseAwaitKnownAsynchronousEquivalentInsteadOfCallingSynchronousMember.cs index 80e482b..b6e7ead 100644 --- a/src/Sharpen.Engine/SharpenSuggestions/CSharp50/AsyncAwait/BaseAwaitKnownAsynchronousEquivalentInsteadOfCallingSynchronousMember.cs +++ b/src/Sharpen.Engine/SharpenSuggestions/CSharp50/AsyncAwait/BaseAwaitKnownAsynchronousEquivalentInsteadOfCallingSynchronousMember.cs @@ -62,7 +62,7 @@ public IEnumerable Analyze(SyntaxTree syntaxTree, SemanticModel analysisContext, syntaxTree.FilePath, GetStartingSyntaxNode(node).GetFirstToken(), - node + node.FirstAncestorOrSelf() ?? node )); bool InvokedMemberHasAsynchronousEquivalentThatCanBeAwaited(SyntaxNode invocation) diff --git a/tests/smoke/CSharp50/AsyncAwait/AwaitTaskDelayInsteadOfCallingThreadSleep/TaskDelayCannotBeAwaitedInsteadOfCallingThreadSleep.cs b/tests/smoke/CSharp50/AsyncAwait/AwaitTaskDelayInsteadOfCallingThreadSleep/TaskDelayCannotBeAwaitedInsteadOfCallingThreadSleep.cs index 7b9ada5..cdca951 100644 --- a/tests/smoke/CSharp50/AsyncAwait/AwaitTaskDelayInsteadOfCallingThreadSleep/TaskDelayCannotBeAwaitedInsteadOfCallingThreadSleep.cs +++ b/tests/smoke/CSharp50/AsyncAwait/AwaitTaskDelayInsteadOfCallingThreadSleep/TaskDelayCannotBeAwaitedInsteadOfCallingThreadSleep.cs @@ -1,5 +1,6 @@ // ReSharper disable All +using System; using System.Threading; using static System.Threading.Thread; @@ -12,5 +13,14 @@ void CannotBeAwaited() Thread.Sleep(0); Sleep(0); } + + async void CannotBeAwaitedSoFarBecauseOfLambda() + { + Action a = () => + { + Thread.Sleep(0); + Sleep(0); + }; + } } } \ No newline at end of file diff --git a/tests/smoke/CSharp50/AsyncAwait/AwaitTaskInsteadOfCallingTaskResult/TaskCanBeAwaitedInsteadOfCallingTaskResult.cs b/tests/smoke/CSharp50/AsyncAwait/AwaitTaskInsteadOfCallingTaskResult/TaskCanBeAwaitedInsteadOfCallingTaskResult.cs index 7d05f82..0a31785 100644 --- a/tests/smoke/CSharp50/AsyncAwait/AwaitTaskInsteadOfCallingTaskResult/TaskCanBeAwaitedInsteadOfCallingTaskResult.cs +++ b/tests/smoke/CSharp50/AsyncAwait/AwaitTaskInsteadOfCallingTaskResult/TaskCanBeAwaitedInsteadOfCallingTaskResult.cs @@ -13,9 +13,9 @@ async void CanBeAwaited() var task = new Task(() => 0); var result = task.Result; result = task.Result + 100; - Method(task.Result); + SomeMethod(task.Result); } - void Method(int i) { } + void SomeMethod(int i) { } } } \ No newline at end of file diff --git a/tests/smoke/CSharp50/AsyncAwait/AwaitTaskInsteadOfCallingTaskWait/TaskCanBeAwaitedInsteadOfCallingTaskWait.cs b/tests/smoke/CSharp50/AsyncAwait/AwaitTaskInsteadOfCallingTaskWait/TaskCanBeAwaitedInsteadOfCallingTaskWait.cs index 88acd23..74cce6e 100644 --- a/tests/smoke/CSharp50/AsyncAwait/AwaitTaskInsteadOfCallingTaskWait/TaskCanBeAwaitedInsteadOfCallingTaskWait.cs +++ b/tests/smoke/CSharp50/AsyncAwait/AwaitTaskInsteadOfCallingTaskWait/TaskCanBeAwaitedInsteadOfCallingTaskWait.cs @@ -1,6 +1,6 @@ // ReSharper disable All -// Expected number of suggestions: 1 +// Expected number of suggestions: 3 using System.Threading.Tasks; @@ -12,6 +12,9 @@ async void CanBeAwaited() { var task = new Task(() => {}); task.Wait(0); + task.Wait(1 + 2 + 2); + int wait = 100; + task.Wait(wait); } } } \ No newline at end of file diff --git a/tests/smoke/CSharp50/AsyncAwait/AwaitTaskWhenAllInsteadOfCallingTaskWaitAll/TaskWhenAllCanBeAwaitedInsteadOfCallingTaskWaitAll.cs b/tests/smoke/CSharp50/AsyncAwait/AwaitTaskWhenAllInsteadOfCallingTaskWaitAll/TaskWhenAllCanBeAwaitedInsteadOfCallingTaskWaitAll.cs index 341e20e..83c1143 100644 --- a/tests/smoke/CSharp50/AsyncAwait/AwaitTaskWhenAllInsteadOfCallingTaskWaitAll/TaskWhenAllCanBeAwaitedInsteadOfCallingTaskWaitAll.cs +++ b/tests/smoke/CSharp50/AsyncAwait/AwaitTaskWhenAllInsteadOfCallingTaskWaitAll/TaskWhenAllCanBeAwaitedInsteadOfCallingTaskWaitAll.cs @@ -1,6 +1,6 @@ // ReSharper disable All -// Expected number of suggestions: 2 +// Expected number of suggestions: 3 using System.Threading.Tasks; using static System.Threading.Tasks.Task; @@ -13,6 +13,7 @@ async void CanBeAwaited() { Task.WaitAll(null); WaitAll(null); + System.Threading.Tasks.Task.WaitAll(new Task[0]); } } } \ No newline at end of file diff --git a/tests/smoke/CSharp50/AsyncAwait/AwaitTaskWhenAnyInsteadOfCallingTaskWaitAny/TaskWhenAnyCanBeAwaitedInsteadOfCallingTaskWaitAny.cs b/tests/smoke/CSharp50/AsyncAwait/AwaitTaskWhenAnyInsteadOfCallingTaskWaitAny/TaskWhenAnyCanBeAwaitedInsteadOfCallingTaskWaitAny.cs index aaf3266..a0f7d0c 100644 --- a/tests/smoke/CSharp50/AsyncAwait/AwaitTaskWhenAnyInsteadOfCallingTaskWaitAny/TaskWhenAnyCanBeAwaitedInsteadOfCallingTaskWaitAny.cs +++ b/tests/smoke/CSharp50/AsyncAwait/AwaitTaskWhenAnyInsteadOfCallingTaskWaitAny/TaskWhenAnyCanBeAwaitedInsteadOfCallingTaskWaitAny.cs @@ -1,6 +1,6 @@ // ReSharper disable All -// Expected number of suggestions: 2 +// Expected number of suggestions: 4 using System.Threading.Tasks; using static System.Threading.Tasks.Task; @@ -13,6 +13,8 @@ async void CanBeAwaited() { Task.WaitAny(null); WaitAny(null); + System.Threading.Tasks.Task.WaitAny(new Task[0]); + int value = WaitAny(null, 1000); } } } \ No newline at end of file