Skip to content

Commit b5152f6

Browse files
authored
Merge pull request #293 from Muscraft/fix-duplicate-annotations
fix: Allow merging of multiline duplicate annotations
2 parents 551b0d7 + 533d426 commit b5152f6

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

β€Žsrc/renderer/source_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,18 +213,18 @@ impl<'a> SourceMap<'a> {
213213

214214
// Find overlapping multiline annotations, put them at different depths
215215
multiline_annotations.sort_by_key(|ml| (ml.start.line, usize::MAX - ml.end.line));
216-
for ann in multiline_annotations.clone() {
216+
for (outer_i, ann) in multiline_annotations.clone().into_iter().enumerate() {
217217
if ann.kind.is_primary() {
218218
primary_spans.push((ann.start, ann.end));
219219
}
220-
for a in &mut multiline_annotations {
220+
for (inner_i, a) in &mut multiline_annotations.iter_mut().enumerate() {
221221
// Move all other multiline annotations overlapping with this one
222222
// one level to the right.
223223
if !ann.same_span(a)
224224
&& num_overlap(ann.start.line, ann.end.line, a.start.line, a.end.line, true)
225225
{
226226
a.increase_depth();
227-
} else if ann.same_span(a) && &ann != a {
227+
} else if ann.same_span(a) && outer_i != inner_i {
228228
a.overlaps_exactly = true;
229229
} else {
230230
if primary_spans

β€Žtests/formatter.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4235,3 +4235,49 @@ error: showing how tabs are rendered
42354235
let renderer = renderer.decor_style(DecorStyle::Unicode);
42364236
assert_data_eq!(renderer.render(input), expected_unicode);
42374237
}
4238+
4239+
#[test]
4240+
fn duplicate_annotations() {
4241+
let source = r#"foobar
4242+
4243+
foobar πŸš€
4244+
"#;
4245+
let report = &[
4246+
Group::with_title(Level::WARNING.primary_title("whatever")).element(
4247+
Snippet::source(source)
4248+
.path("whatever")
4249+
.annotation(AnnotationKind::Primary.span(0..source.len()).label("blah"))
4250+
.annotation(AnnotationKind::Primary.span(0..source.len()).label("blah")),
4251+
),
4252+
];
4253+
4254+
let expected_ascii = str![[r#"
4255+
warning: whatever
4256+
--> whatever:1:1
4257+
|
4258+
1 | / foobar
4259+
2 | |
4260+
3 | | foobar πŸš€
4261+
| | ^
4262+
| | |
4263+
| |______________________blah
4264+
| blah
4265+
"#]];
4266+
let renderer = Renderer::plain();
4267+
assert_data_eq!(renderer.render(report), expected_ascii);
4268+
4269+
let expected_unicode = str![[r#"
4270+
warning: whatever
4271+
β•­β–Έ whatever:1:1
4272+
β”‚
4273+
1 β”‚ ┏ foobar
4274+
2 β”‚ ┃
4275+
3 β”‚ ┃ foobar πŸš€
4276+
β”‚ ┃ β•Ώ
4277+
β”‚ ┃ β”‚
4278+
β”‚ ┗━━━━━━━━━━━━━━━━━━━━━━blah
4279+
β•°β•΄ blah
4280+
"#]];
4281+
let renderer = renderer.decor_style(DecorStyle::Unicode);
4282+
assert_data_eq!(renderer.render(report), expected_unicode);
4283+
}

0 commit comments

Comments
Β (0)