diff --git a/crates/typst-cli/src/watch.rs b/crates/typst-cli/src/watch.rs index bc2fdc165..78bf12f08 100644 --- a/crates/typst-cli/src/watch.rs +++ b/crates/typst-cli/src/watch.rs @@ -9,7 +9,6 @@ use codespan_reporting::term::termcolor::WriteColor; use codespan_reporting::term::{self, termcolor}; use ecow::eco_format; use notify::{Event, RecommendedWatcher, RecursiveMode, Watcher as _}; -use same_file::is_same_file; use typst::diag::{bail, StrResult}; use typst::utils::format_duration; @@ -23,12 +22,12 @@ use crate::{print_error, terminal}; pub fn watch(timer: &mut Timer, command: &WatchCommand) -> StrResult<()> { let mut config = CompileConfig::watching(command)?; - let Output::Path(output) = &config.output else { + let Output::Path(_) = &config.output else { bail!("cannot write document to stdout in watch mode"); }; // Create a file system watcher. - let mut watcher = Watcher::new(output.clone())?; + let mut watcher = Watcher::new()?; // Create the world that serves sources, files, and fonts. // Additionally, if any files do not exist, wait until they do. @@ -79,8 +78,6 @@ pub fn watch(timer: &mut Timer, command: &WatchCommand) -> StrResult<()> { /// Watches file system activity. struct Watcher { - /// The output file. We ignore any events for it. - output: PathBuf, /// The underlying watcher. watcher: RecommendedWatcher, /// Notify event receiver. @@ -107,7 +104,7 @@ impl Watcher { const POLL_INTERVAL: Duration = Duration::from_millis(300); /// Create a new, blank watcher. - fn new(output: PathBuf) -> StrResult { + fn new() -> StrResult { // Setup file watching. let (tx, rx) = std::sync::mpsc::channel(); @@ -121,7 +118,6 @@ impl Watcher { .map_err(|err| eco_format!("failed to setup file watching ({err})"))?; Ok(Self { - output, rx, watcher, watched: HashMap::new(), @@ -237,7 +233,7 @@ impl Watcher { /// Whether a watch event is relevant for compilation. fn is_event_relevant(&self, event: ¬ify::Event) -> bool { - let kind_relevant = match &event.kind { + match &event.kind { notify::EventKind::Any => true, notify::EventKind::Access(_) => false, notify::EventKind::Create(_) => true, @@ -250,22 +246,7 @@ impl Watcher { }, notify::EventKind::Remove(_) => true, notify::EventKind::Other => false, - }; - - if !kind_relevant { - return false; } - - // Never recompile because the output file changed. - if event - .paths - .iter() - .all(|path| is_same_file(path, &self.output).unwrap_or(false)) - { - return false; - } - - true } }