@@ -80,9 +80,6 @@ pub fn rule(
80
80
}
81
81
}
82
82
83
- // in
84
- let child = children. get_next ( ) . unwrap ( ) ;
85
- let indent = build_ctx. pos_new . column > 1 ;
86
83
match layout {
87
84
crate :: config:: Layout :: Tall => {
88
85
steps. push_back ( crate :: builder:: Step :: Dedent ) ;
@@ -93,40 +90,69 @@ pub fn rule(
93
90
steps. push_back ( crate :: builder:: Step :: Whitespace ) ;
94
91
}
95
92
}
96
- steps. push_back ( crate :: builder:: Step :: Format ( child. element ) ) ;
93
+
94
+ // in
95
+ let child_in = children. get_next ( ) . unwrap ( ) ;
96
+ let top_level = build_ctx. pos_new . column <= 1 ;
97
+
98
+ // /**/
99
+ let mut child_comments = std:: collections:: LinkedList :: new ( ) ;
100
+ children. drain_comments_and_newlines ( |element| match element {
101
+ crate :: children:: DrainCommentOrNewline :: Comment ( text) => {
102
+ child_comments. push_back ( crate :: builder:: Step :: Comment ( text) )
103
+ }
104
+ crate :: children:: DrainCommentOrNewline :: Newline ( _) => { }
105
+ } ) ;
106
+
107
+ // expr
108
+ let child_expr = children. get_next ( ) . unwrap ( ) ;
109
+
110
+ // in
111
+ steps. push_back ( crate :: builder:: Step :: Format ( child_in. element ) ) ;
97
112
match layout {
98
113
crate :: config:: Layout :: Tall => {
99
- if indent {
100
- steps. push_back ( crate :: builder:: Step :: Indent ) ;
114
+ if child_comments. is_empty ( )
115
+ && matches ! (
116
+ child_expr. element. kind( ) ,
117
+ rnix:: SyntaxKind :: NODE_ATTR_SET
118
+ | rnix:: SyntaxKind :: NODE_LET_IN
119
+ | rnix:: SyntaxKind :: NODE_LIST
120
+ | rnix:: SyntaxKind :: NODE_PAREN
121
+ | rnix:: SyntaxKind :: NODE_STRING
122
+ )
123
+ {
124
+ steps. push_back ( crate :: builder:: Step :: Whitespace ) ;
125
+ } else {
126
+ if !top_level {
127
+ steps. push_back ( crate :: builder:: Step :: Indent ) ;
128
+ }
129
+ steps. push_back ( crate :: builder:: Step :: NewLine ) ;
130
+ steps. push_back ( crate :: builder:: Step :: Pad ) ;
101
131
}
102
132
}
103
133
crate :: config:: Layout :: Wide => { }
104
134
}
105
135
106
136
// /**/
107
- children. drain_comments_and_newlines ( |element| match element {
108
- crate :: children:: DrainCommentOrNewline :: Comment ( text) => {
109
- steps. push_back ( crate :: builder:: Step :: NewLine ) ;
110
- steps. push_back ( crate :: builder:: Step :: Pad ) ;
111
- steps. push_back ( crate :: builder:: Step :: Comment ( text) ) ;
112
- }
113
- crate :: children:: DrainCommentOrNewline :: Newline ( _) => { }
114
- } ) ;
137
+ for comment in child_comments {
138
+ steps. push_back ( comment) ;
139
+ steps. push_back ( crate :: builder:: Step :: NewLine ) ;
140
+ steps. push_back ( crate :: builder:: Step :: Pad ) ;
141
+ }
115
142
116
143
// expr
117
- let child = children. get_next ( ) . unwrap ( ) ;
118
144
match layout {
119
145
crate :: config:: Layout :: Tall => {
120
- steps. push_back ( crate :: builder:: Step :: NewLine ) ;
121
- steps . push_back ( crate :: builder :: Step :: Pad ) ;
122
- steps . push_back ( crate :: builder :: Step :: FormatWider ( child . element ) ) ;
123
- if indent {
146
+ steps. push_back ( crate :: builder:: Step :: FormatWider (
147
+ child_expr . element ,
148
+ ) ) ;
149
+ if !top_level {
124
150
steps. push_back ( crate :: builder:: Step :: Dedent ) ;
125
151
}
126
152
}
127
153
crate :: config:: Layout :: Wide => {
128
154
steps. push_back ( crate :: builder:: Step :: Whitespace ) ;
129
- steps. push_back ( crate :: builder:: Step :: Format ( child . element ) ) ;
155
+ steps. push_back ( crate :: builder:: Step :: Format ( child_expr . element ) ) ;
130
156
}
131
157
}
132
158
0 commit comments