From bbc78ed56efac83715faa58b2c3d0d6317156cbe Mon Sep 17 00:00:00 2001 From: Heejae Chang Date: Thu, 6 Jun 2019 19:29:33 -0700 Subject: [PATCH] pass in cancellation token to bail out early (#36176) this particular code path can take a long time if metadata reference hasn't created its symbols yet. this can get really bad if we try to show code lens for something like IDispose.Dipose and it tries to create all metdata references in the solution. since it is not cancellable, just passing by a Dipose method can cause this to occupy CPU 100% for several seconds and there is no way to make it go away. now we pass in cancellation token so that we can bail out sooner. --- .../FindReferences/DependentProjectsFinder.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentProjectsFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentProjectsFinder.cs index 3d4f1e2b72e..267c33fce73 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentProjectsFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/DependentProjectsFinder.cs @@ -403,18 +403,19 @@ private static bool HasReferenceTo(IAssemblySymbol containingAssembly, Project s return project.ProjectReferences.Any(p => p.ProjectId == sourceProject.Id); } - return project.HasReferenceToAssembly(containingAssembly); + return project.HasReferenceToAssembly(containingAssembly, cancellationToken); } - public static bool HasReferenceToAssembly(this Project project, IAssemblySymbol assemblySymbol) + public static bool HasReferenceToAssembly(this Project project, IAssemblySymbol assemblySymbol, CancellationToken cancellationToken) { - return project.HasReferenceToAssembly(assemblySymbol.Name); + return project.HasReferenceToAssembly(assemblySymbol.Name, cancellationToken); } - public static bool HasReferenceToAssembly(this Project project, string assemblyName) + public static bool HasReferenceToAssembly(this Project project, string assemblyName, CancellationToken cancellationToken) { bool? hasMatch = project.GetAssemblyReferenceType( - a => a.Name == assemblyName ? true : (bool?)null); + a => a.Name == assemblyName ? true : (bool?)null, + cancellationToken); return hasMatch == true; } @@ -427,7 +428,8 @@ public static bool HasReferenceToAssembly(this Project project, string assemblyN /// private static T? GetAssemblyReferenceType( this Project project, - Func predicate) where T : struct + Func predicate, + CancellationToken cancellationToken) where T : struct { // If the project we're looking at doesn't even support compilations, then there's no // way for it to have an IAssemblySymbol. And without that, there is no way for it @@ -449,6 +451,8 @@ public static bool HasReferenceToAssembly(this Project project, string assemblyN foreach (var reference in project.MetadataReferences) { + cancellationToken.ThrowIfCancellationRequested(); + if (compilation.GetAssemblyOrModuleSymbol(reference) is IAssemblySymbol symbol) { var result = predicate(symbol); -- GitLab