Skip to content

Commit ae1e73a

Browse files
author
Jonathan Turner
committed
Print secondary labels as notes in old skool mode
1 parent 5743564 commit ae1e73a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/libsyntax/errors/emitter.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,9 @@ impl Destination {
524524
}
525525
Style::Quotation => {
526526
}
527+
Style::OldSkoolNote => {
528+
self.start_attr(term::Attr::Bold)?;
529+
}
527530
Style::UnderlinePrimary | Style::LabelPrimary => {
528531
self.start_attr(term::Attr::Bold)?;
529532
self.start_attr(term::Attr::ForegroundColor(lvl.color()))?;

src/libsyntax/errors/snippet/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub enum Style {
9090
UnderlineSecondary,
9191
LabelPrimary,
9292
LabelSecondary,
93+
OldSkoolNote,
9394
NoStyle,
9495
}
9596

@@ -497,6 +498,28 @@ impl FileInfo {
497498
match self.primary_span {
498499
Some(span) => {
499500
let lo = codemap.lookup_char_pos(span.lo);
501+
//Before each secondary line in old skool-mode, print the label
502+
//as an old-style note
503+
if !line.annotations[0].is_primary {
504+
if let Some(ann) = line.annotations[0].label.clone() {
505+
output.push(RenderedLine {
506+
text: vec![StyledString {
507+
text: lo.file.name.clone(),
508+
style: Style::FileNameStyle,
509+
}, StyledString {
510+
text: format!(":{}:{}: ", lo.line, lo.col.0 + 1),
511+
style: Style::LineAndColumn,
512+
}, StyledString {
513+
text: format!("note: "),
514+
style: Style::LabelSecondary,
515+
}, StyledString {
516+
text: format!("{}", ann),
517+
style: Style::OldSkoolNote,
518+
}],
519+
kind: RenderedLineKind::Annotations,
520+
});
521+
}
522+
}
500523
rendered_lines[0].text.insert(0, StyledString {
501524
text: format!(":{} ", lo.line),
502525
style: Style::LineAndColumn,

0 commit comments

Comments
 (0)