提交 f0e90350 编写于 作者: M Manish Vasani

Fix VB test helper to find prefix text matches

This is needed when we want to find IOperation for a multiline syntax node, but the 'BIND annotation can only contain the first line of the text.
Fixes #18047
上级 2ba0d8f2
......@@ -444,21 +444,23 @@ Friend Module CompilationUtils
Return s
End Function
Public Function FindBindingText(Of TNode As SyntaxNode)(compilation As Compilation, fileName As String, Optional which As Integer = 0) As TNode
Public Function FindBindingText(Of TNode As SyntaxNode)(compilation As Compilation, fileName As String, Optional which As Integer = 0, Optional prefixMatch As Boolean = False) As TNode
Dim tree = (From t In compilation.SyntaxTrees Where t.FilePath = fileName).Single()
Dim bindText As String = Nothing
Dim bindPoint = FindBindingTextPosition(compilation, fileName, bindText, which)
Dim token = tree.GetRoot().FindToken(bindPoint, True)
Dim node = token.Parent
Dim hasMatchingText As Func(Of SyntaxNode, Boolean) = Function(n) n.ToString = bindText OrElse
(prefixMatch AndAlso TryCast(n, TNode) IsNot Nothing AndAlso n.ToString.StartsWith(bindText))
While (node IsNot Nothing AndAlso node.ToString <> bindText)
While (node IsNot Nothing AndAlso Not hasMatchingText(node))
node = node.Parent
End While
If node IsNot Nothing Then
While TryCast(node, TNode) Is Nothing
If node.Parent IsNot Nothing AndAlso node.Parent.ToString = bindText Then
If node.Parent IsNot Nothing AndAlso hasMatchingText(node.Parent) Then
node = node.Parent
Else
Exit While
......@@ -468,7 +470,12 @@ Friend Module CompilationUtils
Assert.NotNull(node) ' If this trips, then node wasn't found
Assert.IsAssignableFrom(GetType(TNode), node)
Assert.Equal(bindText, node.ToString())
If Not prefixMatch Then
Assert.Equal(bindText, node.ToString())
Else
Assert.StartsWith(bindText, node.ToString)
End If
Return DirectCast(node, TNode)
End Function
......
......@@ -153,7 +153,7 @@ Public MustInherit Class SemanticModelTestBase : Inherits BasicTestBase
End Function
Friend Function GetOperationTreeForTest(Of TSyntaxNode As SyntaxNode)(compilation As VisualBasicCompilation, fileName As String, Optional which As Integer = 0) As String
Dim node As SyntaxNode = CompilationUtils.FindBindingText(Of TSyntaxNode)(compilation, fileName, which)
Dim node As SyntaxNode = CompilationUtils.FindBindingText(Of TSyntaxNode)(compilation, fileName, which, prefixMatch:=True)
If node Is Nothing Then
Return Nothing
End If
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册