Skip to content

Implement auto-restarting on rude edit or no-effect change #48752

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

Merged
merged 3 commits into from
May 5, 2025

Conversation

tmat
Copy link
Member

@tmat tmat commented Apr 28, 2025

Using APIs added in dotnet/roslyn#78220, implements auto-restart of a project that have HotReloadAutoRestart property set, or any project if --non-interactive is passed on command line.
dotnet-watch automatically terminates associated processes, rebuilds and re-launches the project whenever a rude edit or no-effect change is detected.

@tmat tmat force-pushed the WatchAutoRestart branch from ab0a1f2 to 7fb9c21 Compare May 2, 2025 00:17
@tmat tmat marked this pull request as ready for review May 2, 2025 00:18
@Copilot Copilot AI review requested due to automatic review settings May 2, 2025 00:18
@tmat tmat requested review from arunchndr and a team as code owners May 2, 2025 00:18
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements auto-restarting behavior when a rude edit or a no-effect change is detected. Key changes include:

  • Updated tests (in ApplyDeltaTests.cs, RuntimeProcessLauncherTests.cs, and CompilationHandlerTests.cs) to validate auto-restart on both rude edits and changes with no effect.
  • Adjustments to the hot reload logic in CompilationHandler.cs and HotReloadDotNetWatcher.cs to incorporate a new GlobalOptions parameter and to handle project auto-restart determination.
  • Addition of the IsAutoRestartEnabled extension method in ProjectGraphNodeExtensions.cs to support the new auto-restart configuration.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/dotnet-watch.Tests/HotReload/RuntimeProcessLauncherTests.cs Removed an outdated process output check to align with the new restart behavior.
test/dotnet-watch.Tests/HotReload/CompilationHandlerTests.cs Updated CompilationHandler instantiation with an extra GlobalOptions parameter.
test/dotnet-watch.Tests/HotReload/ApplyDeltaTests.cs Added new theory tests for auto-restart on rude and no-effect edits and updated assertion messages accordingly.
test/TestAssets/TestProjects/WatchHotReloadApp/Program.cs Updated the class C placeholder to include a comment for later source modifications.
src/BuiltInTools/dotnet-watch/Utilities/ProjectGraphNodeExtensions.cs Added the IsAutoRestartEnabled extension to check the HotReloadAutoRestart property.
src/BuiltInTools/dotnet-watch/HotReloadDotNetWatcher.cs Modified CompilationHandler instantiation to provide Context.Options to the new parameter.
src/BuiltInTools/dotnet-watch/HotReload/CompilationHandler.cs Updated constructor signatures, diagnostic reporting, and process restart logic to support auto-restart.

@tmat
Copy link
Member Author

tmat commented May 5, 2025

@phil-allen-msft @DustinCampbell ptal

@@ -45,6 +45,9 @@ public static string GetAssemblyName(this ProjectGraphNode projectNode)
public static IEnumerable<string> GetCapabilities(this ProjectGraphNode projectNode)
=> projectNode.ProjectInstance.GetItems("ProjectCapability").Select(item => item.EvaluatedInclude);

public static bool IsAutoRestartEnabled(this ProjectGraphNode projectNode)
=> bool.TryParse(projectNode.ProjectInstance.GetPropertyValue("HotReloadAutoRestart"), out var result) && result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this constant be defined somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of that definition. I can make it a const field, but it's ever going to be used here.

Co-authored-by: Dustin Campbell <dustin@teamcampbell.org>
@tmat tmat enabled auto-merge (squash) May 5, 2025 18:15
@tmat tmat merged commit 67f43d9 into dotnet:main May 5, 2025
30 checks passed
@tmat tmat deleted the WatchAutoRestart branch May 5, 2025 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants