@@ -58,6 +58,9 @@ struct Annotation {
58
58
/// Is this annotation derived from primary span
59
59
is_primary : bool ,
60
60
61
+ /// Is this a large span minimized down to a smaller span
62
+ is_minimized : bool ,
63
+
61
64
/// Optional label to display adjacent to the annotation.
62
65
label : Option < String > ,
63
66
}
@@ -90,6 +93,8 @@ pub enum Style {
90
93
UnderlineSecondary ,
91
94
LabelPrimary ,
92
95
LabelSecondary ,
96
+ OldSkoolNoteText ,
97
+ OldSkoolNote ,
93
98
NoStyle ,
94
99
}
95
100
@@ -382,10 +387,10 @@ impl FileInfo {
382
387
// Basically, although this loses information, multi-line spans just
383
388
// never look good.
384
389
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 )
387
392
} 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 )
389
394
} ;
390
395
391
396
// Watch out for "empty spans". If we get a span like 6..6, we
@@ -401,6 +406,7 @@ impl FileInfo {
401
406
self . lines [ index] . push_annotation ( start_col,
402
407
end_col,
403
408
is_primary,
409
+ is_minimized,
404
410
label) ;
405
411
}
406
412
@@ -497,6 +503,30 @@ impl FileInfo {
497
503
match self . primary_span {
498
504
Some ( span) => {
499
505
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
+ }
500
530
rendered_lines[ 0 ] . text . insert ( 0 , StyledString {
501
531
text : format ! ( ":{} " , lo. line) ,
502
532
style : Style :: LineAndColumn ,
@@ -598,15 +628,15 @@ impl FileInfo {
598
628
if annotation. is_primary {
599
629
Style :: UnderlinePrimary
600
630
} else {
601
- Style :: UnderlineSecondary
631
+ Style :: OldSkoolNote
602
632
} ) ;
603
633
}
604
634
else {
605
635
styled_buffer. putc ( 1 , p, '~' ,
606
636
if annotation. is_primary {
607
637
Style :: UnderlinePrimary
608
638
} else {
609
- Style :: UnderlineSecondary
639
+ Style :: OldSkoolNote
610
640
} ) ;
611
641
}
612
642
}
@@ -615,10 +645,14 @@ impl FileInfo {
615
645
for p in annotation. start_col .. annotation. end_col {
616
646
if annotation. is_primary {
617
647
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
+ }
619
651
} else {
620
652
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
+ }
622
656
}
623
657
}
624
658
}
@@ -819,11 +853,13 @@ impl Line {
819
853
start : CharPos ,
820
854
end : CharPos ,
821
855
is_primary : bool ,
856
+ is_minimized : bool ,
822
857
label : Option < String > ) {
823
858
self . annotations . push ( Annotation {
824
859
start_col : start. 0 ,
825
860
end_col : end. 0 ,
826
861
is_primary : is_primary,
862
+ is_minimized : is_minimized,
827
863
label : label,
828
864
} ) ;
829
865
}
0 commit comments