Skip to content

Commit

Permalink
Remove cancellation tokens from FAR context objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Apr 22, 2021
1 parent 95d0579 commit 89d820c
Show file tree
Hide file tree
Showing 66 changed files with 630 additions and 652 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,32 @@ private async Task StreamingFindBaseSymbolsAsync(
{
using var token = _asyncListener.BeginAsyncOperation(nameof(StreamingFindBaseSymbolsAsync));

var context = presenter.StartSearch(EditorFeaturesResources.Navigating, supportsReferences: true, cancellationToken);
var (context, combinedCancellationToken) = presenter.StartSearch(EditorFeaturesResources.Navigating, supportsReferences: true, cancellationToken);
cancellationToken = combinedCancellationToken;

using (Logger.LogBlock(
FunctionId.CommandHandler_FindAllReference,
KeyValueLogMessage.Create(LogType.UserAction, m => m["type"] = "streaming"),
context.CancellationToken))
cancellationToken))
{
try
{
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
var relevantSymbol = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, context.CancellationToken);
var relevantSymbol = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, cancellationToken);
#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task

var overriddenSymbol = relevantSymbol?.symbol.GetOverriddenMember();

while (overriddenSymbol != null)
{
if (context.CancellationToken.IsCancellationRequested)
if (cancellationToken.IsCancellationRequested)
{
return;
}

var definitionItem = overriddenSymbol.ToNonClassifiedDefinitionItem(document.Project.Solution, true);
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
await context.OnDefinitionFoundAsync(definitionItem);
await context.OnDefinitionFoundAsync(definitionItem, cancellationToken);
#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task

// try getting the next one
Expand All @@ -99,7 +100,7 @@ private async Task StreamingFindBaseSymbolsAsync(
}
finally
{
await context.OnCompletedAsync().ConfigureAwait(false);
await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,37 +91,38 @@ private async Task FindDerivedSymbolsAsync(
{
using var token = _asyncListener.BeginAsyncOperation(nameof(FindDerivedSymbolsAsync));

var context = presenter.StartSearch(EditorFeaturesResources.Navigating, supportsReferences: true, cancellationToken);
var (context, combinedCancellationToken) = presenter.StartSearch(EditorFeaturesResources.Navigating, supportsReferences: true, cancellationToken);
cancellationToken = combinedCancellationToken;
try
{
using (Logger.LogBlock(
FunctionId.CommandHandler_FindAllReference,
KeyValueLogMessage.Create(LogType.UserAction, m => m["type"] = "streaming"),
context.CancellationToken))
cancellationToken))
{
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
var candidateSymbolProjectPair = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, context.CancellationToken);
var candidateSymbolProjectPair = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, cancellationToken);
#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task
if (candidateSymbolProjectPair?.symbol == null)
return;

#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
var candidates = await GatherSymbolsAsync(candidateSymbolProjectPair.Value.symbol,
document.Project.Solution, context.CancellationToken);
document.Project.Solution, cancellationToken);
#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task

foreach (var candidate in candidates)
{
var definitionItem = candidate.ToNonClassifiedDefinitionItem(document.Project.Solution, true);
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
await context.OnDefinitionFoundAsync(definitionItem);
await context.OnDefinitionFoundAsync(definitionItem, cancellationToken);
#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task
}
}
}
finally
{
await context.OnCompletedAsync().ConfigureAwait(false);
await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false);
}
}
catch (OperationCanceledException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,68 +68,69 @@ private async Task FindExtensionMethodsAsync(
{
using var token = _asyncListener.BeginAsyncOperation(nameof(FindExtensionMethodsAsync));

var context = presenter.StartSearch(EditorFeaturesResources.Navigating, supportsReferences: true, cancellationToken);
var (context, combinedCancellationToken) = presenter.StartSearch(EditorFeaturesResources.Navigating, supportsReferences: true, cancellationToken);
cancellationToken = combinedCancellationToken;

using (Logger.LogBlock(
FunctionId.CommandHandler_FindAllReference,
KeyValueLogMessage.Create(LogType.UserAction, m => m["type"] = "streaming"),
context.CancellationToken))
cancellationToken))
{
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
var candidateSymbolProjectPair = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, context.CancellationToken);
var candidateSymbolProjectPair = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, cancellationToken);
#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task

var symbol = candidateSymbolProjectPair?.symbol as INamedTypeSymbol;

// if we didn't get the right symbol, just abort
if (symbol == null)
{
await context.OnCompletedAsync().ConfigureAwait(false);
await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false);
return;
}

Compilation compilation;
if (!document.Project.TryGetCompilation(out compilation))
{
await context.OnCompletedAsync().ConfigureAwait(false);
await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false);
return;
}

var solution = document.Project.Solution;

foreach (var type in compilation.Assembly.GlobalNamespace.GetAllTypes(context.CancellationToken))
foreach (var type in compilation.Assembly.GlobalNamespace.GetAllTypes(cancellationToken))
{
if (!type.MightContainExtensionMethods)
continue;

foreach (var extMethod in type.GetMembers().OfType<IMethodSymbol>().Where(method => method.IsExtensionMethod))
{
if (context.CancellationToken.IsCancellationRequested)
if (cancellationToken.IsCancellationRequested)
break;

var reducedMethod = extMethod.ReduceExtensionMethod(symbol);
if (reducedMethod != null)
{
var loc = extMethod.Locations.First();

var sourceDefinition = await SymbolFinder.FindSourceDefinitionAsync(reducedMethod, solution, context.CancellationToken).ConfigureAwait(false);
var sourceDefinition = await SymbolFinder.FindSourceDefinitionAsync(reducedMethod, solution, cancellationToken).ConfigureAwait(false);

// And if our definition actually is from source, then let's re-figure out what project it came from
if (sourceDefinition != null)
{
var originatingProject = solution.GetProject(sourceDefinition.ContainingAssembly, context.CancellationToken);
var originatingProject = solution.GetProject(sourceDefinition.ContainingAssembly, cancellationToken);

var definitionItem = reducedMethod.ToNonClassifiedDefinitionItem(solution, true);

#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
await context.OnDefinitionFoundAsync(definitionItem);
await context.OnDefinitionFoundAsync(definitionItem, cancellationToken);
#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task
}
}
}
}

await context.OnCompletedAsync().ConfigureAwait(false);
await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false);
}
}
catch (OperationCanceledException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,18 @@ private async Task FindImplementingMembersAsync(
// Let the presented know we're starting a search. We pass in no cancellation token here as this
// operation itself is fire-and-forget and the user won't cancel the operation through us (though
// the window itself can cancel the operation if it is taken over for another find operation.
var context = presenter.StartSearch(EditorFeaturesResources.Navigating, supportsReferences: true, cancellationToken);
var (context, combinedCancellationToken) = presenter.StartSearch(EditorFeaturesResources.Navigating, supportsReferences: true, cancellationToken);
cancellationToken = combinedCancellationToken;

using (Logger.LogBlock(
FunctionId.CommandHandler_FindAllReference,
KeyValueLogMessage.Create(LogType.UserAction, m => m["type"] = "streaming"),
context.CancellationToken))
cancellationToken))
{
try
{
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
var relevantSymbol = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, context.CancellationToken);
var relevantSymbol = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, cancellationToken);
#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task

var interfaceSymbol = relevantSymbol?.symbol as INamedTypeSymbol;
Expand Down Expand Up @@ -118,20 +119,20 @@ private async Task FindImplementingMembersAsync(

// we can search for implementations of the interface, within this type
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
await InspectInterfaceAsync(context, interfaceSymbol, namedTypeSymbol, document.Project);
await InspectInterfaceAsync(context, interfaceSymbol, namedTypeSymbol, document.Project, cancellationToken);
#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task

// now, we iterate on interfaces of our interfaces
foreach (var iFace in interfaceSymbol.AllInterfaces)
{
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
await InspectInterfaceAsync(context, iFace, namedTypeSymbol, document.Project);
await InspectInterfaceAsync(context, iFace, namedTypeSymbol, document.Project, cancellationToken);
#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task
}
}
finally
{
await context.OnCompletedAsync().ConfigureAwait(false);
await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false);
}
}
}
Expand All @@ -143,11 +144,12 @@ private async Task FindImplementingMembersAsync(
}
}

private static async Task InspectInterfaceAsync(IFindUsagesContext context, INamedTypeSymbol interfaceSymbol, INamedTypeSymbol namedTypeSymbol, Project project)
private static async Task InspectInterfaceAsync(
IFindUsagesContext context, INamedTypeSymbol interfaceSymbol, INamedTypeSymbol namedTypeSymbol, Project project, CancellationToken cancellationToken)
{
foreach (var interfaceMember in interfaceSymbol.GetMembers())
{
if (context.CancellationToken.IsCancellationRequested)
if (cancellationToken.IsCancellationRequested)
return;

var impl = namedTypeSymbol.FindImplementationForInterfaceMember(interfaceMember);
Expand All @@ -156,7 +158,7 @@ private static async Task InspectInterfaceAsync(IFindUsagesContext context, INam

var definitionItem = impl.ToNonClassifiedDefinitionItem(project.Solution, true);
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
await context.OnDefinitionFoundAsync(definitionItem);
await context.OnDefinitionFoundAsync(definitionItem, cancellationToken);
#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,19 @@ private async Task FindMemberOverloadsAsync(
{
using var token = _asyncListener.BeginAsyncOperation(nameof(FindMemberOverloadsAsync));

var context = presenter.StartSearch(
var (context, combinedCancellationToken) = presenter.StartSearch(
EditorFeaturesResources.Navigating, supportsReferences: true, cancellationToken);
cancellationToken = combinedCancellationToken;

using (Logger.LogBlock(
FunctionId.CommandHandler_FindAllReference,
KeyValueLogMessage.Create(LogType.UserAction, m => m["type"] = "streaming"),
context.CancellationToken))
cancellationToken))
{
try
{
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
var candidateSymbolProjectPair = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, context.CancellationToken);
var candidateSymbolProjectPair = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(document, caretPosition, cancellationToken);
#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task

// we need to get the containing type (i.e. class)
Expand All @@ -90,13 +91,13 @@ private async Task FindMemberOverloadsAsync(
{
var definitionItem = curSymbol.ToNonClassifiedDefinitionItem(document.Project.Solution, true);
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
await context.OnDefinitionFoundAsync(definitionItem);
await context.OnDefinitionFoundAsync(definitionItem, cancellationToken);
#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task
}
}
finally
{
await context.OnCompletedAsync().ConfigureAwait(false);
await context.OnCompletedAsync(cancellationToken).ConfigureAwait(false);
}
}
}
Expand Down
Loading

0 comments on commit 89d820c

Please sign in to comment.