Skip to content

Commit

Permalink
fix(remotecontrol): Ensure generators run after a referenced project …
Browse files Browse the repository at this point in the history
…file update
  • Loading branch information
jeromelaban committed Jan 17, 2023
1 parent a12175b commit db174a8
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ private void ObserveSolutionPaths(Solution solution)
{
var observedPaths =
solution.Projects
.SelectMany(p => p.Documents.Select(d => Path.GetDirectoryName(d.FilePath)))
.SelectMany(p => p
.Documents
.Select(d => d.FilePath)
.Concat(p.AdditionalDocuments
.Select(d => d.FilePath)))
.Select(p => Path.GetDirectoryName(p))
.Distinct()
.ToArray();

Expand Down Expand Up @@ -170,6 +175,16 @@ private async Task<bool> ProcessSolutionChanged(CancellationToken cancellationTo
var sourceText = await GetSourceTextAsync(file);
updatedSolution = _currentSolution.WithAdditionalDocumentText(additionalDocument.Id, sourceText, PreservationMode.PreserveValue);
updatedProjectId = additionalDocument.Project.Id;

// Generate an empty document to force the generators to run
// in a separate project of the same solution. This is not needed
// for the head project, but it's no causing issues either.
var docName = Guid.NewGuid().ToString();
updatedSolution = updatedSolution.AddAdditionalDocument(
DocumentId.CreateNewId(updatedProjectId),
docName,
SourceText.From("")
);
}
else
{
Expand All @@ -178,9 +193,10 @@ private async Task<bool> ProcessSolutionChanged(CancellationToken cancellationTo
return false;
}


var (updates, hotReloadDiagnostics) = await _hotReloadService.EmitSolutionUpdateAsync(updatedSolution, cancellationToken);

Console.WriteLine($"Got results after {sw.Elapsed}");
_reporter.Output($"Found {updates.Length} metadata updates after {sw.Elapsed}");

if (hotReloadDiagnostics.IsDefaultOrEmpty && updates.IsDefaultOrEmpty)
{
Expand Down Expand Up @@ -225,6 +241,10 @@ private async Task<bool> ProcessSolutionChanged(CancellationToken cancellationTo

async Task UpdateMetadata(string file, ImmutableArray<WatchHotReloadService.Update> updates)
{
#if DEBUG
_reporter.Output($"Sending {updates.Length} metadata updates for {file}");
#endif

for (int i = 0; i < updates.Length; i++)
{
var updateTypesWriterStream = new MemoryStream();
Expand Down

0 comments on commit db174a8

Please sign in to comment.