File tree Expand file tree Collapse file tree 6 files changed +36
-4
lines changed
tools/src/format/test_data/format_data Expand file tree Collapse file tree 6 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -245,6 +245,14 @@ impl<'p> Printer<'p> {
245
245
match self . comments . pop_front ( ) {
246
246
Some ( comment) => {
247
247
self . writeln ( & comment. node . text ) ;
248
+ match self . comments . front ( ) {
249
+ Some ( next_comment) => {
250
+ if next_comment. line >= comment. line + 2 && count > 0 {
251
+ self . write_newline ( ) ;
252
+ }
253
+ }
254
+ None => { }
255
+ }
248
256
}
249
257
None => break ,
250
258
}
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ impl<'p, 'ctx> MutSelfTypedResultWalker<'ctx> for Printer<'p> {
39
39
if let Some ( doc) = & module. doc {
40
40
self . write ( & doc. node ) ;
41
41
self . write_newline ( ) ;
42
+ self . write_newline ( ) ;
42
43
}
43
44
44
45
self . stmts ( & module. body ) ;
@@ -993,9 +994,13 @@ impl<'p> Printer<'p> {
993
994
// Do not format out user-reserved blank lines: which does not mean that to preserve all user-written blank lines.
994
995
// For situations where there are more than two blank lines, we only keep one blank line.
995
996
let need_newline = if let Some ( prev_stmt) = prev_stmt {
996
- stmt. line > 0
997
- && stmt. line >= prev_stmt. end_line + 2
998
- && !self . has_comments_on_node ( stmt)
997
+ if stmt. line > prev_stmt. end_line + 2 {
998
+ true
999
+ } else if stmt. line == prev_stmt. end_line + 2 {
1000
+ stmt. line > 0 && !self . has_comments_on_node ( stmt)
1001
+ } else {
1002
+ false
1003
+ }
999
1004
} else {
1000
1005
false
1001
1006
} ;
Original file line number Diff line number Diff line change 1
1
"""
2
2
Module documents
3
3
"""
4
+
4
5
import math as alias_math
5
6
6
7
schema Person(Base):
@@ -111,6 +112,7 @@ joined_data_3 = '''\
111
112
joined_data_4 = '''\
112
113
\${CC}
113
114
'''
115
+
114
116
# Member access and index assign targets
115
117
a[0].b -= 1
116
118
a.b[0] += 1
Original file line number Diff line number Diff line change @@ -77,4 +77,10 @@ data = [ # Comment One
77
77
2 # Comment Five
78
78
# Comment Six
79
79
*[3, 4] # Comment Seven
80
- ]
80
+ ]
81
+
82
+ # This is a comment
83
+ foo = "bar"
84
+
85
+ # This is another comment
86
+ fizz = "bazz"
Original file line number Diff line number Diff line change @@ -34,10 +34,13 @@ appConfiguration = AppConfiguration {
34
34
name: "kusion_override"
35
35
}
36
36
# Comment Seven
37
+
37
38
# Comment Eight
38
39
overQuota: True
39
40
}
41
+
40
42
# Comment Nine
43
+
41
44
# Deprecated
42
45
@Deprecated()
43
46
schema Foo:
@@ -91,3 +94,9 @@ data = [
91
94
# Comment Seven
92
95
*[3, 4]
93
96
]
97
+
98
+ # This is a comment
99
+ foo = "bar"
100
+
101
+ # This is another comment
102
+ fizz = "bazz"
Original file line number Diff line number Diff line change 2
2
# Inline comment 2
3
3
# Inline comment 3
4
4
a = 1
5
+
5
6
# Inline comment 4
6
7
# Inline comment 5
7
8
#
11
12
#
12
13
# Inline comment 8
13
14
b = 2
15
+
14
16
# Same inline comment
15
17
# Same inline comment
16
18
# Same inline comment
You can’t perform that action at this time.
0 commit comments