mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Warn if layout doesn't stabilize (#1684)
This commit is contained in:
parent
77cc05b121
commit
3c94e05ced
@ -28,7 +28,7 @@ use std::mem::ManuallyDrop;
|
|||||||
|
|
||||||
use comemo::{Track, Tracked, TrackedMut, Validate};
|
use comemo::{Track, Tracked, TrackedMut, Validate};
|
||||||
|
|
||||||
use crate::diag::{SourceDiagnostic, SourceResult};
|
use crate::diag::{warning, SourceDiagnostic, SourceResult};
|
||||||
use crate::doc::Document;
|
use crate::doc::Document;
|
||||||
use crate::eval::Tracer;
|
use crate::eval::Tracer;
|
||||||
use crate::World;
|
use crate::World;
|
||||||
@ -82,7 +82,20 @@ pub fn typeset(
|
|||||||
introspector = ManuallyDrop::new(Introspector::new(&document.pages));
|
introspector = ManuallyDrop::new(Introspector::new(&document.pages));
|
||||||
iter += 1;
|
iter += 1;
|
||||||
|
|
||||||
if iter >= 5 || introspector.validate(&constraint) {
|
if introspector.validate(&constraint) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if iter >= 5 {
|
||||||
|
tracer.warn(
|
||||||
|
warning!(
|
||||||
|
world.main().root().span(),
|
||||||
|
"layout did not converge within 5 attempts",
|
||||||
|
)
|
||||||
|
.with_hint(
|
||||||
|
"check if any states or queries are updating themselves".into(),
|
||||||
|
),
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 46 KiB |
@ -670,8 +670,14 @@ fn parse_part_metadata(source: &Source) -> TestPartMetadata {
|
|||||||
compare_ref = get_flag_metadata(line, "Ref").or(compare_ref);
|
compare_ref = get_flag_metadata(line, "Ref").or(compare_ref);
|
||||||
validate_hints = get_flag_metadata(line, "Hints").or(validate_hints);
|
validate_hints = get_flag_metadata(line, "Hints").or(validate_hints);
|
||||||
|
|
||||||
fn num(s: &mut Scanner) -> usize {
|
fn num(s: &mut Scanner) -> isize {
|
||||||
s.eat_while(char::is_numeric).parse().unwrap()
|
let mut first = true;
|
||||||
|
let n = &s.eat_while(|c: char| {
|
||||||
|
let valid = first && c == '-' || c.is_numeric();
|
||||||
|
first = false;
|
||||||
|
valid
|
||||||
|
});
|
||||||
|
n.parse().unwrap_or_else(|e| panic!("{n} is not a number ({e})"))
|
||||||
}
|
}
|
||||||
|
|
||||||
let comments_until_code =
|
let comments_until_code =
|
||||||
@ -681,8 +687,15 @@ fn parse_part_metadata(source: &Source) -> TestPartMetadata {
|
|||||||
let first = num(s) - 1;
|
let first = num(s) - 1;
|
||||||
let (delta, column) =
|
let (delta, column) =
|
||||||
if s.eat_if(':') { (first, num(s) - 1) } else { (0, first) };
|
if s.eat_if(':') { (first, num(s) - 1) } else { (0, first) };
|
||||||
let line = (i + comments_until_code) + delta;
|
let line = (i + comments_until_code)
|
||||||
source.line_column_to_byte(line, column).unwrap()
|
.checked_add_signed(delta)
|
||||||
|
.expect("line number overflowed limits");
|
||||||
|
source
|
||||||
|
.line_column_to_byte(
|
||||||
|
line,
|
||||||
|
usize::try_from(column).expect("column number overflowed limits"),
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let error_factory: fn(Range<usize>, String) -> UserOutput = UserOutput::error;
|
let error_factory: fn(Range<usize>, String) -> UserOutput = UserOutput::error;
|
||||||
|
@ -46,3 +46,13 @@ Was: #locate(location => {
|
|||||||
#trait[Adventure]
|
#trait[Adventure]
|
||||||
#trait[Fear]
|
#trait[Fear]
|
||||||
#trait[Anger]
|
#trait[Anger]
|
||||||
|
|
||||||
|
---
|
||||||
|
// Make sure that a warning is produced if the layout fails to converge.
|
||||||
|
// Warning: -3:1-6:1 layout did not converge within 5 attempts
|
||||||
|
// Hint: -3:1-6:1 check if any states or queries are updating themselves
|
||||||
|
#let s = state("x", 1)
|
||||||
|
#locate(loc => {
|
||||||
|
s.update(s.final(loc) + 1)
|
||||||
|
})
|
||||||
|
#s.display()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user