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

make sure VS to not crash when analyzer.initialize throws (#31543)

上级 779880d5
......@@ -292,7 +292,7 @@ private static IEnumerable<AnalyzerPerformanceInfo> Convert(IEnumerable<(Diagnos
return analyzerPerf.Select(kv => new AnalyzerPerformanceInfo(kv.analyzer.GetAnalyzerId(), DiagnosticAnalyzerLogger.AllowsTelemetry(kv.analyzer, serviceOpt), kv.timeSpan));
}
public static bool IsCompilationEndAnalyzer(this DiagnosticAnalyzer analyzer, Project project, Compilation compilation)
public static bool? IsCompilationEndAnalyzer(this DiagnosticAnalyzer analyzer, Project project, Compilation compilation)
{
if (!project.SupportsCompilation)
{
......@@ -301,16 +301,26 @@ public static bool IsCompilationEndAnalyzer(this DiagnosticAnalyzer analyzer, Pr
Contract.ThrowIfNull(compilation);
// currently, this is only way to see whether analyzer has compilation end analysis or not.
// also, analyzer being compilation end analyzer or not is dynamic. so this can return different value based on
// given compilation or options.
//
// but for now, this is what we decided in design meeting until we decide how to deal with compilation end analyzer
// long term
var context = new CollectCompilationActionsContext(compilation, project.AnalyzerOptions);
analyzer.Initialize(context);
return context.IsCompilationEndAnalyzer;
try
{
// currently, this is only way to see whether analyzer has compilation end analysis or not.
// also, analyzer being compilation end analyzer or not is dynamic. so this can return different value based on
// given compilation or options.
//
// but for now, this is what we decided in design meeting until we decide how to deal with compilation end analyzer
// long term
var context = new CollectCompilationActionsContext(compilation, project.AnalyzerOptions);
analyzer.Initialize(context);
return context.IsCompilationEndAnalyzer;
}
catch
{
// analyzer.initialize can throw. when that happens, we will try again next time.
// we are not logging anything here since it will be logged by CompilationWithAnalyzer later
// in the error list
return null;
}
}
/// <summary>
......
......@@ -265,7 +265,14 @@ public void ComputeCompilationEndAnalyzer(Project project, Compilation compilati
}
// running this multiple time is fine
_compilationEndAnalyzer = _analyzer.IsCompilationEndAnalyzer(project, compilation) ? 1 : 0;
var result = _analyzer.IsCompilationEndAnalyzer(project, compilation);
if (!result.HasValue)
{
// try again next time.
return;
}
_compilationEndAnalyzer = result.Value ? 1 : 0;
}
public bool IsCompilationEndAnalyzer(Project project, Compilation compilation)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册