@@ -2717,6 +2717,30 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item) {
27172717 // The output code is limited to that byte range.
27182718 let contents_subset = & contents[ ( byte_min as usize ) ..( byte_max as usize ) ] ;
27192719
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+
27202744 // The call locations need to be updated to reflect that the size of the program has changed.
27212745 // Specifically, the ranges are all subtracted by `byte_min` since that's the new zero point.
27222746 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) {
27262750 let ( byte_lo, byte_hi) = loc. call_expr . byte_span ;
27272751 let ( line_lo, line_hi) = loc. call_expr . line_span ;
27282752 let byte_range = ( byte_lo - byte_min, byte_hi - byte_min) ;
2753+ let byte_ranges = strip_leading_whitespace ( byte_range) ;
2754+
27292755 let line_range = ( line_lo - line_min, line_hi - line_min) ;
27302756 let ( line_url, line_title) = link_to_loc ( call_data, loc) ;
27312757
2732- ( byte_range , ( line_range, line_url, line_title) )
2758+ ( byte_ranges , ( line_range, line_url, line_title) )
27332759 } )
27342760 . unzip ( ) ;
27352761
@@ -2784,8 +2810,8 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item) {
27842810 let root_path = vec ! [ "../" ; cx. current. len( ) - 1 ] . join ( "" ) ;
27852811
27862812 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 ( ) ) ;
27892815
27902816 sources:: print_src (
27912817 w,
0 commit comments