|
1153 | 1153 | ; long_argument_3 |
1154 | 1154 | ; long_argument_4 |
1155 | 1155 | ; |
1156 | | -; When the last argument is a (parenthesized) function application, end the scope |
| 1156 | +; When the last argument is a (parenthesized) function application, end the indentation |
1157 | 1157 | ; _before_ the application. This allows the following to be formatted as such: |
1158 | 1158 | ; let () = |
1159 | 1159 | ; foo bar (fun x -> |
1160 | | -; something horrible onto x |
| 1160 | +; something horrible onto x |
| 1161 | +; ) |
| 1162 | +; But when the function application minus the last argument is multiline, |
| 1163 | +; the whole scope still must be indented: |
| 1164 | +; let () = |
| 1165 | +; foo |
| 1166 | +; bar |
| 1167 | +; (fun x -> |
| 1168 | +; x |
1161 | 1169 | ; ) |
| 1170 | +; |
| 1171 | +; Because of these constraints, we must use measuring scopes here: the position of the |
| 1172 | +; indent_end depends on the multi-line-ness of a subsection of the whole scope. |
1162 | 1173 | (application_expression |
1163 | 1174 | . |
1164 | | - (_) @append_indent_start @prepend_begin_scope |
| 1175 | + (_) @append_indent_start @prepend_begin_scope @prepend_begin_measuring_scope |
1165 | 1176 | (#scope_id! "function_application") |
1166 | | - (_) @append_indent_end |
| 1177 | + (_) @append_end_scope |
1167 | 1178 | . |
1168 | 1179 | ) |
| 1180 | +; The end of the measuring scope depends on the last argument: if it's a function, |
| 1181 | +; end it before the function, otherwise end it after the last argument. In that case, |
| 1182 | +; it's the same as the regular scope. |
1169 | 1183 | (application_expression |
1170 | 1184 | (#scope_id! "function_application") |
1171 | 1185 | (_ |
1172 | 1186 | [ |
1173 | 1187 | (fun_expression) |
1174 | 1188 | (function_expression) |
1175 | 1189 | ]? @do_nothing |
1176 | | - ) @append_end_scope |
| 1190 | + ) @append_end_measuring_scope |
1177 | 1191 | . |
1178 | 1192 | ) |
1179 | 1193 | (application_expression |
|
1182 | 1196 | [ |
1183 | 1197 | (fun_expression) |
1184 | 1198 | (function_expression) |
1185 | | - ] @prepend_end_scope |
| 1199 | + ] @prepend_end_measuring_scope |
1186 | 1200 | ) |
1187 | 1201 | . |
1188 | 1202 | ) |
| 1203 | +; If the measuring scope is single-line, end indentation _before_ the last node. |
| 1204 | +; Otherwise, end the indentation after the last node. |
| 1205 | +(application_expression |
| 1206 | + (#multi_line_scope_only! "function_application") |
| 1207 | + (_) @append_indent_end |
| 1208 | + . |
| 1209 | +) |
| 1210 | +(application_expression |
| 1211 | + (#single_line_scope_only! "function_application") |
| 1212 | + (_) @prepend_indent_end |
| 1213 | + . |
| 1214 | +) |
| 1215 | +; The node to which we apply append_spaced_scoped_softline will always |
| 1216 | +; be in both scopes, regular and measuring. |
1189 | 1217 | (application_expression |
1190 | 1218 | (_) @append_spaced_scoped_softline |
1191 | 1219 | . |
|
0 commit comments