未验证 提交 bbc78ed5 编写于 作者: H Heejae Chang 提交者: GitHub

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.
上级 eadc22bb
......@@ -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
/// </summary>
private static T? GetAssemblyReferenceType<T>(
this Project project,
Func<IAssemblySymbol, T?> predicate) where T : struct
Func<IAssemblySymbol, T?> 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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册