Revert "Remove special handling of multi-line primary diagnostic messages and fix tests"

This reverts commit ce4142eab3.
This commit is contained in:
Max Brunsfeld 2022-01-06 14:38:13 -08:00
parent 10548c2038
commit 7357b3ff2a

View file

@ -281,14 +281,17 @@ impl ProjectDiagnosticsEditor {
if is_first_excerpt_for_group { if is_first_excerpt_for_group {
is_first_excerpt_for_group = false; is_first_excerpt_for_group = false;
let primary = &group.entries[group.primary_ix].diagnostic; let primary = &group.entries[group.primary_ix].diagnostic;
let mut header = primary.clone();
header.message =
primary.message.split('\n').next().unwrap().to_string();
group_state.block_count += 1; group_state.block_count += 1;
diagnostic_blocks.push(DiagnosticBlock::Header(primary.clone())); diagnostic_blocks.push(DiagnosticBlock::Header(header.clone()));
blocks_to_add.push(BlockProperties { blocks_to_add.push(BlockProperties {
position: header_position, position: header_position,
height: primary.message.matches('\n').count() as u8 + 2, height: 2,
render: diagnostic_header_renderer( render: diagnostic_header_renderer(
buffer.clone(), buffer.clone(),
primary.clone(), header,
true, true,
self.build_settings.clone(), self.build_settings.clone(),
), ),
@ -306,17 +309,21 @@ impl ProjectDiagnosticsEditor {
} }
for entry in &group.entries[*start_ix..ix] { for entry in &group.entries[*start_ix..ix] {
if !entry.diagnostic.is_primary { let mut diagnostic = entry.diagnostic.clone();
if diagnostic.is_primary {
diagnostic.message =
entry.diagnostic.message.split('\n').skip(1).collect();
}
if !diagnostic.message.is_empty() {
group_state.block_count += 1; group_state.block_count += 1;
diagnostic_blocks diagnostic_blocks
.push(DiagnosticBlock::Inline(entry.diagnostic.clone())); .push(DiagnosticBlock::Inline(diagnostic.clone()));
blocks_to_add.push(BlockProperties { blocks_to_add.push(BlockProperties {
position: (excerpt_id.clone(), entry.range.start.clone()), position: (excerpt_id.clone(), entry.range.start.clone()),
height: entry.diagnostic.message.matches('\n').count() height: diagnostic.message.matches('\n').count() as u8 + 1,
as u8
+ 1,
render: diagnostic_block_renderer( render: diagnostic_block_renderer(
entry.diagnostic.clone(), diagnostic,
true, true,
self.build_settings.clone(), self.build_settings.clone(),
), ),
@ -601,7 +608,7 @@ mod tests {
DiagnosticEntry { DiagnosticEntry {
range: PointUtf16::new(7, 6)..PointUtf16::new(7, 7), range: PointUtf16::new(7, 6)..PointUtf16::new(7, 7),
diagnostic: Diagnostic { diagnostic: Diagnostic {
message: "use of moved value".to_string(), message: "use of moved value\nvalue used here after move".to_string(),
severity: DiagnosticSeverity::ERROR, severity: DiagnosticSeverity::ERROR,
is_primary: true, is_primary: true,
is_disk_based: true, is_disk_based: true,
@ -609,21 +616,10 @@ mod tests {
..Default::default() ..Default::default()
}, },
}, },
DiagnosticEntry {
range: PointUtf16::new(7, 6)..PointUtf16::new(7, 7),
diagnostic: Diagnostic {
message: "value used here after move".to_string(),
severity: DiagnosticSeverity::INFORMATION,
is_primary: false,
is_disk_based: true,
group_id: 0,
..Default::default()
},
},
DiagnosticEntry { DiagnosticEntry {
range: PointUtf16::new(8, 6)..PointUtf16::new(8, 7), range: PointUtf16::new(8, 6)..PointUtf16::new(8, 7),
diagnostic: Diagnostic { diagnostic: Diagnostic {
message: "use of moved value".to_string(), message: "use of moved value\nvalue used here after move".to_string(),
severity: DiagnosticSeverity::ERROR, severity: DiagnosticSeverity::ERROR,
is_primary: true, is_primary: true,
is_disk_based: true, is_disk_based: true,
@ -631,17 +627,6 @@ mod tests {
..Default::default() ..Default::default()
}, },
}, },
DiagnosticEntry {
range: PointUtf16::new(8, 6)..PointUtf16::new(8, 7),
diagnostic: Diagnostic {
message: "value used here after move".to_string(),
severity: DiagnosticSeverity::INFORMATION,
is_primary: false,
is_disk_based: true,
group_id: 1,
..Default::default()
},
},
], ],
cx, cx,
) )
@ -703,30 +688,17 @@ mod tests {
.update_diagnostic_entries( .update_diagnostic_entries(
Arc::from("/test/a.rs".as_ref()), Arc::from("/test/a.rs".as_ref()),
None, None,
vec![ vec![DiagnosticEntry {
DiagnosticEntry { range: PointUtf16::new(0, 15)..PointUtf16::new(0, 15),
range: PointUtf16::new(0, 15)..PointUtf16::new(0, 15), diagnostic: Diagnostic {
diagnostic: Diagnostic { message: "mismatched types\nexpected `usize`, found `char`".to_string(),
message: "mismatched types".to_string(), severity: DiagnosticSeverity::ERROR,
severity: DiagnosticSeverity::ERROR, is_primary: true,
is_primary: true, is_disk_based: true,
is_disk_based: true, group_id: 0,
group_id: 0, ..Default::default()
..Default::default()
},
}, },
DiagnosticEntry { }],
range: PointUtf16::new(0, 15)..PointUtf16::new(0, 15),
diagnostic: Diagnostic {
message: "expected `usize`, found `char`".to_string(),
severity: DiagnosticSeverity::INFORMATION,
is_primary: false,
is_disk_based: true,
group_id: 0,
..Default::default()
},
},
],
cx, cx,
) )
.unwrap(); .unwrap();