From b119113e8d96288c75b4347ab35cdedb897a06b8 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Fri, 17 Dec 2021 12:22:49 -0800 Subject: [PATCH] Run solution crawler on source generated documents that change --- .../SolutionCrawler/WorkCoordinator.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.cs b/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.cs index 832aaad45c68a..5e515f4e28336 100644 --- a/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.cs +++ b/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.cs @@ -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) @@ -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()