Skip to content
Open
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
4 changes: 1 addition & 3 deletions src/renderer/display_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1400,9 +1400,7 @@ fn format_body(
}
})
.sum();
if line.chars().any(|c| !c.is_whitespace()) {
whitespace_margin = min(whitespace_margin, leading_whitespace);
}
whitespace_margin = min(whitespace_margin, leading_whitespace);
max_line_len = max(max_line_len, line_length);

let line_start_index = line_range.0;
Expand Down
26 changes: 26 additions & 0 deletions tests/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,3 +955,29 @@ error: title
let renderer = Renderer::plain();
assert_data_eq!(renderer.render(input).to_string(), expected);
}

// This tests that reasonable rendering is done in an odd case: when the source
// is a single ASCII whitespace and there's annotation pointing to immediately
// after it.
//
// Previously, this would end up with a `...` rendered instead of just the
// space itself. The `...` seems incorrect here because I don't believe any
// trimming occurs (or is needed).
#[test]
fn one_space_annotation() {
let source = " ";
let input = Level::Error.title("title").snippet(
Snippet::source(source)
.fold(false)
.annotation(Level::Error.span(1..1).label("annotation")),
);
let expected = "\
error: title
|
1 |\x20\x20
| ^ annotation
|\
";
let renderer = Renderer::plain();
assert_data_eq!(renderer.render(input).to_string(), expected);
}
Loading