summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHasanAlrimawi <141642411+HasanAlrimawi@users.noreply.github.com>2024-11-16 16:59:31 +0200
committerGitHub <noreply@github.com>2024-11-16 15:59:31 +0100
commitabf06eb87f10ebed93b39948213dccfe086bd0fa (patch)
treef67a1d5f6f0ba8ec7ff666f1029fa225978b242c
parent768c5ea2bb2a927455577a29f0761425593aea98 (diff)
feat(watch): log which file changed on HMR or watch change (#25801)
Closes #25504
-rw-r--r--cli/tools/bench/mod.rs1
-rw-r--r--cli/tools/fmt.rs1
-rw-r--r--cli/tools/lint/mod.rs1
-rw-r--r--cli/tools/run/mod.rs3
-rw-r--r--cli/tools/serve.rs3
-rw-r--r--cli/tools/test/mod.rs1
-rw-r--r--cli/util/file_watcher.rs21
-rw-r--r--tests/integration/watcher_tests.rs2
8 files changed, 20 insertions, 13 deletions
diff --git a/cli/tools/bench/mod.rs b/cli/tools/bench/mod.rs
index 272d06335..1d49fa061 100644
--- a/cli/tools/bench/mod.rs
+++ b/cli/tools/bench/mod.rs
@@ -486,6 +486,7 @@ pub async fn run_benchmarks_with_watch(
),
move |flags, watcher_communicator, changed_paths| {
let bench_flags = bench_flags.clone();
+ watcher_communicator.show_path_changed(changed_paths.clone());
Ok(async move {
let factory = CliFactory::from_flags_for_watcher(
flags,
diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs
index 56b1632cf..2221c0da9 100644
--- a/cli/tools/fmt.rs
+++ b/cli/tools/fmt.rs
@@ -83,6 +83,7 @@ pub async fn format(
file_watcher::PrintConfig::new("Fmt", !watch_flags.no_clear_screen),
move |flags, watcher_communicator, changed_paths| {
let fmt_flags = fmt_flags.clone();
+ watcher_communicator.show_path_changed(changed_paths.clone());
Ok(async move {
let factory = CliFactory::from_flags(flags);
let cli_options = factory.cli_options()?;
diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs
index 36f1cc049..a9c2d0152 100644
--- a/cli/tools/lint/mod.rs
+++ b/cli/tools/lint/mod.rs
@@ -80,6 +80,7 @@ pub async fn lint(
file_watcher::PrintConfig::new("Lint", !watch_flags.no_clear_screen),
move |flags, watcher_communicator, changed_paths| {
let lint_flags = lint_flags.clone();
+ watcher_communicator.show_path_changed(changed_paths.clone());
Ok(async move {
let factory = CliFactory::from_flags(flags);
let cli_options = factory.cli_options()?;
diff --git a/cli/tools/run/mod.rs b/cli/tools/run/mod.rs
index bebb3f588..8fab544ec 100644
--- a/cli/tools/run/mod.rs
+++ b/cli/tools/run/mod.rs
@@ -124,7 +124,8 @@ async fn run_with_watch(
!watch_flags.no_clear_screen,
),
WatcherRestartMode::Automatic,
- move |flags, watcher_communicator, _changed_paths| {
+ move |flags, watcher_communicator, changed_paths| {
+ watcher_communicator.show_path_changed(changed_paths.clone());
Ok(async move {
let factory = CliFactory::from_flags_for_watcher(
flags,
diff --git a/cli/tools/serve.rs b/cli/tools/serve.rs
index e3f9e94f8..d7989140a 100644
--- a/cli/tools/serve.rs
+++ b/cli/tools/serve.rs
@@ -151,7 +151,8 @@ async fn serve_with_watch(
!watch_flags.no_clear_screen,
),
WatcherRestartMode::Automatic,
- move |flags, watcher_communicator, _changed_paths| {
+ move |flags, watcher_communicator, changed_paths| {
+ watcher_communicator.show_path_changed(changed_paths.clone());
Ok(async move {
let factory = CliFactory::from_flags_for_watcher(
flags,
diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs
index 966b0d285..6357ebcae 100644
--- a/cli/tools/test/mod.rs
+++ b/cli/tools/test/mod.rs
@@ -1661,6 +1661,7 @@ pub async fn run_tests_with_watch(
),
move |flags, watcher_communicator, changed_paths| {
let test_flags = test_flags.clone();
+ watcher_communicator.show_path_changed(changed_paths.clone());
Ok(async move {
let factory = CliFactory::from_flags_for_watcher(
flags,
diff --git a/cli/util/file_watcher.rs b/cli/util/file_watcher.rs
index 21ea95e06..eb3fb8c60 100644
--- a/cli/util/file_watcher.rs
+++ b/cli/util/file_watcher.rs
@@ -127,19 +127,12 @@ impl PrintConfig {
}
}
-fn create_print_after_restart_fn(
- banner: &'static str,
- clear_screen: bool,
-) -> impl Fn() {
+fn create_print_after_restart_fn(clear_screen: bool) -> impl Fn() {
move || {
#[allow(clippy::print_stderr)]
if clear_screen && std::io::stderr().is_terminal() {
eprint!("{}", CLEAR_SCREEN);
}
- info!(
- "{} File change detected! Restarting!",
- colors::intense_blue(banner),
- );
}
}
@@ -187,7 +180,15 @@ impl WatcherCommunicator {
}
pub fn print(&self, msg: String) {
- log::info!("{} {}", self.banner, msg);
+ log::info!("{} {}", self.banner, colors::gray(msg));
+ }
+
+ pub fn show_path_changed(&self, changed_paths: Option<Vec<PathBuf>>) {
+ if let Some(paths) = changed_paths {
+ self.print(
+ format!("Restarting! File change detected: {:?}", paths[0]).to_string(),
+ )
+ }
}
}
@@ -263,7 +264,7 @@ where
clear_screen,
} = print_config;
- let print_after_restart = create_print_after_restart_fn(banner, clear_screen);
+ let print_after_restart = create_print_after_restart_fn(clear_screen);
let watcher_communicator = Arc::new(WatcherCommunicator {
paths_to_watch_tx: paths_to_watch_tx.clone(),
changed_paths_rx: changed_paths_rx.resubscribe(),
diff --git a/tests/integration/watcher_tests.rs b/tests/integration/watcher_tests.rs
index e8f264632..055e46af9 100644
--- a/tests/integration/watcher_tests.rs
+++ b/tests/integration/watcher_tests.rs
@@ -55,7 +55,7 @@ where
let mut str = String::new();
while let Some(t) = next_line(stderr_lines).await {
let t = util::strip_ansi_codes(&t);
- if t.starts_with("Watcher File change detected") {
+ if t.starts_with("Watcher Restarting! File change detected") {
continue;
}
if t.starts_with("Watcher") {