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

Add work coordinator unit tests for different background analysis scopes

上级 cc090d1f
......@@ -74,7 +74,7 @@ public async Task DiagnosticData_GetText6()
await VerifyTextSpanAsync(code, 1, 30, 2, 40, new TextSpan(code.Length, 0));
}
[Fact, Trait(Test.Utilities.Traits.Feature, Test.Utilities.Traits.Features.Diagnostics)]
[Fact, Trait(Traits.Feature, Traits.Features.Diagnostics)]
public async Task DiagnosticData_GetText7()
{
var code = @"
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using System.Composition;
using Microsoft.CodeAnalysis.Host.Mef;
namespace Microsoft.CodeAnalysis.Editor.Test
{
[ExportWorkspaceService(typeof(IDocumentTrackingService)), Shared]
internal sealed class TestDocumentTrackingService : IDocumentTrackingService
{
private readonly object _gate = new object();
private event EventHandler<DocumentId> _activeDocumentChangedEventHandler;
private DocumentId _activeDocumentId;
[ImportingConstructor]
public TestDocumentTrackingService()
{
}
public event EventHandler<DocumentId> ActiveDocumentChanged
{
add
{
lock (_gate)
{
_activeDocumentChangedEventHandler += value;
}
}
remove
{
lock (_gate)
{
_activeDocumentChangedEventHandler -= value;
}
}
}
public event EventHandler<EventArgs> NonRoslynBufferTextChanged
{
add { }
remove { }
}
public void SetActiveDocument(DocumentId newActiveDocumentId)
{
_activeDocumentId = newActiveDocumentId;
_activeDocumentChangedEventHandler?.Invoke(this, newActiveDocumentId);
}
public DocumentId TryGetActiveDocument()
{
return _activeDocumentId;
}
public ImmutableArray<DocumentId> GetVisibleDocuments()
{
return _activeDocumentId != null ? ImmutableArray.Create(_activeDocumentId) : ImmutableArray<DocumentId>.Empty;
}
}
}
......@@ -2,6 +2,7 @@
using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ErrorReporting;
......@@ -75,6 +76,12 @@ public void Enqueue(WorkItem item)
{
Contract.ThrowIfFalse(item.DocumentId != null, "can only enqueue a document work item");
// Don't enqueue item if we don't have any high priority analyzers
if (this.Analyzers.IsEmpty)
{
return;
}
// we only put workitem in high priority queue if there is a text change.
// this is to prevent things like opening a file, changing in other files keep enqueuing
// expensive high priority work.
......@@ -110,6 +117,8 @@ protected override Task WaitAsync(CancellationToken cancellationToken)
protected override async Task ExecuteAsync()
{
Debug.Assert(!Analyzers.IsEmpty);
if (CancellationToken.IsCancellationRequested)
{
return;
......
......@@ -116,20 +116,22 @@ public void Enqueue(WorkItem item)
}
else
{
if (TryGetItemWithOverriddenAnalysisScope(item, _highPriorityProcessor.Analyzers, options, analysisScope, out var newWorkItem))
if (TryGetItemWithOverriddenAnalysisScope(item, _highPriorityProcessor.Analyzers, options, analysisScope, _listener, out var newWorkItem))
{
_highPriorityProcessor.Enqueue(newWorkItem.Value);
}
if (TryGetItemWithOverriddenAnalysisScope(item, _normalPriorityProcessor.Analyzers, options, analysisScope, out newWorkItem))
if (TryGetItemWithOverriddenAnalysisScope(item, _normalPriorityProcessor.Analyzers, options, analysisScope, _listener, out newWorkItem))
{
_normalPriorityProcessor.Enqueue(newWorkItem.Value);
}
if (TryGetItemWithOverriddenAnalysisScope(item, _lowPriorityProcessor.Analyzers, options, analysisScope, out newWorkItem))
if (TryGetItemWithOverriddenAnalysisScope(item, _lowPriorityProcessor.Analyzers, options, analysisScope, _listener, out newWorkItem))
{
_lowPriorityProcessor.Enqueue(newWorkItem.Value);
}
item.AsyncToken.Dispose();
}
ReportPendingWorkItemCount();
......@@ -151,7 +153,7 @@ bool ShouldEnqueueForAllQueues(WorkItem item, BackgroundAnalysisScope analysisSc
!reasons.Contains(PredefinedInvocationReasons.DocumentClosed) &&
!reasons.Contains(PredefinedInvocationReasons.DocumentRemoved))
{
return item.DocumentId == _documentTracker.TryGetActiveDocument();
return item.DocumentId == _documentTracker?.TryGetActiveDocument();
}
return true;
......@@ -163,6 +165,7 @@ bool ShouldEnqueueForAllQueues(WorkItem item, BackgroundAnalysisScope analysisSc
ImmutableArray<IIncrementalAnalyzer> allAnalyzers,
OptionSet options,
BackgroundAnalysisScope analysisScope,
IAsynchronousOperationListener listener,
[NotNullWhen(returnValue: true)] out WorkItem? newWorkItem)
{
var analyzersToExecute = item.GetApplicableAnalyzers(allAnalyzers);
......@@ -173,7 +176,7 @@ bool ShouldEnqueueForAllQueues(WorkItem item, BackgroundAnalysisScope analysisSc
if (!analyzersWithOverriddenAnalysisScope.IsEmpty)
{
newWorkItem = item.With(analyzersWithOverriddenAnalysisScope);
newWorkItem = item.With(analyzersWithOverriddenAnalysisScope, listener.BeginAsyncOperation("WorkItem"));
return true;
}
......
......@@ -174,10 +174,10 @@ public WorkItem With(DocumentId documentId, ProjectId projectId, IAsyncToken asy
asyncToken);
}
public WorkItem With(ImmutableHashSet<IIncrementalAnalyzer> specificAnalyzers)
public WorkItem With(ImmutableHashSet<IIncrementalAnalyzer> specificAnalyzers, IAsyncToken asyncToken)
{
return new WorkItem(DocumentId, ProjectId, Language, InvocationReasons,
IsLowPriority, ActiveMember, specificAnalyzers, IsRetry, AsyncToken);
IsLowPriority, ActiveMember, specificAnalyzers, IsRetry, asyncToken);
}
public override string ToString()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册