mirror of
https://github.com/typst/typst
synced 2025-06-17 02:42:52 +08:00
Warning when watching stdin (#6381)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
parent
1f5846ce24
commit
19325d5027
@ -10,11 +10,12 @@ 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 same_file::is_same_file;
|
||||||
use typst::diag::{bail, StrResult};
|
use typst::diag::{bail, warning, StrResult};
|
||||||
|
use typst::syntax::Span;
|
||||||
use typst::utils::format_duration;
|
use typst::utils::format_duration;
|
||||||
|
|
||||||
use crate::args::{Input, Output, WatchCommand};
|
use crate::args::{Input, Output, WatchCommand};
|
||||||
use crate::compile::{compile_once, CompileConfig};
|
use crate::compile::{compile_once, print_diagnostics, CompileConfig};
|
||||||
use crate::timings::Timer;
|
use crate::timings::Timer;
|
||||||
use crate::world::{SystemWorld, WorldCreationError};
|
use crate::world::{SystemWorld, WorldCreationError};
|
||||||
use crate::{print_error, terminal};
|
use crate::{print_error, terminal};
|
||||||
@ -55,6 +56,11 @@ pub fn watch(timer: &mut Timer, command: &WatchCommand) -> StrResult<()> {
|
|||||||
// Perform initial compilation.
|
// Perform initial compilation.
|
||||||
timer.record(&mut world, |world| compile_once(world, &mut config))??;
|
timer.record(&mut world, |world| compile_once(world, &mut config))??;
|
||||||
|
|
||||||
|
// Print warning when trying to watch stdin.
|
||||||
|
if matches!(&config.input, Input::Stdin) {
|
||||||
|
warn_watching_std(&world, &config)?;
|
||||||
|
}
|
||||||
|
|
||||||
// Recompile whenever something relevant happens.
|
// Recompile whenever something relevant happens.
|
||||||
loop {
|
loop {
|
||||||
// Watch all dependencies of the most recent compilation.
|
// Watch all dependencies of the most recent compilation.
|
||||||
@ -332,3 +338,15 @@ impl Status {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Emits a warning when trying to watch stdin.
|
||||||
|
fn warn_watching_std(world: &SystemWorld, config: &CompileConfig) -> StrResult<()> {
|
||||||
|
let warning = warning!(
|
||||||
|
Span::detached(),
|
||||||
|
"cannot watch changes for stdin";
|
||||||
|
hint: "to recompile on changes, watch a regular file instead";
|
||||||
|
hint: "to compile once and exit, please use `typst compile` instead"
|
||||||
|
);
|
||||||
|
print_diagnostics(world, &[], &[warning], config.diagnostic_format)
|
||||||
|
.map_err(|err| eco_format!("failed to print diagnostics ({err})"))
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user