提交 32f18526 编写于 作者: C Cyrus Najmabadi

Simplify the mechnanism for all languages to extend how we cascade between symbols

上级 c183420f
......@@ -165,16 +165,23 @@ private async Task DetermineAllSymbolsCoreAsync(ISymbol symbol, ConcurrentSet<IS
{
finderTasks.Add(Task.Run(async () =>
{
var symbols = await f.DetermineCascadedSymbolsAsync(searchSymbol, _solution, projects, _cancellationToken).ConfigureAwait(false) ?? SpecializedCollections.EmptyEnumerable<ISymbol>();
var symbolTasks = new List<Task>();
_cancellationToken.ThrowIfCancellationRequested();
var symbols = await f.DetermineCascadedSymbolsAsync(searchSymbol, _solution, projects, _cancellationToken).ConfigureAwait(false);
AddSymbolTasks(result, symbols, symbolTasks);
List<Task> symbolTasks = new List<Task>();
foreach (var child in symbols)
// Defer to the language to see if it wants to cascade here in some special way.
var symbolProject = _solution.GetProject(searchSymbol.ContainingAssembly);
if (symbolProject != null)
{
symbolTasks.Add(Task.Run(async () => await DetermineAllSymbolsCoreAsync(child, result).ConfigureAwait(false), _cancellationToken));
var service = symbolProject.LanguageServices.GetService<ILanguageServiceReferenceFinder>();
symbols = await service.DetermineCascadedSymbolsAsync(searchSymbol, symbolProject, _cancellationToken).ConfigureAwait(false);
AddSymbolTasks(result, symbols, symbolTasks);
}
_cancellationToken.ThrowIfCancellationRequested();
await Task.WhenAll(symbolTasks).ConfigureAwait(false);
}, _cancellationToken));
}
......@@ -183,6 +190,18 @@ private async Task DetermineAllSymbolsCoreAsync(ISymbol symbol, ConcurrentSet<IS
}
}
private void AddSymbolTasks(ConcurrentSet<ISymbol> result, IEnumerable<ISymbol> symbols, List<Task> symbolTasks)
{
if (symbols != null)
{
foreach (var child in symbols)
{
_cancellationToken.ThrowIfCancellationRequested();
symbolTasks.Add(Task.Run(async () => await DetermineAllSymbolsCoreAsync(child, result).ConfigureAwait(false), _cancellationToken));
}
}
}
private ImmutableHashSet<Project> GetProjectScope()
{
if (_documents == null)
......
......@@ -9,7 +9,6 @@ namespace Microsoft.CodeAnalysis.FindSymbols.Finders
{
internal interface ILanguageServiceReferenceFinder : ILanguageService
{
Task<IEnumerable<ISymbol>> DetermineCascadedSymbolsAsync(INamedTypeSymbol namedType, Project project, CancellationToken cancellationToken);
Task<IEnumerable<ISymbol>> DetermineCascadedSymbolsAsync(IPropertySymbol property, Project project, CancellationToken cancellationToken);
Task<IEnumerable<ISymbol>> DetermineCascadedSymbolsAsync(ISymbol symbol, Project project, CancellationToken cancellationToken);
}
}
\ No newline at end of file
......@@ -20,14 +20,13 @@ protected override bool CanFind(INamedTypeSymbol symbol)
return symbol.TypeKind != TypeKind.Error;
}
protected override async Task<IEnumerable<ISymbol>> DetermineCascadedSymbolsAsync(
protected override Task<IEnumerable<ISymbol>> DetermineCascadedSymbolsAsync(
INamedTypeSymbol symbol,
Solution solution,
IImmutableSet<Project> projects,
CancellationToken cancellationToken)
{
List<ISymbol> result = null;
if (symbol.AssociatedSymbol != null)
{
result = Add(result, SpecializedCollections.SingletonEnumerable(symbol.AssociatedSymbol));
......@@ -39,24 +38,7 @@ protected override bool CanFind(INamedTypeSymbol symbol)
// cascade to destructor
result = Add(result, symbol.GetMembers(WellKnownMemberNames.DestructorName));
result = Add(result, await DetermineLanguageCascadedSymbolsAsync(symbol, solution, cancellationToken).ConfigureAwait(false));
return result ?? SpecializedCollections.EmptyList<ISymbol>();
}
private async Task<IEnumerable<ISymbol>> DetermineLanguageCascadedSymbolsAsync(INamedTypeSymbol symbol, Solution solution, CancellationToken cancellationToken)
{
var definitionProject = solution.GetProject(symbol.ContainingAssembly, cancellationToken);
if (definitionProject != null)
{
var referenceFinder = definitionProject.LanguageServices.GetService<ILanguageServiceReferenceFinder>();
if (referenceFinder != null)
{
return await referenceFinder.DetermineCascadedSymbolsAsync(symbol, definitionProject, cancellationToken).ConfigureAwait(false);
}
}
return null;
return Task.FromResult<IEnumerable<ISymbol>>(result ?? SpecializedCollections.EmptyList<ISymbol>());
}
private List<ISymbol> Add(List<ISymbol> result, IEnumerable<ISymbol> enumerable)
......
......@@ -38,17 +38,6 @@ 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;
}
......
......@@ -12,7 +12,17 @@ Namespace Microsoft.CodeAnalysis.FindSymbols
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
Public Function DetermineCascadedSymbolsAsync(symbol As ISymbol, project As Project, cancellationToken As CancellationToken) As Task(Of IEnumerable(Of ISymbol)) Implements ILanguageServiceReferenceFinder.DetermineCascadedSymbolsAsync
If symbol.Kind = SymbolKind.Property Then
Return DetermineCascadedSymbolsAsync(DirectCast(symbol, IPropertySymbol), project, cancellationToken)
ElseIf symbol.Kind = SymbolKind.NamedType Then
Return DetermineCascadedSymbolsAsync(DirectCast(symbol, INamedTypeSymbol), project, cancellationToken)
Else
Return Nothing
End If
End Function
Private Async Function DetermineCascadedSymbolsAsync([property] As IPropertySymbol, project As Project, cancellationToken As CancellationToken) As Task(Of IEnumerable(Of ISymbol))
Dim compilation = Await project.GetCompilationAsync(cancellationToken).ConfigureAwait(False)
Dim relatedSymbol = [property].FindRelatedExplicitlyDeclaredSymbol(compilation)
......@@ -21,7 +31,7 @@ Namespace Microsoft.CodeAnalysis.FindSymbols
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
Private Async Function DetermineCascadedSymbolsAsync(namedType As INamedTypeSymbol, project As Project, cancellationToken As CancellationToken) As Task(Of IEnumerable(Of ISymbol))
Dim compilation = Await project.GetCompilationAsync(cancellationToken).ConfigureAwait(False)
' If this is a WinForms project, then the VB 'my' feature may have synthesized
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册