Skip to content

Commit 41932eb

Browse files
committed
fix: Use the multi-suggestion-separator between suggestions
1 parent 6964206 commit 41932eb

File tree

2 files changed

+40
-39
lines changed

2 files changed

+40
-39
lines changed

src/renderer/mod.rs

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ impl Renderer {
264264
}
265265
}
266266
let mut message_iter = group.elements.iter().enumerate().peekable();
267-
let mut last_was_suggestion = false;
268267
if let Some(title) = &group.title {
269268
let peek = message_iter.peek().map(|(_, s)| s).copied();
270269
let title_style = if g == 0 {
@@ -299,6 +298,7 @@ impl Renderer {
299298
}
300299
}
301300
let mut seen_primary = false;
301+
let mut last_suggestion_path = None;
302302
while let Some((i, section)) = message_iter.next() {
303303
let peek = message_iter.peek().map(|(_, s)| s).copied();
304304
let is_first = i == 0;
@@ -314,7 +314,6 @@ impl Renderer {
314314
peek.is_some(),
315315
buffer_msg_line_offset,
316316
);
317-
last_was_suggestion = false;
318317
}
319318
Element::Cause(cause) => {
320319
if let Some((source_map, annotated_lines)) =
@@ -354,22 +353,27 @@ impl Renderer {
354353
}
355354
}
356355
}
357-
358-
last_was_suggestion = false;
359356
}
360357
Element::Suggestion(suggestion) => {
361358
let source_map =
362359
SourceMap::new(&suggestion.source, suggestion.line_start);
360+
let matches_previous_suggestion =
361+
last_suggestion_path == Some(suggestion.path.as_ref());
363362
self.emit_suggestion_default(
364363
&mut buffer,
365364
suggestion,
366365
max_line_num_len,
367366
&source_map,
368367
primary_path.or(og_primary_path),
369-
last_was_suggestion,
368+
matches_previous_suggestion,
370369
is_first,
371370
);
372-
last_was_suggestion = true;
371+
372+
if matches!(peek, Some(Element::Suggestion(_))) {
373+
last_suggestion_path = Some(suggestion.path.as_ref());
374+
} else {
375+
last_suggestion_path = None;
376+
}
373377
}
374378

375379
Element::Origin(origin) => {
@@ -384,7 +388,6 @@ impl Renderer {
384388
is_first,
385389
buffer_msg_line_offset,
386390
);
387-
last_was_suggestion = false;
388391
}
389392
Element::Padding(_) => {
390393
let current_line = buffer.num_lines();
@@ -1614,48 +1617,46 @@ impl Renderer {
16141617
max_line_num_len: usize,
16151618
sm: &SourceMap<'_>,
16161619
primary_path: Option<&Cow<'_, str>>,
1617-
is_cont: bool,
1620+
matches_previous_suggestion: bool,
16181621
is_first: bool,
16191622
) {
16201623
let suggestions = sm.splice_lines(suggestion.markers.clone());
16211624

16221625
let buffer_offset = buffer.num_lines();
1623-
let mut row_num = buffer_offset + usize::from(!is_cont);
1624-
for (i, (complete, parts, highlights)) in suggestions.iter().enumerate() {
1626+
let mut row_num = buffer_offset + usize::from(!matches_previous_suggestion);
1627+
for (complete, parts, highlights) in &suggestions {
16251628
let has_deletion = parts
16261629
.iter()
16271630
.any(|p| p.is_deletion(sm) || p.is_destructive_replacement(sm));
16281631
let is_multiline = complete.lines().count() > 1;
16291632

1630-
if i == 0 {
1631-
self.draw_col_separator_start(buffer, row_num - 1, max_line_num_len + 1);
1632-
} else {
1633+
if matches_previous_suggestion {
16331634
buffer.puts(
16341635
row_num - 1,
16351636
max_line_num_len + 1,
16361637
self.multi_suggestion_separator(),
16371638
ElementStyle::LineNumber,
16381639
);
1640+
} else {
1641+
self.draw_col_separator_start(buffer, row_num - 1, max_line_num_len + 1);
16391642
}
16401643
if suggestion.path.as_ref() != primary_path {
16411644
if let Some(path) = suggestion.path.as_ref() {
1642-
let (loc, _) = sm.span_to_locations(parts[0].span.clone());
1643-
// --> file.rs:line:col
1644-
// |
1645-
let arrow = self.file_start(is_first);
1646-
buffer.puts(row_num - 1, 0, arrow, ElementStyle::LineNumber);
1647-
let message = format!("{}:{}:{}", path, loc.line, loc.char + 1);
1648-
if is_cont {
1649-
buffer.append(row_num - 1, &message, ElementStyle::LineAndColumn);
1650-
} else {
1645+
if !matches_previous_suggestion {
1646+
let (loc, _) = sm.span_to_locations(parts[0].span.clone());
1647+
// --> file.rs:line:col
1648+
// |
1649+
let arrow = self.file_start(is_first);
1650+
buffer.puts(row_num - 1, 0, arrow, ElementStyle::LineNumber);
1651+
let message = format!("{}:{}:{}", path, loc.line, loc.char + 1);
16511652
let col = usize::max(max_line_num_len + 1, arrow.len());
16521653
buffer.puts(row_num - 1, col, &message, ElementStyle::LineAndColumn);
1654+
for _ in 0..max_line_num_len {
1655+
buffer.prepend(row_num - 1, " ", ElementStyle::NoStyle);
1656+
}
1657+
self.draw_col_separator_no_space(buffer, row_num, max_line_num_len + 1);
1658+
row_num += 1;
16531659
}
1654-
for _ in 0..max_line_num_len {
1655-
buffer.prepend(row_num - 1, " ", ElementStyle::NoStyle);
1656-
}
1657-
self.draw_col_separator_no_space(buffer, row_num, max_line_num_len + 1);
1658-
row_num += 1;
16591660
}
16601661
}
16611662
let show_code_change = if has_deletion && !is_multiline {

tests/rustc_tests.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4065,11 +4065,11 @@ LL │ let mut iter = IntoIter::new(self);
40654065
help: consider importing one of these structs
40664066
╭╴
40674067
LL + use std::array::IntoIter;
4068-
4068+
40694069
LL + use std::collections::binary_heap::IntoIter;
4070-
4070+
40714071
LL + use std::collections::btree_map::IntoIter;
4072-
4072+
40734073
LL + use std::collections::btree_set::IntoIter;
40744074
╰╴
40754075
╰ and 9 other candidates
@@ -4200,13 +4200,13 @@ LL │ let _ = std::collections::HashMap();
42004200
help: you might have meant to use an associated function to build this type
42014201
╭╴
42024202
LL │ let _ = std::collections::HashMap::new();
4203-
╴ +++++
4203+
╴ +++++
42044204
LL - let _ = std::collections::HashMap();
42054205
LL + let _ = std::collections::HashMap::with_capacity(_);
4206-
4206+
42074207
LL - let _ = std::collections::HashMap();
42084208
LL + let _ = std::collections::HashMap::with_hasher(_);
4209-
4209+
42104210
LL - let _ = std::collections::HashMap();
42114211
LL + let _ = std::collections::HashMap::with_capacity_and_hasher(_, _);
42124212
╰╴
@@ -4374,19 +4374,19 @@ LL - wtf: None,
43744374
LL - x: (),
43754375
LL - })),
43764376
LL + wtf: Some(Box::new(_)),
4377-
4377+
43784378
LL - wtf: Some(Box(U {
43794379
LL - wtf: None,
43804380
LL - x: (),
43814381
LL - })),
43824382
LL + wtf: Some(Box::new_uninit()),
4383-
4383+
43844384
LL - wtf: Some(Box(U {
43854385
LL - wtf: None,
43864386
LL - x: (),
43874387
LL - })),
43884388
LL + wtf: Some(Box::new_zeroed()),
4389-
4389+
43904390
LL - wtf: Some(Box(U {
43914391
LL - wtf: None,
43924392
LL - x: (),
@@ -4522,11 +4522,11 @@ LL │ t.bar();
45224522
help: some of the expressions' fields have a method of the same name
45234523
╭╴
45244524
LL │ t.a0.bar();
4525-
╴ +++
4525+
╴ +++
45264526
LL │ t.a1.bar();
4527-
╴ +++
4527+
╴ +++
45284528
LL │ t.a2.bar();
4529-
╴ +++
4529+
╴ +++
45304530
LL │ t.a3.bar();
45314531
╰╴ +++
45324532
╰ and 6 other candidates

0 commit comments

Comments
 (0)