From 782945537a03880f96b13eaf6273fd84f736d6c1 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 8 Sep 2026 08:18:32 +0000 Subject: [PATCH] Refactor `scan_files` to reduce nesting Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com> --- cli/src/watch.rs | 50 ++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/cli/src/watch.rs b/cli/src/watch.rs index 9b4eb2ad..d5374dfd 100644 --- a/cli/src/watch.rs +++ b/cli/src/watch.rs @@ -71,29 +71,7 @@ impl FileWatcher { fn scan_files(&self, states: &mut HashMap) -> anyhow::Result<()> { let mut dirs = vec![self.root.clone()]; while let Some(dir) = dirs.pop() { - if dir.is_dir() { - if let Ok(entries) = std::fs::read_dir(dir) { - for entry in entries.flatten() { - let path = entry.path(); - if path.is_dir() { - // Don't watch build or cache directories to prevent infinite loops - let name = path.file_name().unwrap_or_default().to_string_lossy(); - if name != "build" && name != ".git" && name != "target" { - dirs.push(path); - } - } else { - let ext = path.extension().unwrap_or_default().to_string_lossy(); - if ext == "txs" || ext == "ts" { - if let Ok(metadata) = entry.metadata() { - if let Ok(modified) = metadata.modified() { - states.insert(path, modified); - } - } - } - } - } - } - } else { + if !dir.is_dir() { // Root is a single file let ext = self.root.extension().unwrap_or_default().to_string_lossy(); if ext == "txs" || ext == "ts" { @@ -103,6 +81,32 @@ impl FileWatcher { } } } + continue; + } + + if let Ok(entries) = std::fs::read_dir(dir) { + for entry in entries.flatten() { + let path = entry.path(); + if path.is_dir() { + // Don't watch build or cache directories to prevent infinite loops + let name = path.file_name().unwrap_or_default().to_string_lossy(); + if name != "build" && name != ".git" && name != "target" { + dirs.push(path); + } + continue; + } + + let ext = path.extension().unwrap_or_default().to_string_lossy(); + if ext != "txs" && ext != "ts" { + continue; + } + + if let Ok(metadata) = entry.metadata() { + if let Ok(modified) = metadata.modified() { + states.insert(path, modified); + } + } + } } } Ok(())