@@ -58,6 +58,9 @@ struct Annotation {
5858 /// Is this annotation derived from primary span
5959 is_primary : bool ,
6060
61+ /// Is this a large span minimized down to a smaller span
62+ is_minimized : bool ,
63+
6164 /// Optional label to display adjacent to the annotation.
6265 label : Option < String > ,
6366}
@@ -90,6 +93,8 @@ pub enum Style {
9093 UnderlineSecondary ,
9194 LabelPrimary ,
9295 LabelSecondary ,
96+ OldSkoolNoteText ,
97+ OldSkoolNote ,
9398 NoStyle ,
9499}
95100
@@ -382,10 +387,10 @@ impl FileInfo {
382387 // Basically, although this loses information, multi-line spans just
383388 // never look good.
384389
385- let ( line, start_col, mut end_col) = if lines. len ( ) == 1 {
386- ( lines[ 0 ] . line_index , lines[ 0 ] . start_col , lines[ 0 ] . end_col )
390+ let ( line, start_col, mut end_col, is_minimized ) = if lines. len ( ) == 1 {
391+ ( lines[ 0 ] . line_index , lines[ 0 ] . start_col , lines[ 0 ] . end_col , false )
387392 } else {
388- ( lines[ 0 ] . line_index , lines[ 0 ] . start_col , CharPos ( lines[ 0 ] . start_col . 0 + 1 ) )
393+ ( lines[ 0 ] . line_index , lines[ 0 ] . start_col , CharPos ( lines[ 0 ] . start_col . 0 + 1 ) , true )
389394 } ;
390395
391396 // Watch out for "empty spans". If we get a span like 6..6, we
@@ -401,6 +406,7 @@ impl FileInfo {
401406 self . lines [ index] . push_annotation ( start_col,
402407 end_col,
403408 is_primary,
409+ is_minimized,
404410 label) ;
405411 }
406412
@@ -497,6 +503,30 @@ impl FileInfo {
497503 match self . primary_span {
498504 Some ( span) => {
499505 let lo = codemap. lookup_char_pos ( span. lo ) ;
506+ let hi = codemap. lookup_char_pos ( span. hi ) ;
507+ //Before each secondary line in old skool-mode, print the label
508+ //as an old-style note
509+ if !line. annotations [ 0 ] . is_primary {
510+ if let Some ( ann) = line. annotations [ 0 ] . label . clone ( ) {
511+ output. push ( RenderedLine {
512+ text : vec ! [ StyledString {
513+ text: lo. file. name. clone( ) ,
514+ style: Style :: FileNameStyle ,
515+ } , StyledString {
516+ text: format!( ":{}:{}: {}:{} " , lo. line, lo. col. 0 + 1 ,
517+ hi. line, hi. col. 0 +1 ) ,
518+ style: Style :: LineAndColumn ,
519+ } , StyledString {
520+ text: format!( "note: " ) ,
521+ style: Style :: OldSkoolNote ,
522+ } , StyledString {
523+ text: format!( "{}" , ann) ,
524+ style: Style :: OldSkoolNoteText ,
525+ } ] ,
526+ kind : RenderedLineKind :: Annotations ,
527+ } ) ;
528+ }
529+ }
500530 rendered_lines[ 0 ] . text . insert ( 0 , StyledString {
501531 text : format ! ( ":{} " , lo. line) ,
502532 style : Style :: LineAndColumn ,
@@ -598,15 +628,15 @@ impl FileInfo {
598628 if annotation. is_primary {
599629 Style :: UnderlinePrimary
600630 } else {
601- Style :: UnderlineSecondary
631+ Style :: OldSkoolNote
602632 } ) ;
603633 }
604634 else {
605635 styled_buffer. putc ( 1 , p, '~' ,
606636 if annotation. is_primary {
607637 Style :: UnderlinePrimary
608638 } else {
609- Style :: UnderlineSecondary
639+ Style :: OldSkoolNote
610640 } ) ;
611641 }
612642 }
@@ -615,10 +645,14 @@ impl FileInfo {
615645 for p in annotation. start_col .. annotation. end_col {
616646 if annotation. is_primary {
617647 styled_buffer. putc ( 1 , p, '^' , Style :: UnderlinePrimary ) ;
618- styled_buffer. set_style ( 0 , p, Style :: UnderlinePrimary ) ;
648+ if !annotation. is_minimized {
649+ styled_buffer. set_style ( 0 , p, Style :: UnderlinePrimary ) ;
650+ }
619651 } else {
620652 styled_buffer. putc ( 1 , p, '-' , Style :: UnderlineSecondary ) ;
621- styled_buffer. set_style ( 0 , p, Style :: UnderlineSecondary ) ;
653+ if !annotation. is_minimized {
654+ styled_buffer. set_style ( 0 , p, Style :: UnderlineSecondary ) ;
655+ }
622656 }
623657 }
624658 }
@@ -819,11 +853,13 @@ impl Line {
819853 start : CharPos ,
820854 end : CharPos ,
821855 is_primary : bool ,
856+ is_minimized : bool ,
822857 label : Option < String > ) {
823858 self . annotations . push ( Annotation {
824859 start_col : start. 0 ,
825860 end_col : end. 0 ,
826861 is_primary : is_primary,
862+ is_minimized : is_minimized,
827863 label : label,
828864 } ) ;
829865 }
0 commit comments