@@ -9,6 +9,7 @@ use crate::shape::{Indent, Shape};
9
9
use crate :: source_map:: LineRangeUtils ;
10
10
use crate :: utils:: { count_lf_crlf, count_newlines, last_line_width, mk_sp} ;
11
11
use crate :: visitor:: FmtVisitor ;
12
+ use crate :: Config ;
12
13
13
14
struct SnippetStatus {
14
15
/// An offset to the current line from the beginning of the original snippet.
@@ -112,27 +113,9 @@ impl<'a> FmtVisitor<'a> {
112
113
}
113
114
}
114
115
115
- fn push_vertical_spaces ( & mut self , mut newline_count : usize ) {
116
- let offset = self . buffer . chars ( ) . rev ( ) . take_while ( |c| * c == '\n' ) . count ( ) ;
117
- let newline_upper_bound = self . config . blank_lines_upper_bound ( ) + 1 ;
118
- let newline_lower_bound = self . config . blank_lines_lower_bound ( ) + 1 ;
119
-
120
- if newline_count + offset > newline_upper_bound {
121
- if offset >= newline_upper_bound {
122
- newline_count = 0 ;
123
- } else {
124
- newline_count = newline_upper_bound - offset;
125
- }
126
- } else if newline_count + offset < newline_lower_bound {
127
- if offset >= newline_lower_bound {
128
- newline_count = 0 ;
129
- } else {
130
- newline_count = newline_lower_bound - offset;
131
- }
132
- }
133
-
134
- let blank_lines = "\n " . repeat ( newline_count) ;
135
- self . push_str ( & blank_lines) ;
116
+ fn push_vertical_spaces ( & mut self , newline_count : usize ) {
117
+ let newlines_pushed = push_vertical_spaces ( & mut self . buffer , self . config , newline_count) ;
118
+ self . line_number += newlines_pushed;
136
119
}
137
120
138
121
fn write_snippet < F > ( & mut self , span : Span , process_last_snippet : F )
@@ -361,3 +344,31 @@ impl<'a> FmtVisitor<'a> {
361
344
}
362
345
}
363
346
}
347
+
348
+ pub ( crate ) fn push_vertical_spaces (
349
+ buffer : & mut String ,
350
+ config : & Config ,
351
+ mut newline_count : usize ,
352
+ ) -> usize {
353
+ let offset = buffer. chars ( ) . rev ( ) . take_while ( |c| * c == '\n' ) . count ( ) ;
354
+ let newline_upper_bound = config. blank_lines_upper_bound ( ) + 1 ;
355
+ let newline_lower_bound = config. blank_lines_lower_bound ( ) + 1 ;
356
+
357
+ if newline_count + offset > newline_upper_bound {
358
+ if offset >= newline_upper_bound {
359
+ newline_count = 0 ;
360
+ } else {
361
+ newline_count = newline_upper_bound - offset;
362
+ }
363
+ } else if newline_count + offset < newline_lower_bound {
364
+ if offset >= newline_lower_bound {
365
+ newline_count = 0 ;
366
+ } else {
367
+ newline_count = newline_lower_bound - offset;
368
+ }
369
+ }
370
+
371
+ let blank_lines = "\n " . repeat ( newline_count) ;
372
+ buffer. push_str ( & blank_lines) ;
373
+ newline_count
374
+ }
0 commit comments