提交 f308997c 编写于 作者: D David Poeschl

Fix crash when NavBar navigating to symbols without source locations

Fixes internal bug 187905

In a Visual Basic WinForms application, the Application.Designer.vb file
contains one Partial of the MyApplication class. Using the NavBar in
this class to attempt navigation to “Main” crashes VS. This crash will
happen any time a non-source symbol (that’s also not a “code generation”
entry like “New” and “Finalize”) finds its way into the NavBar, but this
is the only example I currently have.

This has been broken since Visual Studio 2015 RTM, but previous versions
of Visual Studio showed a "The definition of the object is hidden."
dialog in this case.
上级 44b03197
......@@ -464,13 +464,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
symbol = symbols.CandidateSymbols(item.NavigationSymbolIndex.Value)
End If
' First figure out the location that we want to grab considering partial types
Dim location = symbol.Locations.FirstOrDefault(Function(l) l.SourceTree.Equals(document.GetSyntaxTreeAsync(cancellationToken).WaitAndGetResult(cancellationToken)))
If location Is Nothing Then
location = symbol.Locations.FirstOrDefault
End If
Dim location As Location = GetSourceNavigationLocation(document, symbol, cancellationToken)
If location Is Nothing Then
Return Nothing
End If
......@@ -488,6 +482,19 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
Return New VirtualTreePoint(location.SourceTree, location.SourceTree.GetText(cancellationToken), location.SourceSpan.Start)
End Function
Private Shared Function GetSourceNavigationLocation(document As Document, symbol As ISymbol, cancellationToken As CancellationToken) As Location
Dim sourceLocations = symbol.Locations.Where(Function(l) l.IsInSource)
' First figure out the location that we want to grab considering partial types
Dim location = sourceLocations.FirstOrDefault(Function(l) l.SourceTree.Equals(document.GetSyntaxTreeAsync(cancellationToken).WaitAndGetResult(cancellationToken)))
If location Is Nothing Then
location = sourceLocations.FirstOrDefault
End If
Return location
End Function
Public Overrides Sub NavigateToItem(document As Document, item As NavigationBarItem, textView As ITextView, cancellationToken As CancellationToken)
Dim generateCodeItem = TryCast(item, AbstractGenerateCodeItem)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册