Skip to content

Commit

Permalink
Enqueue additional and analyzer config documents in WorkCoordinator
Browse files Browse the repository at this point in the history
Fixes dotnet#53192
Currently, work coordinator only enqueues source document IDs for project analysis work items. This means we don't analyze the additional documents, which can now report standalone diagnostics through RegisterAdditionalFileAction. This PR fixes this by enqueuing project's additional document IDs and analyzer config document IDs.
  • Loading branch information
mavasani committed Dec 24, 2021
1 parent 678b269 commit 6e9947a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
25 changes: 24 additions & 1 deletion src/EditorFeatures/Test/SolutionCrawler/WorkCoordinatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ internal async Task Project_AnalyzerOptions_Change(BackgroundAnalysisScope analy

Assert.Equal(expectedDocumentEvents, worker.SyntaxDocumentIds.Count);
Assert.Equal(expectedDocumentEvents, worker.DocumentIds.Count);

Assert.Equal(1, worker.NonSourceDocumentIds.Count);
}

[InlineData(BackgroundAnalysisScope.ActiveFile, false)]
Expand Down Expand Up @@ -701,22 +703,26 @@ internal async Task Document_AdditionalFileChange(BackgroundAnalysisScope analys

var expectedDocumentSyntaxEvents = 5;
var expectedDocumentSemanticEvents = 5;
var expectedNonSourceDocumentEvents = 1;

var ncfile = DocumentInfo.Create(DocumentId.CreateNewId(project.Id), "D6");

var worker = await ExecuteOperation(workspace, w => w.OnAdditionalDocumentAdded(ncfile));
Assert.Equal(expectedDocumentSyntaxEvents, worker.SyntaxDocumentIds.Count);
Assert.Equal(expectedDocumentSemanticEvents, worker.DocumentIds.Count);
Assert.Equal(expectedNonSourceDocumentEvents, worker.NonSourceDocumentIds.Count);

worker = await ExecuteOperation(workspace, w => w.ChangeAdditionalDocument(ncfile.Id, SourceText.From("//")));

Assert.Equal(expectedDocumentSyntaxEvents, worker.SyntaxDocumentIds.Count);
Assert.Equal(expectedDocumentSemanticEvents, worker.DocumentIds.Count);
Assert.Equal(expectedNonSourceDocumentEvents, worker.NonSourceDocumentIds.Count);

worker = await ExecuteOperation(workspace, w => w.OnAdditionalDocumentRemoved(ncfile.Id));

Assert.Equal(expectedDocumentSyntaxEvents, worker.SyntaxDocumentIds.Count);
Assert.Equal(expectedDocumentSemanticEvents, worker.DocumentIds.Count);
Assert.Empty(worker.NonSourceDocumentIds);
}

[InlineData(BackgroundAnalysisScope.ActiveFile, false)]
Expand Down Expand Up @@ -1619,7 +1625,7 @@ internal static class Metadata
public static readonly IncrementalAnalyzerProviderMetadata Crawler = new IncrementalAnalyzerProviderMetadata(new Dictionary<string, object> { { "WorkspaceKinds", new[] { SolutionCrawlerWorkspaceKind } }, { "HighPriorityForActiveFile", false }, { "Name", "TestAnalyzer" } });
}

private class Analyzer : IIncrementalAnalyzer
private class Analyzer : IIncrementalAnalyzer2
{
public static readonly Option<bool> TestOption = new Option<bool>("TestOptions", "TestOption", defaultValue: true);

Expand All @@ -1628,6 +1634,7 @@ private class Analyzer : IIncrementalAnalyzer

public readonly HashSet<DocumentId> SyntaxDocumentIds = new HashSet<DocumentId>();
public readonly HashSet<DocumentId> DocumentIds = new HashSet<DocumentId>();
public readonly HashSet<DocumentId> NonSourceDocumentIds = new HashSet<DocumentId>();
public readonly HashSet<ProjectId> ProjectIds = new HashSet<ProjectId>();

public readonly HashSet<DocumentId> InvalidateDocumentIds = new HashSet<DocumentId>();
Expand All @@ -1653,6 +1660,7 @@ public void Reset()

SyntaxDocumentIds.Clear();
DocumentIds.Clear();
NonSourceDocumentIds.Clear();
ProjectIds.Clear();

InvalidateDocumentIds.Clear();
Expand Down Expand Up @@ -1682,6 +1690,12 @@ public Task AnalyzeSyntaxAsync(Document document, InvocationReasons reasons, Can
return Task.CompletedTask;
}

public Task AnalyzeNonSourceDocumentAsync(TextDocument textDocument, InvocationReasons reasons, CancellationToken cancellationToken)
{
this.NonSourceDocumentIds.Add(textDocument.Id);
return Task.CompletedTask;
}

public Task RemoveDocumentAsync(DocumentId documentId, CancellationToken cancellationToken)
{
InvalidateDocumentIds.Add(documentId);
Expand Down Expand Up @@ -1732,6 +1746,15 @@ public Task DocumentCloseAsync(Document document, CancellationToken cancellation

public Task DocumentResetAsync(Document document, CancellationToken cancellationToken)
=> Task.CompletedTask;

public Task NonSourceDocumentOpenAsync(TextDocument textDocument, CancellationToken cancellationToken)
=> Task.CompletedTask;

public Task NonSourceDocumentCloseAsync(TextDocument textDocument, CancellationToken cancellationToken)
=> Task.CompletedTask;

public Task NonSourceDocumentResetAsync(TextDocument textDocument, CancellationToken cancellationToken)
=> Task.CompletedTask;
#endregion
}

Expand Down
5 changes: 3 additions & 2 deletions src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ private async Task EnqueueWorkItemAsync(Project project, DocumentId documentId,
_shutdownToken.ThrowIfCancellationRequested();

var priorityService = project.GetLanguageService<IWorkCoordinatorPriorityService>();
var isLowPriority = priorityService != null && await priorityService.IsLowPriorityAsync(GetRequiredDocument(project, documentId, document), _shutdownToken).ConfigureAwait(false);
document ??= project.GetDocument(documentId);
var isLowPriority = priorityService != null && document != null && await priorityService.IsLowPriorityAsync(document, _shutdownToken).ConfigureAwait(false);

var currentMember = GetSyntaxPath(changedMember);

Expand Down Expand Up @@ -473,7 +474,7 @@ private static Document GetRequiredDocument(Project project, DocumentId document

private async Task EnqueueWorkItemAsync(Project project, InvocationReasons invocationReasons)
{
foreach (var documentId in project.DocumentIds)
foreach (var documentId in project.DocumentIds.Concat(project.AdditionalDocumentIds).Concat(project.AnalyzerConfigDocumentIds))
await EnqueueWorkItemAsync(project, documentId, document: null, invocationReasons).ConfigureAwait(false);
}

Expand Down

0 comments on commit 6e9947a

Please sign in to comment.