Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async diagnostics analyzer work queue #2351

Merged
merged 22 commits into from
Sep 25, 2023
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix merge
  • Loading branch information
neoGeneva committed May 11, 2022
commit a180b16a955a7ee6e5f3f6a0695f150300948689
Original file line number Diff line number Diff line change
@@ -32,11 +32,7 @@ public class CSharpDiagnosticWorkerWithAnalyzers : ICsDiagnosticWorker, IDisposa
private readonly OmniSharpOptions _options;
private readonly OmniSharpWorkspace _workspace;

<<<<<<< HEAD
private int _projectCount = 0;
=======
private const int WorkerWait = 250;
>>>>>>> master

public CSharpDiagnosticWorkerWithAnalyzers(
OmniSharpWorkspace workspace,
@@ -122,39 +118,7 @@ private async Task Worker()
item = await _workQueue.TakeWorkAsync();
(documentId, cancellationToken, workType, documentCount, remaining) = item;

<<<<<<< HEAD
if (workType == AnalyzerWorkType.Background)
=======
var documents = _workQueue
.TakeWork(workType)
.Select(documentId => (projectId: solution.GetDocument(documentId)?.Project?.Id, documentId))
.Where(x => x.projectId != null)
.ToImmutableArray();

if (documents.IsEmpty)
{
_workQueue.WorkComplete(workType);

await Task.Delay(WorkerWait);

continue;
}

var documentCount = documents.Length;
var documentCountRemaining = documentCount;

// event every percentage increase, or every 10th if there are fewer than 1000
var eventEvery = Math.Max(10, documentCount / 100);

var documentsGroupedByProjects = documents
.GroupBy(x => x.projectId, x => x.documentId)
.ToImmutableArray();
var projectCount = documentsGroupedByProjects.Length;

EventIfBackgroundWork(workType, BackgroundDiagnosticStatus.Started, projectCount, documentCount, documentCountRemaining);

void decrementDocumentCountRemaining()
>>>>>>> master
{
// event every percentage increase, or every 10th if there are fewer than 1000
var eventEvery = Math.Max(10, documentCount / 100);
@@ -180,17 +144,10 @@ void decrementDocumentCountRemaining()
if (remaining == 0)
EventIfBackgroundWork(workType, BackgroundDiagnosticStatus.Finished, _projectCount, documentCount, remaining);
}
<<<<<<< HEAD
}
catch (OperationCanceledException) when (cancellationToken != null && cancellationToken.Value.IsCancellationRequested)
{
_logger.LogInformation($"Analyzer work cancelled.");
=======

_workQueue.WorkComplete(workType);

await Task.Delay(WorkerWait);
>>>>>>> master
}
catch (Exception ex)
{
@@ -265,12 +222,7 @@ public async Task<IEnumerable<Diagnostic>> AnalyzeDocumentAsync(Document documen
var allAnalyzers = GetAnalyzersForProject(project);
var compilation = await project.GetCompilationAsync(cancellationToken);

<<<<<<< HEAD
return await AnalyzeDocument(project, allAnalyzers, compilation, CreateAnalyzerOptions(document.Project), document, cancellationToken);
=======
cancellationToken.ThrowIfCancellationRequested();
return await AnalyzeDocument(project, allAnalyzers, compilation, CreateAnalyzerOptions(document.Project), document);
>>>>>>> master
}

public async Task<IEnumerable<Diagnostic>> AnalyzeProjectsAsync(Project project, CancellationToken cancellationToken)