Skip to content

fix!: Make fold the default #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,11 @@ fn fold(bencher: divan::Bencher<'_, '_>, context: usize) {
.bench_values(|(input, span)| {
let message = &[
Group::with_title(Level::ERROR.title("mismatched types").id("E0308")).element(
Snippet::source(&input)
.fold(true)
.path("src/format.rs")
.annotation(
AnnotationKind::Context
.span(span)
.label("expected `Option<String>` because of return type"),
),
Snippet::source(&input).path("src/format.rs").annotation(
AnnotationKind::Context
.span(span)
.label("expected `Option<String>` because of return type"),
),
),
];

Expand Down
13 changes: 5 additions & 8 deletions examples/custom_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ pub static C: u32 = 0 - 1;
.id("E0080"),
)
.element(
Snippet::source(source)
.path("$DIR/err.rs")
.fold(true)
.annotation(
AnnotationKind::Primary
.span(386..391)
.label("attempt to compute `0_u32 - 1_u32`, which would overflow"),
),
Snippet::source(source).path("$DIR/err.rs").annotation(
AnnotationKind::Primary
.span(386..391)
.label("attempt to compute `0_u32 - 1_u32`, which would overflow"),
),
)];

let renderer = Renderer::styled().theme(OutputTheme::Unicode);
Expand Down
2 changes: 0 additions & 2 deletions examples/custom_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ fn main() {
Snippet::source(source)
.line_start(1)
.path("$DIR/issue-114529-illegal-break-with-value.rs")
.fold(true)
.annotation(
AnnotationKind::Primary
.span(483..581)
Expand All @@ -60,7 +59,6 @@ fn main() {
Snippet::source(source)
.line_start(1)
.path("$DIR/issue-114529-illegal-break-with-value.rs")
.fold(true)
.patch(Patch::new(483..581, "break")),
),
];
Expand Down
1 change: 0 additions & 1 deletion examples/expected_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ fn main() {
Snippet::source(source)
.line_start(26)
.path("examples/footer.rs")
.fold(true)
.annotation(AnnotationKind::Primary.span(193..195).label(
"expected struct `annotate_snippets::snippet::Slice`, found reference",
))
Expand Down
1 change: 1 addition & 0 deletions examples/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fn main() {
Snippet::source(source)
.line_start(51)
.path("src/format.rs")
.fold(false)
.annotation(
AnnotationKind::Context
.span(5..19)
Expand Down
1 change: 0 additions & 1 deletion examples/highlight_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ fn main() {}
.id("E0010"))
.element(
Snippet::source(source)
.fold(true)
.path("$DIR/E0010-teach.rs")
.annotation(
AnnotationKind::Primary
Expand Down
2 changes: 0 additions & 2 deletions examples/highlight_title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ fn main() {
Group::with_title(Level::ERROR.title("mismatched types").id("E0308"))
.element(
Snippet::source(source)
.fold(true)
.path("$DIR/highlighting.rs")
.annotation(
AnnotationKind::Primary
Expand All @@ -61,7 +60,6 @@ fn main() {
.element(Level::NOTE.pre_styled_title(&title)),
Group::with_title(Level::NOTE.title("function defined here")).element(
Snippet::source(source)
.fold(true)
.path("$DIR/highlighting.rs")
.annotation(AnnotationKind::Context.span(200..333).label(""))
.annotation(AnnotationKind::Primary.span(194..199)),
Expand Down
1 change: 0 additions & 1 deletion examples/id_hyperlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ fn main() {
Snippet::source(source)
.line_start(1)
.path("$DIR/terminal_urls.rs")
.fold(true)
.annotation(
AnnotationKind::Primary
.span(59..61)
Expand Down
2 changes: 2 additions & 0 deletions examples/multislice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ fn main() {
.element(
Snippet::<Annotation<'_>>::source("Foo")
.line_start(51)
.fold(false)
.path("src/format.rs"),
)
.element(
Snippet::<Annotation<'_>>::source("Faa")
.line_start(129)
.fold(false)
.path("src/display.rs"),
)];

Expand Down
1 change: 0 additions & 1 deletion src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
//! Snippet::source(source)
//! .path("temp.rs")
//! .line_start(1)
//! .fold(true)
//! .annotation(
//! AnnotationKind::Primary
//! .span(10..13)
Expand Down
2 changes: 1 addition & 1 deletion src/snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<'a, T: Clone> Snippet<'a, T> {
line_start: 1,
source: source.into(),
markers: vec![],
fold: false,
fold: true,
}
}

Expand Down
1 change: 0 additions & 1 deletion tests/color/fold_ann_multiline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ fn case() {
Snippet::source(source)
.path("src/format.rs")
.line_start(51)
.fold(true)
.annotation(AnnotationKind::Context.span(5..19).label(
"expected `std::option::Option<std::string::String>` because of return type",
))
Expand Down
1 change: 0 additions & 1 deletion tests/color/fold_bad_origin_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ invalid syntax
Snippet::source(source)
.path("path/to/error.rs")
.line_start(1)
.fold(true)
.annotation(AnnotationKind::Context.span(2..16).label("error here")),
)];
let expected = file!["fold_bad_origin_line.term.svg"];
Expand Down
1 change: 0 additions & 1 deletion tests/color/fold_leading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ workspace = 20
Snippet::source(source)
.path("Cargo.toml")
.line_start(1)
.fold(true)
.annotation(AnnotationKind::Primary.span(132..134).label("")),
)];
let expected = file!["fold_leading.term.svg"];
Expand Down
1 change: 0 additions & 1 deletion tests/color/fold_trailing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ edition = "2021"
Snippet::source(source)
.path("Cargo.toml")
.line_start(1)
.fold(true)
.annotation(AnnotationKind::Primary.span(8..10).label("")),
)];
let expected = file!["fold_trailing.term.svg"];
Expand Down
3 changes: 1 addition & 2 deletions tests/color/multiline_removal_suggestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ fn main() {}
.element(
Snippet::source(source)
.path("$DIR/multiline-removal-suggestion.rs")
.fold(true)
.annotation(
AnnotationKind::Primary
.span(769..776)
Expand All @@ -96,7 +95,7 @@ fn main() {}
Group::with_title(Level::HELP.title("consider removing this method call, as the receiver has type `std::vec::IntoIter<HashSet<u8>>` and `std::vec::IntoIter<HashSet<u8>>: Iterator` trivially holds")).element(
Snippet::source(source)
.path("$DIR/multiline-removal-suggestion.rs")
.fold(true)

.patch(Patch::new(708..768, "")),
),
];
Expand Down
1 change: 1 addition & 0 deletions tests/color/multiple_annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fn case() {
let input = &[Group::with_title(Level::ERROR.title("")).element(
Snippet::source(source)
.line_start(96)
.fold(false)
.annotation(
AnnotationKind::Primary
.span(100..110)
Expand Down
Loading