提交 5de0b845 编写于 作者: M Manish Vasani

Address some more feedback

上级 3a6892d2
......@@ -18,7 +18,6 @@
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Roslyn.Utilities;
......@@ -41,6 +40,7 @@ private partial class IncrementalAnalyzerProcessor
private readonly NormalPriorityProcessor _normalPriorityProcessor;
private readonly LowPriorityProcessor _lowPriorityProcessor;
// NOTE: IDiagnosticAnalyzerService can be null in test environment.
private readonly Lazy<IDiagnosticAnalyzerService?> _lazyDiagnosticAnalyzerService;
private LogAggregator _logAggregator;
......@@ -116,19 +116,19 @@ public void Enqueue(WorkItem item)
}
else
{
if (ShouldEnqueueReducedWorkItem(item, _highPriorityProcessor.Analyzers, options, analysisScope, out var reducedWorkItem))
if (TryGetItemWithOverriddenAnalysisScope(item, _highPriorityProcessor.Analyzers, options, analysisScope, out var newWorkItem))
{
_highPriorityProcessor.Enqueue(reducedWorkItem.Value);
_highPriorityProcessor.Enqueue(newWorkItem.Value);
}
if (ShouldEnqueueReducedWorkItem(item, _normalPriorityProcessor.Analyzers, options, analysisScope, out reducedWorkItem))
if (TryGetItemWithOverriddenAnalysisScope(item, _normalPriorityProcessor.Analyzers, options, analysisScope, out newWorkItem))
{
_normalPriorityProcessor.Enqueue(reducedWorkItem.Value);
_normalPriorityProcessor.Enqueue(newWorkItem.Value);
}
if (ShouldEnqueueReducedWorkItem(item, _lowPriorityProcessor.Analyzers, options, analysisScope, out reducedWorkItem))
if (TryGetItemWithOverriddenAnalysisScope(item, _lowPriorityProcessor.Analyzers, options, analysisScope, out newWorkItem))
{
_lowPriorityProcessor.Enqueue(reducedWorkItem.Value);
_lowPriorityProcessor.Enqueue(newWorkItem.Value);
}
}
......@@ -139,11 +139,18 @@ public void Enqueue(WorkItem item)
bool ShouldEnqueueForAllQueues(WorkItem item, BackgroundAnalysisScope analysisScope)
{
var reasons = item.InvocationReasons;
// For active file analysis scope we only process following:
// 1. Active documents
// 2. Closed and removed documents to ensure that data for removed and closed documents
// is no longer held in memory and removed from any user visible components.
// For example, this ensures that diagnostics for closed/removed documents are removed from error list.
// Note that we don't need to specially handle "Project removed" or "Project closed" case, as the solution crawler
// enqueues individual "DocumentRemoved" work items for each document in the removed project.
if (analysisScope == BackgroundAnalysisScope.ActiveFile &&
!reasons.Contains(PredefinedInvocationReasons.DocumentClosed) &&
!reasons.Contains(PredefinedInvocationReasons.DocumentRemoved))
{
// Only process active/closed/removed documents for active file analysis.
return item.DocumentId == _documentTracker.TryGetActiveDocument();
}
......@@ -151,7 +158,7 @@ bool ShouldEnqueueForAllQueues(WorkItem item, BackgroundAnalysisScope analysisSc
}
}
private static bool ShouldEnqueueReducedWorkItem(
private static bool TryGetItemWithOverriddenAnalysisScope(
WorkItem item,
ImmutableArray<IIncrementalAnalyzer> allAnalyzers,
OptionSet options,
......@@ -254,7 +261,7 @@ private void ReportPendingWorkItemCount()
private async Task RunAnalyzersAsync<T>(
ImmutableArray<IIncrementalAnalyzer> analyzers,
T value,
WorkItem? workItem,
WorkItem workItem,
Func<IIncrementalAnalyzer, T, CancellationToken, Task> runnerAsync,
CancellationToken cancellationToken)
{
......@@ -263,7 +270,7 @@ private void ReportPendingWorkItemCount()
ReportPendingWorkItemCount();
// Check if the work item is specific to some incremental analyzer(s).
var analyzersToExecute = workItem?.GetApplicableAnalyzers(analyzers) ?? analyzers;
var analyzersToExecute = workItem.GetApplicableAnalyzers(analyzers) ?? analyzers;
foreach (var analyzer in analyzersToExecute)
{
if (cancellationToken.IsCancellationRequested)
......
......@@ -335,8 +335,7 @@ private async Task ProcessDocumentAsync(ImmutableArray<IIncrementalAnalyzer> ana
{
var document = solution.GetDocument(documentId);
if (document != null &&
!workItem.InvocationReasons.Contains(PredefinedInvocationReasons.DocumentRemoved))
if (document != null)
{
// if we are called because a document is opened, we invalidate the document so that
// it can be re-analyzed. otherwise, since newly opened document has same version as before
......@@ -472,7 +471,7 @@ private async Task ResetStatesAsync()
return;
}
await Processor.RunAnalyzersAsync(Analyzers, Processor.CurrentSolution, workItem: null, (a, s, c) => a.NewSolutionSnapshotAsync(s, c), CancellationToken).ConfigureAwait(false);
await Processor.RunAnalyzersAsync(Analyzers, Processor.CurrentSolution, workItem: new WorkItem(), (a, s, c) => a.NewSolutionSnapshotAsync(s, c), CancellationToken).ConfigureAwait(false);
foreach (var id in Processor.GetOpenDocumentIds())
{
......
......@@ -40,7 +40,7 @@ private partial class WorkCoordinator
/// Otherwise, returns <paramref name="allAnalyzers"/>.
/// </summary>
public IEnumerable<IIncrementalAnalyzer> GetApplicableAnalyzers(ImmutableArray<IIncrementalAnalyzer> allAnalyzers)
=> SpecificAnalyzers.Count > 0 ? SpecificAnalyzers.Where(allAnalyzers.Contains) : allAnalyzers;
=> SpecificAnalyzers?.Count > 0 ? SpecificAnalyzers.Where(allAnalyzers.Contains) : allAnalyzers;
// retry
public readonly bool IsRetry;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册