@@ -1122,11 +1122,16 @@ impl Renderer {
11221122 // | x_span
11231123 // <EMPTY LINE>
11241124 //
1125+ let mut overlap = vec ! [ false ; annotations. len( ) ] ;
11251126 let mut annotations_position = vec ! [ ] ;
11261127 let mut line_len: usize = 0 ;
11271128 let mut p = 0 ;
11281129 for ( i, annotation) in annotations. iter ( ) . enumerate ( ) {
11291130 for ( j, next) in annotations. iter ( ) . enumerate ( ) {
1131+ if overlaps ( next, annotation, 0 ) && j > 1 {
1132+ overlap[ i] = true ;
1133+ overlap[ j] = true ;
1134+ }
11301135 if overlaps ( next, annotation, 0 ) // This label overlaps with another one and both
11311136 && annotation. has_label ( ) // take space (they have text and are not
11321137 && j > i // multiline lines).
@@ -1474,6 +1479,39 @@ impl Renderer {
14741479 ) ;
14751480 }
14761481 }
1482+
1483+ // We look for individual *long* spans, and we trim the *middle*, so that we render
1484+ // LL | ...= [0, 0, 0, ..., 0, 0];
1485+ // | ^^^^^^^^^^...^^^^^^^ expected `&[u8]`, found `[{integer}; 1680]`
1486+ for ( i, ( _pos, annotation) ) in annotations_position. iter ( ) . enumerate ( ) {
1487+ // Skip cases where multiple spans overlap eachother.
1488+ if overlap[ i] {
1489+ continue ;
1490+ } ;
1491+ let LineAnnotationType :: Singleline = annotation. annotation_type else {
1492+ continue ;
1493+ } ;
1494+ let width = annotation. end . display - annotation. start . display ;
1495+ if width > margin. term_width * 2 && width > 10 {
1496+ // If the terminal is *too* small, we keep at least a tiny bit of the span for
1497+ // display.
1498+ let pad = max ( margin. term_width / 3 , 5 ) ;
1499+ // Code line
1500+ buffer. replace (
1501+ line_offset,
1502+ annotation. start . display + pad,
1503+ annotation. end . display - pad,
1504+ self . margin ( ) ,
1505+ ) ;
1506+ // Underline line
1507+ buffer. replace (
1508+ line_offset + 1 ,
1509+ annotation. start . display + pad,
1510+ annotation. end . display - pad,
1511+ self . margin ( ) ,
1512+ ) ;
1513+ }
1514+ }
14771515 annotations_position
14781516 . iter ( )
14791517 . filter_map ( |& ( _, annotation) | match annotation. annotation_type {
0 commit comments