提交 2fe85c41 编写于 作者: C Cyrus Najmabadi

Make the Type/Property cascading symmetric

上级 ea92e95e
......@@ -315,4 +315,4 @@
<ImportGroup Label="Targets">
<Import Project="..\..\..\build\Targets\VSL.Imports.targets" />
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
......@@ -4,6 +4,7 @@ Imports System.Composition
Imports Microsoft.CodeAnalysis.Editor.Host
Imports Microsoft.CodeAnalysis.Editor.Implementation.GoToDefinition
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.VisualBasic.Utilities
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.GoToDefinition
<ExportLanguageService(GetType(IGoToDefinitionService), LanguageNames.VisualBasic), [Shared]>
......@@ -16,22 +17,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.GoToDefinition
End Sub
Protected Overrides Function FindRelatedExplicitlyDeclaredSymbol(symbol As ISymbol, compilation As Compilation) As ISymbol
' For example: My.Forms.[|LoginForm|]
' LoginForm is a SynthesizedMyGroupCollectionPropertySymbol with no Location. Use the
' type of this property, the actual LoginForm type itself, for navigation purposes.
If symbol.IsKind(SymbolKind.Property) AndAlso symbol.IsImplicitlyDeclared Then
Dim propertySymbol = DirectCast(symbol, IPropertySymbol)
If propertySymbol.ContainingType IsNot Nothing AndAlso
propertySymbol.ContainingType.Name = "MyForms" AndAlso
propertySymbol.ContainingType.ContainingNamespace IsNot Nothing AndAlso
propertySymbol.ContainingType.ContainingNamespace.IsMyNamespace(compilation) Then
Return propertySymbol.Type
End If
End If
Return symbol
Return symbol.FindRelatedExplicitlyDeclaredSymbol(compilation)
End Function
End Class
End Namespace
......@@ -7,6 +7,7 @@ namespace Microsoft.CodeAnalysis.FindSymbols.Finders
{
internal interface ILanguageServiceReferenceFinder : ILanguageService
{
Task<IEnumerable<ISymbol>> DetermineCascadedSymbolsAsync(INamedTypeSymbol symbol, Project project, CancellationToken cancellationToken);
Task<IEnumerable<ISymbol>> DetermineCascadedSymbolsAsync(INamedTypeSymbol namedType, Project project, CancellationToken cancellationToken);
Task<IEnumerable<ISymbol>> DetermineCascadedSymbolsAsync(IPropertySymbol property, Project project, CancellationToken cancellationToken);
}
}
\ No newline at end of file
......@@ -38,6 +38,17 @@ protected override bool CanFind(IPropertySymbol symbol)
result = result.Concat(symbol.SetMethod);
}
var project = solution.GetProject(symbol.ContainingAssembly, cancellationToken);
var service = project?.LanguageServices.GetService<ILanguageServiceReferenceFinder>();
if (service != null)
{
var languageCascades = await service.DetermineCascadedSymbolsAsync(symbol, project, cancellationToken).ConfigureAwait(false);
if (languageCascades != null)
{
result = result.Concat(languageCascades);
}
}
return result;
}
......
......@@ -239,6 +239,7 @@
<Compile Include="Utilities\NameSyntaxIterator.vb" />
<Compile Include="Utilities\PossibleDeclarationTypes.vb" />
<Compile Include="Utilities\SpeculationAnalyzer.vb" />
<Compile Include="Utilities\SymbolExtensions.vb" />
<Compile Include="Utilities\SyntaxKindSet.vb" />
<Compile Include="Utilities\TokenComparer.vb" />
<Compile Include="Utilities\TypeSyntaxComparer.vb" />
......
......@@ -3,12 +3,22 @@ Imports System.Threading
Imports System.Threading.Tasks
Imports Microsoft.CodeAnalysis.FindSymbols.Finders
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.VisualBasic.Utilities
Namespace Microsoft.CodeAnalysis.FindSymbols
<ExportLanguageService(GetType(ILanguageServiceReferenceFinder), LanguageNames.VisualBasic), [Shared]>
Friend Class VisualBasicReferenceFinder
Implements ILanguageServiceReferenceFinder
Public Async Function DetermineCascadedSymbolsAsync([property] As IPropertySymbol, project As Project, cancellationToken As CancellationToken) As Task(Of IEnumerable(Of ISymbol)) Implements ILanguageServiceReferenceFinder.DetermineCascadedSymbolsAsync
Dim compilation = Await project.GetCompilationAsync(cancellationToken).ConfigureAwait(False)
Dim relatedSymbol = [property].FindRelatedExplicitlyDeclaredSymbol(compilation)
Return If([property].Equals(relatedSymbol),
SpecializedCollections.EmptyEnumerable(Of ISymbol),
SpecializedCollections.SingletonEnumerable(relatedSymbol))
End Function
Public Async Function DetermineCascadedSymbolsAsync(namedType As INamedTypeSymbol, project As Project, cancellationToken As CancellationToken) As Task(Of IEnumerable(Of ISymbol)) Implements ILanguageServiceReferenceFinder.DetermineCascadedSymbolsAsync
Debug.Assert(project.Language = LanguageNames.VisualBasic)
Dim compilation = Await project.GetCompilationAsync(cancellationToken).ConfigureAwait(False)
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Runtime.CompilerServices
Namespace Microsoft.CodeAnalysis.VisualBasic.Utilities
Friend Module SymbolExtensions
<Extension>
Public Function FindRelatedExplicitlyDeclaredSymbol(symbol As ISymbol, compilation As Compilation) As ISymbol
' For example: My.Forms.[|LoginForm|]
' LoginForm is a SynthesizedMyGroupCollectionPropertySymbol with no Location. Use the
' type of this property, the actual LoginForm type itself, for navigation purposes.
If symbol.IsKind(SymbolKind.Property) AndAlso symbol.IsImplicitlyDeclared Then
Dim propertySymbol = DirectCast(symbol, IPropertySymbol)
If propertySymbol.ContainingType IsNot Nothing AndAlso
propertySymbol.ContainingType.Name = "MyForms" AndAlso
propertySymbol.ContainingType.ContainingNamespace IsNot Nothing AndAlso
propertySymbol.ContainingType.ContainingNamespace.IsMyNamespace(compilation) Then
Return propertySymbol.Type
End If
End If
Return symbol
End Function
End Module
End Namespace
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册