1
1
use crate :: renderer:: { char_width, is_different, num_overlap, LineAnnotation , LineAnnotationType } ;
2
2
use crate :: { Annotation , AnnotationKind , Patch } ;
3
3
use std:: borrow:: Cow ;
4
- use std:: cmp:: { max, min} ;
4
+ use std:: cmp:: { max, min, Ordering } ;
5
5
use std:: ops:: Range ;
6
6
7
7
#[ derive( Debug ) ]
@@ -294,12 +294,16 @@ impl<'a> SourceMap<'a> {
294
294
. map_or ( ann. start . line , |( line, _) | line) ;
295
295
for line in ann. start . line + 1 ..until {
296
296
// Every `|` that joins the beginning of the span (`___^`) to the end (`|__^`).
297
- self . add_annotation_to_file ( & mut annotated_line_infos, line, ann. as_line ( ) ) ;
297
+ self . add_annotation_to_file ( & mut annotated_line_infos, line, ann. as_line ( line ) ) ;
298
298
}
299
299
let line_end = ann. end . line - 1 ;
300
300
let end_is_empty = self . get_line ( line_end) . map_or ( false , |s| !filter ( s) ) ;
301
301
if middle < line_end && !end_is_empty {
302
- self . add_annotation_to_file ( & mut annotated_line_infos, line_end, ann. as_line ( ) ) ;
302
+ self . add_annotation_to_file (
303
+ & mut annotated_line_infos,
304
+ line_end,
305
+ ann. as_line ( line_end) ,
306
+ ) ;
303
307
}
304
308
}
305
309
self . add_annotation_to_file ( & mut annotated_line_infos, end_ann. end . line , end_ann) ;
@@ -575,10 +579,16 @@ impl<'a> MultilineAnnotation<'a> {
575
579
}
576
580
}
577
581
578
- pub ( crate ) fn as_line ( & self ) -> LineAnnotation < ' a > {
582
+ pub ( crate ) fn as_line ( & self , line : usize ) -> LineAnnotation < ' a > {
579
583
LineAnnotation {
580
- start : Loc :: default ( ) ,
581
- end : Loc :: default ( ) ,
584
+ start : Loc {
585
+ line,
586
+ ..Default :: default ( )
587
+ } ,
588
+ end : Loc {
589
+ line,
590
+ ..Default :: default ( )
591
+ } ,
582
592
kind : self . kind ,
583
593
label : None ,
584
594
annotation_type : LineAnnotationType :: MultilineLine ( self . depth ) ,
@@ -604,7 +614,7 @@ pub(crate) struct AnnotatedLineInfo<'a> {
604
614
}
605
615
606
616
/// A source code location used for error reporting.
607
- #[ derive( Clone , Copy , Debug , Default , PartialOrd , Ord , PartialEq , Eq ) ]
617
+ #[ derive( Clone , Copy , Debug , Default , Eq ) ]
608
618
pub ( crate ) struct Loc {
609
619
/// The (1-based) line number.
610
620
pub ( crate ) line : usize ,
@@ -616,6 +626,30 @@ pub(crate) struct Loc {
616
626
pub ( crate ) byte : usize ,
617
627
}
618
628
629
+ impl PartialEq for Loc {
630
+ fn eq ( & self , other : & Self ) -> bool {
631
+ self . line . eq ( & other. line ) && self . display . eq ( & other. display ) && self . char . eq ( & other. char )
632
+ }
633
+ }
634
+
635
+ impl Ord for Loc {
636
+ fn cmp ( & self , other : & Self ) -> Ordering {
637
+ match self . line . cmp ( & other. line ) {
638
+ Ordering :: Equal => match self . display . cmp ( & other. display ) {
639
+ Ordering :: Equal => self . char . cmp ( & other. char ) ,
640
+ c => c,
641
+ } ,
642
+ c => c,
643
+ }
644
+ }
645
+ }
646
+
647
+ impl PartialOrd for Loc {
648
+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
649
+ Some ( self . cmp ( other) )
650
+ }
651
+ }
652
+
619
653
struct CursorLines < ' a > ( & ' a str ) ;
620
654
621
655
impl CursorLines < ' _ > {
0 commit comments