@@ -442,6 +442,42 @@ impl<'a> DisplaySet<'a> {
442
442
line_len += 1 ;
443
443
}
444
444
445
+ // This is a special case where we have a multiline
446
+ // annotation that is at the start of the line disregarding
447
+ // any leading whitespace, and no other multiline
448
+ // annotations overlap it. In this case, we want to draw
449
+ //
450
+ // 2 | fn foo() {
451
+ // | _^
452
+ // 3 | |
453
+ // 4 | | }
454
+ // | |_^ test
455
+ //
456
+ // we simplify the output to:
457
+ //
458
+ // 2 | / fn foo() {
459
+ // 3 | |
460
+ // 4 | | }
461
+ // | |_^ test
462
+ if multiline_depth == 1
463
+ && annotations_positions. len ( ) == 1
464
+ && annotations_positions
465
+ . first ( )
466
+ . map_or ( false , |( _, annotation) | {
467
+ matches ! (
468
+ annotation. annotation_part,
469
+ DisplayAnnotationPart :: MultilineStart ( _)
470
+ ) && text
471
+ . chars ( )
472
+ . take ( annotation. range . 0 )
473
+ . all ( |c| c. is_whitespace ( ) )
474
+ } )
475
+ {
476
+ let ( _, ann) = annotations_positions. remove ( 0 ) ;
477
+ let style = get_annotation_style ( & ann. annotation_type , stylesheet) ;
478
+ buffer. putc ( line_offset, 3 + lineno_width, '/' , * style) ;
479
+ }
480
+
445
481
// Draw the column separator for any extra lines that were
446
482
// created
447
483
//
@@ -535,15 +571,13 @@ impl<'a> DisplaySet<'a> {
535
571
// Add in any inline marks for any extra lines that have
536
572
// been created. Output should look like above.
537
573
for inline_mark in inline_marks {
538
- if let DisplayMarkType :: AnnotationThrough ( depth) = inline_mark. mark_type {
539
- let style =
540
- get_annotation_style ( & inline_mark. annotation_type , stylesheet) ;
541
- if annotations_positions. is_empty ( ) {
542
- buffer. putc ( line_offset, width_offset + depth, '|' , * style) ;
543
- } else {
544
- for p in line_offset..=line_offset + line_len + 1 {
545
- buffer. putc ( p, width_offset + depth, '|' , * style) ;
546
- }
574
+ let DisplayMarkType :: AnnotationThrough ( depth) = inline_mark. mark_type ;
575
+ let style = get_annotation_style ( & inline_mark. annotation_type , stylesheet) ;
576
+ if annotations_positions. is_empty ( ) {
577
+ buffer. putc ( line_offset, width_offset + depth, '|' , * style) ;
578
+ } else {
579
+ for p in line_offset..=line_offset + line_len + 1 {
580
+ buffer. putc ( p, width_offset + depth, '|' , * style) ;
547
581
}
548
582
}
549
583
}
@@ -823,8 +857,6 @@ pub(crate) struct DisplayMark {
823
857
pub ( crate ) enum DisplayMarkType {
824
858
/// A mark indicating a multiline annotation going through the current line.
825
859
AnnotationThrough ( usize ) ,
826
- /// A mark indicating a multiline annotation starting on the given line.
827
- AnnotationStart ,
828
860
}
829
861
830
862
/// A type of the `Annotation` which may impact the sigils, style or text displayed.
@@ -1153,18 +1185,8 @@ fn fold_body(body: Vec<DisplayLine<'_>>) -> Vec<DisplayLine<'_>> {
1153
1185
let mut unhighlighed_lines = vec ! [ ] ;
1154
1186
for line in body {
1155
1187
match & line {
1156
- DisplayLine :: Source {
1157
- annotations,
1158
- inline_marks,
1159
- ..
1160
- } => {
1161
- if annotations. is_empty ( )
1162
- // A multiline start mark (`/`) needs be treated as an
1163
- // annotation or the line could get folded.
1164
- && inline_marks
1165
- . iter ( )
1166
- . all ( |m| m. mark_type != DisplayMarkType :: AnnotationStart )
1167
- {
1188
+ DisplayLine :: Source { annotations, .. } => {
1189
+ if annotations. is_empty ( ) {
1168
1190
unhighlighed_lines. push ( line) ;
1169
1191
} else {
1170
1192
if lines. is_empty ( ) {
@@ -1407,20 +1429,7 @@ fn format_body(
1407
1429
&& start <= line_end_index + end_line_size. saturating_sub ( 1 )
1408
1430
&& end > line_end_index =>
1409
1431
{
1410
- // Special case for multiline annotations that start at the
1411
- // beginning of a line, which requires a special mark (`/`)
1412
- if start - line_start_index == 0 {
1413
- if let DisplayLine :: Source {
1414
- ref mut inline_marks,
1415
- ..
1416
- } = body[ body_idx]
1417
- {
1418
- inline_marks. push ( DisplayMark {
1419
- mark_type : DisplayMarkType :: AnnotationStart ,
1420
- annotation_type : DisplayAnnotationType :: from ( annotation. level ) ,
1421
- } ) ;
1422
- }
1423
- } else if let DisplayLine :: Source {
1432
+ if let DisplayLine :: Source {
1424
1433
ref mut annotations,
1425
1434
..
1426
1435
} = body[ body_idx]
@@ -1679,9 +1688,6 @@ fn format_inline_marks(
1679
1688
DisplayMarkType :: AnnotationThrough ( depth) => {
1680
1689
buf. putc ( line, 3 + lineno_width + depth, '|' , * annotation_style) ;
1681
1690
}
1682
- DisplayMarkType :: AnnotationStart => {
1683
- buf. putc ( line, 3 + lineno_width, '/' , * annotation_style) ;
1684
- }
1685
1691
} ;
1686
1692
}
1687
1693
Ok ( ( ) )
0 commit comments