Skip to content

Commit

Permalink
Run solution crawler on source generated documents that change
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Dec 21, 2021
1 parent be04df3 commit b119113
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,9 @@ private async Task EnqueueWorkItemAsync(Project project, InvocationReasons invoc
{
foreach (var documentId in project.DocumentIds)
await EnqueueWorkItemAsync(project, documentId, document: null, invocationReasons).ConfigureAwait(false);

foreach (var document in await project.GetSourceGeneratedDocumentsAsync(CancellationToken.None).ConfigureAwait(false))
await EnqueueWorkItemAsync(project, document.Id, document, invocationReasons).ConfigureAwait(false);
}

private async Task EnqueueWorkItemAsync(IIncrementalAnalyzer analyzer, ReanalyzeScope scope, bool highPriority)
Expand Down Expand Up @@ -636,6 +639,34 @@ private async Task EnqueueWorkItemAfterDiffAsync(Solution oldSolution, Solution
var newProject = newSolution.GetRequiredProject(documentId.ProjectId);

await EnqueueWorkItemAsync(oldProject.GetRequiredDocument(documentId), newProject.GetRequiredDocument(documentId)).ConfigureAwait(continueOnCapturedContext: false);

var oldProjectSourceGeneratedDocuments = await oldProject.GetSourceGeneratedDocumentsAsync(CancellationToken.None).ConfigureAwait(false);
var oldProjectSourceGeneratedDocumentsById = oldProjectSourceGeneratedDocuments.ToDictionary(static document => document.Id);
var newProjectSourceGeneratedDocuments = await newProject.GetSourceGeneratedDocumentsAsync(CancellationToken.None).ConfigureAwait(false);
var newProjectSourceGeneratedDocumentsById = newProjectSourceGeneratedDocuments.ToDictionary(static document => document.Id);

foreach (var (oldDocumentId, _) in oldProjectSourceGeneratedDocumentsById)
{
if (!newProjectSourceGeneratedDocumentsById.ContainsKey(oldDocumentId))
{
// This source generated document was removed
EnqueueEvent(oldSolution, oldDocumentId, InvocationReasons.DocumentRemoved, "OnWorkspaceChanged");
}
}

foreach (var (newDocumentId, newDocument) in newProjectSourceGeneratedDocumentsById)
{
if (!oldProjectSourceGeneratedDocumentsById.TryGetValue(newDocumentId, out var oldDocument))
{
// This source generated document was added
EnqueueEvent(newSolution, newDocumentId, InvocationReasons.DocumentAdded, "OnWorkspaceChanged");
}
else
{
// This source generated document may have changed
await EnqueueWorkItemAsync(oldDocument, newDocument).ConfigureAwait(continueOnCapturedContext: false);
}
}
}

internal TestAccessor GetTestAccessor()
Expand Down

0 comments on commit b119113

Please sign in to comment.