@@ -1122,11 +1122,16 @@ impl Renderer {
1122
1122
// | x_span
1123
1123
// <EMPTY LINE>
1124
1124
//
1125
+ let mut overlap = vec ! [ false ; annotations. len( ) ] ;
1125
1126
let mut annotations_position = vec ! [ ] ;
1126
1127
let mut line_len: usize = 0 ;
1127
1128
let mut p = 0 ;
1128
1129
for ( i, annotation) in annotations. iter ( ) . enumerate ( ) {
1129
1130
for ( j, next) in annotations. iter ( ) . enumerate ( ) {
1131
+ if overlaps ( next, annotation, 0 ) && j > 1 {
1132
+ overlap[ i] = true ;
1133
+ overlap[ j] = true ;
1134
+ }
1130
1135
if overlaps ( next, annotation, 0 ) // This label overlaps with another one and both
1131
1136
&& annotation. has_label ( ) // take space (they have text and are not
1132
1137
&& j > i // multiline lines).
@@ -1474,6 +1479,39 @@ impl Renderer {
1474
1479
) ;
1475
1480
}
1476
1481
}
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
+ }
1477
1515
annotations_position
1478
1516
. iter ( )
1479
1517
. filter_map ( |& ( _, annotation) | match annotation. annotation_type {
0 commit comments