Skip to content
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
5 changes: 4 additions & 1 deletion src/renderer/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,10 @@ fn emit_suggestion_default(
// too bad to begin with, so we side-step that issue here.
for (i, line) in snippet.lines().enumerate() {
let line = normalize_whitespace(line);
let row = row_num - 2 - (newlines - i - 1);
// Going lower than buffer_offset (+ 1) would mean
// overwriting existing content in the buffer
let min_row = buffer_offset + usize::from(!matches_previous_suggestion);
let row = (row_num - 2 - (newlines - i - 1)).max(min_row);
// On the first line, we highlight between the start of the part
// span, and the end of that line.
// On the last line, we highlight between the start of the line, and
Expand Down
62 changes: 62 additions & 0 deletions tests/color/highlight_duplicated_diff_lines.ascii.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions tests/color/highlight_duplicated_diff_lines.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Level, Patch, Renderer, Snippet};

use snapbox::{assert_data_eq, file};

#[test]
fn case() {
// https://github.com/rust-lang/rust/blob/4b94758d2ba7d0ef71ccf5fde29ce4bc5d6fe2a4/tests/ui/argument-suggestions/wrong-highlight-span-extra-arguments-147070.rs

let source = r#"struct Thingie;

impl Thingie {
pub(crate) fn new(
_a: String,
_b: String,
_c: String,
_d: String,
_e: String,
_f: String,
) -> Self {
unimplemented!()
}
}

fn main() {
let foo = Thingie::new(
String::from(""),
String::from(""),
String::from(""),
String::from(""),
String::from(""),
String::from(""),
String::from(""),
);
}"#;

let path = "$DIR/wrong-highlight-span-extra-arguments-147070.rs";

let report = &[
Level::ERROR
.primary_title("this function takes 6 arguments but 7 arguments were supplied")
.id("E0061")
.element(
Snippet::source(source)
.path(path)
.annotation(
AnnotationKind::Context
.span(429..445)
.label("unexpected argument #7 of type `String`"),
)
.annotation(AnnotationKind::Primary.span(251..263)),
),
Level::NOTE
.secondary_title("associated function defined here")
.element(
Snippet::source(source)
.path(path)
.annotation(AnnotationKind::Primary.span(50..53)),
),
Level::HELP
.secondary_title("remove the extra argument")
.element(
Snippet::source(source)
.path(path)
.patch(Patch::new(419..445, "")),
),
];

let expected_ascii = file!["highlight_duplicated_diff_lines.ascii.term.svg": TermSvg];
let renderer = Renderer::styled();
assert_data_eq!(renderer.render(report), expected_ascii);

let expected_unicode = file!["highlight_duplicated_diff_lines.unicode.term.svg": TermSvg];
let renderer = renderer.decor_style(DecorStyle::Unicode);
assert_data_eq!(renderer.render(report), expected_unicode);
}
62 changes: 62 additions & 0 deletions tests/color/highlight_duplicated_diff_lines.unicode.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/color/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ mod fold_ann_multiline;
mod fold_bad_origin_line;
mod fold_leading;
mod fold_trailing;
mod highlight_duplicated_diff_lines;
mod highlight_source;
mod issue_9;
mod multiline_removal_suggestion;
mod multiple_annotations;
mod multiple_highlight_duplicated;
mod multiple_multiline_removal;
mod primary_title_second_group;
mod simple;
mod strip_line;
Expand Down
78 changes: 78 additions & 0 deletions tests/color/multiple_highlight_duplicated.ascii.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading