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

fix: Tweak rendering ofsource when it's a single ASCII whitespace#169

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
BurntSushi wants to merge1 commit intorust-lang:master
base:master
Choose a base branch
Loading
fromBurntSushi:ag/handle-single-space
Open
Show file tree
Hide file tree
Changes fromall 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 deletionssrc/renderer/display_list.rs
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionstests/formatter.rs
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp