提交 a950b47f 编写于 作者: P Paul Chen

Fix VB test case and use Simplifier.Annotation

上级 419681b0
......@@ -308,8 +308,8 @@ NewLines("Imports System.Threading.Tasks \n Module M \n Async Function A() As Ta
<Fact(), Trait(Traits.Feature, Traits.Features.CodeActionsAddAwait)>
Public Sub TestCastExpression()
Test(
NewLines("Imports System.Threading.Tasks \n Module M \n Async Function A() As Task(Of Integer) \n Return [|TryCast(Nothing, Task(Of Integer)|] \n End Function \n End Module"),
NewLines("Imports System.Threading.Tasks \n Module M \n Async Function A() As Task(Of Integer) \n Return Await TryCast(Nothing, Task(Of Integer) \n End Function \n End Module"))
NewLines("Imports System.Threading.Tasks \n Module M \n Async Function A() As Task(Of Integer) \n Return [|TryCast(Nothing, Task(Of Integer))|] \n End Function \n End Module"),
NewLines("Imports System.Threading.Tasks \n Module M \n Async Function A() As Task(Of Integer) \n Return Await TryCast(Nothing, Task(Of Integer)) \n End Function \n End Module"))
End Sub
Friend Overrides Function CreateDiagnosticProviderAndFixer(workspace As Workspace) As Tuple(Of DiagnosticAnalyzer, CodeFixProvider)
......
......@@ -115,27 +115,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.Async
End Function
Private Shared Function ConverToAwaitExpression(expression As ExpressionSyntax, semanticModel As SemanticModel, cancellationToken As CancellationToken) As ExpressionSyntax
Dim root = expression.Ancestors().Last()
If Not RequiresParenthesis(expression, root, semanticModel, cancellationToken) Then
expression = expression.Parenthesize()
End If
Return SyntaxFactory.AwaitExpression(expression.WithoutTrivia()) _
.WithTriviaFrom(expression) _
.WithAdditionalAnnotations(Formatter.Annotation, Simplifier.Annotation)
Return SyntaxFactory.AwaitExpression(expression.WithoutTrivia().Parenthesize()) _
.WithTriviaFrom(expression) _
.WithAdditionalAnnotations(Simplifier.Annotation, Formatter.Annotation)
End Function
Private Shared Function RequiresParenthesis(expression As ExpressionSyntax, root As SyntaxNode, semanticModel As SemanticModel, cancellationToken As CancellationToken) As Boolean
Dim parenthesizedExpression = SyntaxFactory.ParenthesizedExpression(expression)
Dim newRoot = root.ReplaceNode(expression, parenthesizedExpression)
Dim newNode = newRoot.FindNode(expression.Span)
Dim result = newNode _
.DescendantNodesAndSelf(Function(n) n.Kind <> SyntaxKind.ParenthesizedExpression) _
.OfType(Of ParenthesizedExpressionSyntax).FirstOrDefault
If result IsNot Nothing Then
Return Not result.CanRemoveParentheses(semanticModel, cancellationToken)
End If
Return False
End Function
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册