@@ -2717,6 +2717,30 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item) {
2717
2717
// The output code is limited to that byte range.
2718
2718
let contents_subset = & contents[ ( byte_min as usize ) ..( byte_max as usize ) ] ;
2719
2719
2720
+ // Given a call-site range, return the set of sub-ranges that exclude leading whitespace
2721
+ // when the range spans multiple lines.
2722
+ let strip_leading_whitespace = |( lo, hi) : ( u32 , u32 ) | -> Vec < ( u32 , u32 ) > {
2723
+ let contents_range = & contents_subset[ ( lo as usize ) ..( hi as usize ) ] ;
2724
+ let mut ignoring_whitespace = false ;
2725
+ let mut ranges = Vec :: new ( ) ;
2726
+ let mut cur_lo = 0 ;
2727
+ for ( idx, chr) in contents_range. char_indices ( ) {
2728
+ let idx = idx as u32 ;
2729
+ if ignoring_whitespace {
2730
+ if !chr. is_whitespace ( ) {
2731
+ ignoring_whitespace = false ;
2732
+ cur_lo = idx;
2733
+ }
2734
+ } else if chr == '\n' {
2735
+ ranges. push ( ( lo + cur_lo, lo + idx) ) ;
2736
+ cur_lo = idx;
2737
+ ignoring_whitespace = true ;
2738
+ }
2739
+ }
2740
+ ranges. push ( ( lo + cur_lo, hi) ) ;
2741
+ ranges
2742
+ } ;
2743
+
2720
2744
// The call locations need to be updated to reflect that the size of the program has changed.
2721
2745
// Specifically, the ranges are all subtracted by `byte_min` since that's the new zero point.
2722
2746
let ( mut byte_ranges, line_ranges) : ( Vec < _ > , Vec < _ > ) = call_data
@@ -2726,10 +2750,12 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item) {
2726
2750
let ( byte_lo, byte_hi) = loc. call_expr . byte_span ;
2727
2751
let ( line_lo, line_hi) = loc. call_expr . line_span ;
2728
2752
let byte_range = ( byte_lo - byte_min, byte_hi - byte_min) ;
2753
+ let byte_ranges = strip_leading_whitespace ( byte_range) ;
2754
+
2729
2755
let line_range = ( line_lo - line_min, line_hi - line_min) ;
2730
2756
let ( line_url, line_title) = link_to_loc ( call_data, loc) ;
2731
2757
2732
- ( byte_range , ( line_range, line_url, line_title) )
2758
+ ( byte_ranges , ( line_range, line_url, line_title) )
2733
2759
} )
2734
2760
. unzip ( ) ;
2735
2761
@@ -2784,8 +2810,8 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item) {
2784
2810
let root_path = vec ! [ "../" ; cx. current. len( ) - 1 ] . join ( "" ) ;
2785
2811
2786
2812
let mut decoration_info = FxHashMap :: default ( ) ;
2787
- decoration_info. insert ( "highlight focus" , vec ! [ byte_ranges. remove( 0 ) ] ) ;
2788
- decoration_info. insert ( "highlight" , byte_ranges) ;
2813
+ decoration_info. insert ( "highlight focus" , byte_ranges. remove ( 0 ) ) ;
2814
+ decoration_info. insert ( "highlight" , byte_ranges. into_iter ( ) . flatten ( ) . collect ( ) ) ;
2789
2815
2790
2816
sources:: print_src (
2791
2817
w,
0 commit comments