提交 36f67e0c 编写于 作者: B Brett Forsgren

Merge pull request #1837 from brettfo/navigate-to-invalid-cast

don't assume that a constructor's parent is a TypeBlockSyntax
......@@ -551,6 +551,17 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.NavigateTo
End Using
End Sub
<WorkItem(1834, "https://github.com/dotnet/roslyn/issues/1834")>
<Fact, Trait(Traits.Feature, Traits.Features.NavigateTo)>
Public Sub ConstructorNotParentedByTypeBlock()
Using worker = SetupWorkspace("Module Program", "End Module", "Public Sub New()", "End Sub")
SetupVerifableGlyph(StandardGlyphGroup.GlyphGroupModule, StandardGlyphItem.GlyphItemFriend)
Assert.Equal(0, _aggregator.GetItems("New").Count)
Dim item = _aggregator.GetItems("Program").Single
VerifyNavigateToResultItem(item, "Program", MatchKind.Exact, NavigateToItemKind.Module, displayName:="Program")
End Using
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.NavigateTo)>
Public Sub StartStopSanity()
' Verify that mutliple calls to start/stop don't blow up
......
......@@ -965,6 +965,11 @@ private static string GetFullyQualifiedContainerName(SyntaxNode node)
private static string GetContainer(SyntaxNode node, bool immediate)
{
if (node == null)
{
return string.Empty;
}
var name = GetNodeName(node, includeTypeParameters: immediate);
var names = new List<string> { name };
......
......@@ -739,15 +739,18 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return True
Case SyntaxKind.ConstructorBlock
Dim constructor = CType(node, ConstructorBlockSyntax)
Dim typeBlock = CType(constructor.Parent, TypeBlockSyntax)
declaredSymbolInfo = New DeclaredSymbolInfo(
typeBlock.BlockStatement.Identifier.ValueText,
GetContainerDisplayName(node.Parent),
GetFullyQualifiedContainerName(node.Parent),
DeclaredSymbolInfoKind.Constructor,
constructor.SubNewStatement.NewKeyword.Span,
parameterCount:=CType(If(constructor.SubNewStatement.ParameterList?.Parameters.Count, 0), UShort))
Return True
Dim typeBlock = TryCast(constructor.Parent, TypeBlockSyntax)
If typeBlock IsNot Nothing Then
declaredSymbolInfo = New DeclaredSymbolInfo(
typeBlock.BlockStatement.Identifier.ValueText,
GetContainerDisplayName(node.Parent),
GetFullyQualifiedContainerName(node.Parent),
DeclaredSymbolInfoKind.Constructor,
constructor.SubNewStatement.NewKeyword.Span,
parameterCount:=CType(If(constructor.SubNewStatement.ParameterList?.Parameters.Count, 0), UShort))
Return True
End If
Case SyntaxKind.DelegateFunctionStatement, SyntaxKind.DelegateSubStatement
Dim delegateDecl = CType(node, DelegateStatementSyntax)
declaredSymbolInfo = New DeclaredSymbolInfo(delegateDecl.Identifier.ValueText,
......@@ -846,6 +849,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Function
Private Shared Function GetContainer(node As SyntaxNode, immediate As Boolean) As String
If node Is Nothing Then
Return String.Empty
End If
Dim name = GetNodeName(node, includeTypeParameters:=immediate)
Dim names = New List(Of String) From {name}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册