Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit910bfef

Browse files
committed
renderer: fix rendering ofsource when it's a single ASCII whitespace
This PR includes a small fix (that I am not at all sure about) and aregression test that fails on current master.The input here is just a single ASCII whitespace with an annotationpointing to immediately after that whitespace. In current master, itgets rendered like this:```error: missing trailing newline at end of file |1 | ... | ^ W292 | = help: Add trailing newline```But I think the insertion of an ellipsis here is not quite right. I wascertainly confused by the output.I don't really understand the formatting code at all, but I believe theellipsis is being inserted by this code:```rustif self.margin.was_cut_left() { // We have stripped some code/whitespace from the beginning, make it clear. buffer.puts(line_offset, code_offset, "...", *lineno_color);}```And `self.margin.was_cut_left()` was returning true because`computed_left` was set to `18446744073709551593`. This kind of value_seems_ like a bug, although some margin values are explicitlyinitialized to `usize::MAX`, so maybe not.Anywho, I tried removing the condition gating the setting of`whitespace_margin`, and that seems to fix this specific case withoutany other _known_ regressions (including across all of `ruff`'s testsuite), but this was mostly a result of me feeling around in the darkhere.
1 parent7132bf3 commit910bfef

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

‎src/renderer/display_list.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,9 +1400,7 @@ fn format_body(
14001400
}
14011401
})
14021402
.sum();
1403-
if line.chars().any(|c| !c.is_whitespace()){
1404-
whitespace_margin =min(whitespace_margin, leading_whitespace);
1405-
}
1403+
whitespace_margin =min(whitespace_margin, leading_whitespace);
14061404
max_line_len =max(max_line_len, line_length);
14071405

14081406
let line_start_index = line_range.0;

‎tests/formatter.rs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,3 +955,29 @@ error: title
955955
let renderer =Renderer::plain();
956956
assert_data_eq!(renderer.render(input).to_string(), expected);
957957
}
958+
959+
// This tests that reasonable rendering is done in an odd case: when the source
960+
// is a single ASCII whitespace and there's annotation pointing to immediately
961+
// after it.
962+
//
963+
// Previously, this would end up with a `...` rendered instead of just the
964+
// space itself. The `...` seems incorrect here because I don't believe any
965+
// trimming occurs (or is needed).
966+
#[test]
967+
fnone_space_annotation(){
968+
let source =" ";
969+
let input =Level::Error.title("title").snippet(
970+
Snippet::source(source)
971+
.fold(false)
972+
.annotation(Level::Error.span(1..1).label("annotation")),
973+
);
974+
let expected ="\
975+
error: title
976+
|
977+
1 |\x20\x20
978+
| ^ annotation
979+
|\
980+
";
981+
let renderer =Renderer::plain();
982+
assert_data_eq!(renderer.render(input).to_string(), expected);
983+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp