mirror of
https://github.com/typst/typst
synced 2025-08-12 14:17:55 +08:00
remove the output file check in watcher
This commit is contained in:
parent
0576a2fe9f
commit
77b4c28877
@ -9,7 +9,6 @@ use codespan_reporting::term::termcolor::WriteColor;
|
|||||||
use codespan_reporting::term::{self, termcolor};
|
use codespan_reporting::term::{self, termcolor};
|
||||||
use ecow::eco_format;
|
use ecow::eco_format;
|
||||||
use notify::{Event, RecommendedWatcher, RecursiveMode, Watcher as _};
|
use notify::{Event, RecommendedWatcher, RecursiveMode, Watcher as _};
|
||||||
use same_file::is_same_file;
|
|
||||||
use typst::diag::{bail, StrResult};
|
use typst::diag::{bail, StrResult};
|
||||||
use typst::utils::format_duration;
|
use typst::utils::format_duration;
|
||||||
|
|
||||||
@ -23,12 +22,12 @@ use crate::{print_error, terminal};
|
|||||||
pub fn watch(timer: &mut Timer, command: &WatchCommand) -> StrResult<()> {
|
pub fn watch(timer: &mut Timer, command: &WatchCommand) -> StrResult<()> {
|
||||||
let mut config = CompileConfig::watching(command)?;
|
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");
|
bail!("cannot write document to stdout in watch mode");
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create a file system watcher.
|
// 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.
|
// Create the world that serves sources, files, and fonts.
|
||||||
// Additionally, if any files do not exist, wait until they do.
|
// 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.
|
/// Watches file system activity.
|
||||||
struct Watcher {
|
struct Watcher {
|
||||||
/// The output file. We ignore any events for it.
|
|
||||||
output: PathBuf,
|
|
||||||
/// The underlying watcher.
|
/// The underlying watcher.
|
||||||
watcher: RecommendedWatcher,
|
watcher: RecommendedWatcher,
|
||||||
/// Notify event receiver.
|
/// Notify event receiver.
|
||||||
@ -107,7 +104,7 @@ impl Watcher {
|
|||||||
const POLL_INTERVAL: Duration = Duration::from_millis(300);
|
const POLL_INTERVAL: Duration = Duration::from_millis(300);
|
||||||
|
|
||||||
/// Create a new, blank watcher.
|
/// Create a new, blank watcher.
|
||||||
fn new(output: PathBuf) -> StrResult<Self> {
|
fn new() -> StrResult<Self> {
|
||||||
// Setup file watching.
|
// Setup file watching.
|
||||||
let (tx, rx) = std::sync::mpsc::channel();
|
let (tx, rx) = std::sync::mpsc::channel();
|
||||||
|
|
||||||
@ -121,7 +118,6 @@ impl Watcher {
|
|||||||
.map_err(|err| eco_format!("failed to setup file watching ({err})"))?;
|
.map_err(|err| eco_format!("failed to setup file watching ({err})"))?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
output,
|
|
||||||
rx,
|
rx,
|
||||||
watcher,
|
watcher,
|
||||||
watched: HashMap::new(),
|
watched: HashMap::new(),
|
||||||
@ -237,7 +233,7 @@ impl Watcher {
|
|||||||
|
|
||||||
/// Whether a watch event is relevant for compilation.
|
/// Whether a watch event is relevant for compilation.
|
||||||
fn is_event_relevant(&self, event: ¬ify::Event) -> bool {
|
fn is_event_relevant(&self, event: ¬ify::Event) -> bool {
|
||||||
let kind_relevant = match &event.kind {
|
match &event.kind {
|
||||||
notify::EventKind::Any => true,
|
notify::EventKind::Any => true,
|
||||||
notify::EventKind::Access(_) => false,
|
notify::EventKind::Access(_) => false,
|
||||||
notify::EventKind::Create(_) => true,
|
notify::EventKind::Create(_) => true,
|
||||||
@ -250,22 +246,7 @@ impl Watcher {
|
|||||||
},
|
},
|
||||||
notify::EventKind::Remove(_) => true,
|
notify::EventKind::Remove(_) => true,
|
||||||
notify::EventKind::Other => false,
|
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user