提交 c7423cb8 编写于 作者: D Dustin Campbell

Fix VB member body span used to determine whether speculative binding should be used

To determine whether or not speculative binding should be used, GetSemanticModelForSpanAsync calls into ISyntaxFactsService.GetMemberBodySpanForSpeculativeBinding(). In VB, the span returned by this method started from the end of the block statement to the start of the end block statement. However, for VB, the span should start after the block statement's terminator. Otherwise, a member body speculative semantic model will likey be returned when the requested span is within the trivia after the block statement but before the statement terminator. E.g.

Sub M() |

End Sub
上级 f19d3eac
......@@ -173,5 +173,23 @@ End Class
VerifyNoItemsExist(code)
End Sub
<WorkItem(4167, "https://github.com/dotnet/roslyn/issues/4167")>
<Fact(), Trait(Traits.Feature, Traits.Features.KeywordRecommending)>
Public Sub ImplementsAfterSub()
Dim code = "
Interface I
End Interface
Class C
Implements I
Sub M() $$
End Sub
End Class
"
VerifyItemExists(code, "Implements")
End Sub
End Class
End Namespace
......@@ -662,7 +662,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return Nothing
End If
Return TextSpan.FromBounds(method.BlockStatement.Span.End, method.EndBlockStatement.SpanStart)
' We don't want to include the BlockStatement or any trailing trivia up to and including its statement
' terminator in the span. Instead, we use the start of the first statement's leading trivia (if any) up
' to the start of the EndBlockStatement. If there aren't any statements in the block, we use the start
' of the EndBlockStatements leading trivia.
Dim firstStatement = method.Statements.FirstOrDefault()
Dim spanStart = If(firstStatement IsNot Nothing,
firstStatement.FullSpan.Start,
method.EndBlockStatement.FullSpan.Start)
Return TextSpan.FromBounds(spanStart, method.EndBlockStatement.SpanStart)
End If
Return Nothing
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册