@@ -370,6 +370,7 @@ impl<'a> SourceMap<'a> {
370370 pub ( crate ) fn splice_lines < ' b > (
371371 & ' b self ,
372372 mut patches : Vec < Patch < ' b > > ,
373+ fold : bool ,
373374 ) -> Vec < (
374375 String ,
375376 Vec < TrimmedPatch < ' b > > ,
@@ -430,11 +431,16 @@ impl<'a> SourceMap<'a> {
430431 patches. sort_by_key ( |p| p. span . start ) ;
431432
432433 // Find the bounding span.
433- let Some ( lo) = patches. iter ( ) . map ( |p| p. span . start ) . min ( ) else {
434- return Vec :: new ( ) ;
435- } ;
436- let Some ( hi) = patches. iter ( ) . map ( |p| p. span . end ) . max ( ) else {
437- return Vec :: new ( ) ;
434+ let ( lo, hi) = if fold {
435+ let Some ( lo) = patches. iter ( ) . map ( |p| p. span . start ) . min ( ) else {
436+ return Vec :: new ( ) ;
437+ } ;
438+ let Some ( hi) = patches. iter ( ) . map ( |p| p. span . end ) . max ( ) else {
439+ return Vec :: new ( ) ;
440+ } ;
441+ ( lo, hi)
442+ } else {
443+ ( 0 , source_len)
438444 } ;
439445
440446 let lines = self . span_to_lines ( lo..hi) ;
@@ -536,9 +542,19 @@ impl<'a> SourceMap<'a> {
536542 }
537543 }
538544 highlights. push ( std:: mem:: take ( & mut line_highlight) ) ;
539- // if the replacement already ends with a newline, don't print the next line
540- if !buf. ends_with ( '\n' ) {
541- push_trailing ( & mut buf, prev_line, & prev_hi, None ) ;
545+ if fold {
546+ // if the replacement already ends with a newline, don't print the next line
547+ if !buf. ends_with ( '\n' ) {
548+ push_trailing ( & mut buf, prev_line, & prev_hi, None ) ;
549+ }
550+ } else {
551+ // Add the trailing part of the source after the last patch
552+ if let Some ( snippet) = self . span_to_snippet ( prev_hi. byte ..source_len) {
553+ buf. push_str ( snippet) ;
554+ for _ in snippet. matches ( '\n' ) {
555+ highlights. push ( std:: mem:: take ( & mut line_highlight) ) ;
556+ }
557+ }
542558 }
543559 // remove trailing newlines
544560 while buf. ends_with ( '\n' ) {
0 commit comments