Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move part of the SymbolFinder out of proc. #18562

Merged
merged 7 commits into from
Apr 10, 2017
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ namespace Microsoft.CodeAnalysis.FindSymbols

internal static partial class DeclarationFinder
{
internal static async Task<ImmutableArray<SymbolAndProjectId>> FindSourceDeclarationsWithNormalQueryAsync(
#region Dispatch Members

// These are the public entrypoints to finding source declarations. They will attempt to
// remove the query to the OOP process, and will fallback to local processing if they can't.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/remove/remote/.

Consider not using OOP as an acronym.


public static async Task<ImmutableArray<SymbolAndProjectId>> FindSourceDeclarationsWithNormalQueryAsync(
Solution solution, string name, bool ignoreCase, SymbolFilter criteria, CancellationToken cancellationToken)
{
if (solution == null)
Expand Down Expand Up @@ -47,40 +52,6 @@ internal static async Task<ImmutableArray<SymbolAndProjectId>> FindSourceDeclara
solution, name, ignoreCase, criteria, cancellationToken).ConfigureAwait(false);
}

internal static async Task<ImmutableArray<SymbolAndProjectId>> FindSourceDeclarationsWithNormalQueryInCurrentProcessAsync(
Solution solution, string name, bool ignoreCase, SymbolFilter criteria, CancellationToken cancellationToken)
{
var query = SearchQuery.Create(name, ignoreCase);
var result = ArrayBuilder<SymbolAndProjectId>.GetInstance();
foreach (var projectId in solution.ProjectIds)
{
var project = solution.GetProject(projectId);
await AddCompilationDeclarationsWithNormalQueryAsync(
project, query, criteria, result, cancellationToken).ConfigureAwait(false);
}

return result.ToImmutableAndFree();
}

private static async Task<(bool, ImmutableArray<SymbolAndProjectId>)> TryFindSourceDeclarationsWithNormalQueryInRemoteProcessAsync(
Solution solution, string name, bool ignoreCase, SymbolFilter criteria, CancellationToken cancellationToken)
{
var session = await SymbolFinder.TryGetRemoteSessionAsync(solution, cancellationToken).ConfigureAwait(false);
if (session != null)
{
var result = await session.InvokeAsync<SerializableSymbolAndProjectId[]>(
nameof(IRemoteSymbolFinder.FindSolutionSourceDeclarationsWithNormalQuery),
name, ignoreCase, criteria).ConfigureAwait(false);

var rehydrated = await RehydrateAsync(
solution, result, cancellationToken).ConfigureAwait(false);

return (true, rehydrated);
}

return (false, ImmutableArray<SymbolAndProjectId>.Empty);
}

public static async Task<ImmutableArray<SymbolAndProjectId>> FindSourceDeclarationsithNormalQueryAsync(
Project project, string name, bool ignoreCase, SymbolFilter criteria, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -111,6 +82,31 @@ public static async Task<ImmutableArray<SymbolAndProjectId>> FindSourceDeclarati
project, name, ignoreCase, criteria, cancellationToken).ConfigureAwait(false);
}

#endregion

#region Remote Dispatch

// These are the members that actually try to send the request to the remote process.

private static async Task<(bool, ImmutableArray<SymbolAndProjectId>)> TryFindSourceDeclarationsWithNormalQueryInRemoteProcessAsync(
Solution solution, string name, bool ignoreCase, SymbolFilter criteria, CancellationToken cancellationToken)
{
var session = await SymbolFinder.TryGetRemoteSessionAsync(solution, cancellationToken).ConfigureAwait(false);
if (session != null)
{
var result = await session.InvokeAsync<SerializableSymbolAndProjectId[]>(
nameof(IRemoteSymbolFinder.FindSolutionSourceDeclarationsWithNormalQuery),
name, ignoreCase, criteria).ConfigureAwait(false);

var rehydrated = await RehydrateAsync(
solution, result, cancellationToken).ConfigureAwait(false);

return (true, rehydrated);
}

return (false, ImmutableArray<SymbolAndProjectId>.Empty);
}

private static async Task<(bool, ImmutableArray<SymbolAndProjectId>)> TryFindSourceDeclarationsWithNormalQueryInRemoteProcessAsync(
Project project, string name, bool ignoreCase, SymbolFilter criteria, CancellationToken cancellationToken)
{
Expand All @@ -130,6 +126,29 @@ public static async Task<ImmutableArray<SymbolAndProjectId>> FindSourceDeclarati
return (false, ImmutableArray<SymbolAndProjectId>.Empty);
}

#endregion

#region Local processing

// These are the members that have the core logic that does the actual finding. They will
// be called 'in proc' in the remote process if we are able to remote the request. Or they
// will be called 'in proc' from within VS if we are not able to remote the request.

internal static async Task<ImmutableArray<SymbolAndProjectId>> FindSourceDeclarationsWithNormalQueryInCurrentProcessAsync(
Solution solution, string name, bool ignoreCase, SymbolFilter criteria, CancellationToken cancellationToken)
{
var query = SearchQuery.Create(name, ignoreCase);
var result = ArrayBuilder<SymbolAndProjectId>.GetInstance();
foreach (var projectId in solution.ProjectIds)
{
var project = solution.GetProject(projectId);
await AddCompilationDeclarationsWithNormalQueryAsync(
project, query, criteria, result, cancellationToken).ConfigureAwait(false);
}

return result.ToImmutableAndFree();
}

internal static async Task<ImmutableArray<SymbolAndProjectId>> FindSourceDeclarationsWithNormalQueryInCurrentProcessAsync(
Project project, string name, bool ignoreCase, SymbolFilter filter, CancellationToken cancellationToken)
{
Expand All @@ -139,5 +158,7 @@ await AddCompilationDeclarationsWithNormalQueryAsync(
filter, list, cancellationToken).ConfigureAwait(false);
return list.ToImmutableAndFree();
}

#endregion
}
}