File tree 3 files changed +74
-1
lines changed
3 files changed +74
-1
lines changed Original file line number Diff line number Diff line change @@ -290,15 +290,24 @@ fn identify_comment(
290
290
) -> ( bool , usize ) {
291
291
let mut first_group_ending = 0 ;
292
292
let mut hbl = false ;
293
+ let mut seen_cb_delimiters = 0 ;
293
294
294
- for line in orig. lines ( ) {
295
+ for ( i , line) in orig. lines ( ) . enumerate ( ) {
295
296
let trimmed_line = line. trim_start ( ) ;
296
297
if trimmed_line. is_empty ( ) {
297
298
hbl = true ;
298
299
break ;
299
300
} else if trimmed_line. starts_with ( line_start)
300
301
|| comment_style ( trimmed_line, false ) == style
301
302
{
303
+ if line. starts_with ( & format ! ( "{}```" , line_start) ) {
304
+ seen_cb_delimiters += 1 ;
305
+ if seen_cb_delimiters % 2 != 0 && i != 0 {
306
+ // Next line is the start of a new code block. Stop here to avoid wrapping
307
+ // the delimiter up when we format the comment group.
308
+ break ;
309
+ }
310
+ }
302
311
first_group_ending += compute_len ( & orig[ first_group_ending..] , line) ;
303
312
} else {
304
313
break ;
Original file line number Diff line number Diff line change
1
+ // rustfmt-wrap_comments: true
2
+ // rustfmt-max_width: 50
3
+
4
+ // This is a long line that will be wrapped on the next line.
5
+ // This line will be wrapped with it.
6
+ // ```
7
+ // this is code that won't
8
+ // even if it also is very very very very very very very very very very very very long
9
+ // ```
10
+ // This is a second long line that will be wrapped on the next line.
11
+ // ```
12
+ // this is code that won't
13
+ // ```
14
+
15
+ /// This is a long line that will be wrapped on the next line.
16
+ /// ```
17
+ /// Should handle code blocks with no end
18
+ fn outer ( ) {
19
+ //! This is a long line that will be wrapped on the next line.
20
+ //! ```rust
21
+ //! assert!(true);
22
+ //! ```
23
+ fn inner ( ) {
24
+ /* This is a long line that will be wrapped on the next line.
25
+ * ```rust
26
+ * assert!(true);
27
+ * ```
28
+ */
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ // rustfmt-wrap_comments: true
2
+ // rustfmt-max_width: 50
3
+
4
+ // This is a long line that will be wrapped on the
5
+ // next line. This line will be wrapped with it.
6
+ // ```
7
+ // this is code that won't
8
+ // even if it also is very very very very very very very very very very very very long
9
+ // ```
10
+ // This is a second long line that will be wrapped
11
+ // on the next line.
12
+ // ```
13
+ // this is code that won't
14
+ // ```
15
+
16
+ /// This is a long line that will be wrapped on
17
+ /// the next line.
18
+ /// ```
19
+ /// Should handle code blocks with no end
20
+ fn outer ( ) {
21
+ //! This is a long line that will be wrapped
22
+ //! on the next line.
23
+ //! ```rust
24
+ //! assert!(true);
25
+ //! ```
26
+ fn inner ( ) {
27
+ /* This is a long line that will be
28
+ * wrapped on the next line.
29
+ * ```rust
30
+ * assert!(true);
31
+ * ```
32
+ */
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments