提交 83867130 编写于 作者: M Manish Vasani

Address feedback + update DocumentAnalysisExecutor to use the new...

Address feedback + update DocumentAnalysisExecutor to use the new GetAnalysisResultAsync APIs as an outcome of design change in https://github.com/dotnet/roslyn/pull/45347
上级 abdbc3c2
......@@ -169,13 +169,15 @@ private async Task<ImmutableArray<Diagnostic>> GetSyntaxDiagnosticsAsync(SyntaxT
if (isCompilerAnalyzer)
{
// TODO: Move this invocation to OOP
return await _compilationWithAnalyzers.GetAnalyzerSyntaxDiagnosticsAsync(tree, ImmutableArray.Create(analyzer), cancellationToken).ConfigureAwait(false);
}
if (_lazySyntaxDiagnostics == null)
{
// TODO: Move this invocation to OOP
var treeDiagnostics = await _compilationWithAnalyzers.GetCategorizedAnalyzerSyntaxDiagnosticsAsync(tree, _compilationBasedAnalyzersInAnalysisScope, cancellationToken).ConfigureAwait(false);
var analysisResult = await _compilationWithAnalyzers.GetAnalysisResultAsync(tree, _compilationBasedAnalyzersInAnalysisScope, cancellationToken).ConfigureAwait(false);
var treeDiagnostics = analysisResult.SyntaxDiagnostics.TryGetValue(tree, out var value) ? value : ImmutableDictionary<DiagnosticAnalyzer, ImmutableArray<Diagnostic>>.Empty;
Interlocked.CompareExchange(ref _lazySyntaxDiagnostics, treeDiagnostics, null);
}
......@@ -202,13 +204,16 @@ private async Task<ImmutableArray<Diagnostic>> GetSemanticDiagnosticsAsync(Seman
#endif
var adjustedSpan = await GetAdjustedSpanForCompilerAnalyzerAsync().ConfigureAwait(false);
// TODO: Move this invocation to OOP
return await _compilationWithAnalyzers.GetAnalyzerSemanticDiagnosticsAsync(model, adjustedSpan, ImmutableArray.Create(analyzer), cancellationToken).ConfigureAwait(false);
}
if (_lazySemanticDiagnostics == null)
{
// TODO: Move this invocation to OOP
var treeDiagnostics = await _compilationWithAnalyzers.GetCategorizedAnalyzerSemanticDiagnosticsAsync(model, span, _compilationBasedAnalyzersInAnalysisScope, cancellationToken).ConfigureAwait(false);
var analysisResult = await _compilationWithAnalyzers.GetAnalysisResultAsync(model, span, _compilationBasedAnalyzersInAnalysisScope, cancellationToken).ConfigureAwait(false);
var treeDiagnostics = analysisResult.SemanticDiagnostics.TryGetValue(model.SyntaxTree, out var value) ? value : ImmutableDictionary<DiagnosticAnalyzer, ImmutableArray<Diagnostic>>.Empty;
Interlocked.CompareExchange(ref _lazySemanticDiagnostics, treeDiagnostics, null);
}
......
......@@ -47,6 +47,13 @@ private async Task AnalyzeDocumentForKindAsync(Document document, AnalysisKind k
var stateSets = _stateManager.GetOrUpdateStateSets(document.Project);
var compilationWithAnalyzers = await GetOrCreateCompilationWithAnalyzersAsync(document.Project, stateSets, cancellationToken).ConfigureAwait(false);
// We split the diagnostic computation for document into following steps:
// 1. Try to get cached diagnostics for each analyzer, while computing the set of analyzers that do not have cached diagnostics.
// 2. Execute all the non-cached analyzers with a single invocation into CompilationWithAnalyzers.
// 3. Fetch computed diagnostics per-analyzer from the above invocation, and cache and raise diagnostic reported events.
// In near future, the diagnostic computation invocation into CompilationWithAnalyzers will be moved to OOP.
// This should help simplify and/or remove the IDE layer diagnostic caching in devenv process.
// First attempt to fetch diagnostics from the cache, while computing the state sets for analyzers that are not cached.
using var _ = ArrayBuilder<StateSet>.GetInstance(out var nonCachedStateSets);
foreach (var stateSet in stateSets)
......@@ -63,7 +70,7 @@ private async Task AnalyzeDocumentForKindAsync(Document document, AnalysisKind k
}
}
// Then, compute the diagnostics for non-cached state sets.
// Then, compute the diagnostics for non-cached state sets, and cache and raise diagnostic reported events for these diagnostics.
if (nonCachedStateSets.Count > 0)
{
var analysisScope = new DocumentAnalysisScope(document, span: null, nonCachedStateSets.SelectAsArray(s => s.Analyzer), kind);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册