@@ -67,8 +67,8 @@ void apply_formatting_config(
67
67
//
68
68
// Otherwise, we always default to a hang.
69
69
//
70
- // NOTE - any modifications here to child elements could be superseeded later in the recursion
71
- // in order to maintain your sanity, only modify things here that _arent_ touched by default
70
+ // NOTE - any modifications here to child elements could be superseeded later in the recursion!
71
+ // In order to maintain your sanity, only modify things here that _arent_ touched by default
72
72
// configurations. These are explicitly prepended with `parent_mutable_`
73
73
if (!predefined_config) {
74
74
if (curr_node.metadata .is_top_level ) {
@@ -104,6 +104,8 @@ void apply_formatting_config(
104
104
}
105
105
// If we are hanging, lets determine the indentation width since it is based on the form itself
106
106
if (curr_node.formatting_config .hang_forms ) {
107
+ // TODO - this isn't being calculated for a pre-defined config
108
+ // TODO - another idea is to do this during consolidation
107
109
curr_node.formatting_config .indentation_width = hang_indentation_width (curr_node);
108
110
}
109
111
// iterate through the refs
@@ -123,6 +125,7 @@ void apply_formatting_config(
123
125
}
124
126
}
125
127
128
+ // TODO - this doesn't account for paren's width contribution!
126
129
int get_total_form_inlined_width (const FormatterTreeNode& curr_node) {
127
130
if (curr_node.token ) {
128
131
return curr_node.token ->length ();
@@ -191,17 +194,20 @@ bool can_node_be_inlined(const FormatterTreeNode& curr_node, int cursor_pos) {
191
194
}
192
195
193
196
std::vector<std::string> apply_formatting (const FormatterTreeNode& curr_node,
194
- std::vector<std::string> output = {},
197
+ std::vector<std::string> /* output*/ = {},
195
198
int cursor_pos = 0 ) {
196
199
using namespace formatter_rules ;
197
200
if (!curr_node.token && curr_node.refs .empty ()) {
198
201
// special case to handle an empty list
202
+ if (curr_node.node_prefix ) {
203
+ return {fmt::format (" {}()" , curr_node.node_prefix .value ())};
204
+ }
199
205
return {" ()" };
200
206
}
201
207
202
208
// If its a token, just print the token and move on
203
209
if (curr_node.token ) {
204
- return {curr_node.token . value ()};
210
+ return {curr_node.token_str ()};
205
211
}
206
212
207
213
bool inline_form = can_node_be_inlined (curr_node, cursor_pos);
@@ -220,13 +226,19 @@ std::vector<std::string> apply_formatting(const FormatterTreeNode& curr_node,
220
226
// Add new line entry
221
227
if (ref.token ) {
222
228
// Cleanup block-comments
223
- std::string val = ref.token . value ();
229
+ std::string val = ref.token_str ();
224
230
if (ref.metadata .node_type == " block_comment" ) {
225
231
// TODO - change this sanitization to return a list of lines instead of a single new-lined
226
232
// line
227
- val = comments::format_block_comment (ref.token . value ());
233
+ val = comments::format_block_comment (ref.token_str ());
228
234
}
229
235
form_lines.push_back (val);
236
+ if (!curr_node.metadata .is_top_level && i == curr_node.refs .size () - 1 &&
237
+ (ref.metadata .is_comment )) {
238
+ // if there's an inline comment at the end of a form, we have to force the paren to the next
239
+ // line and do a new-line paren this is ugly, but we have no choice!
240
+ form_lines.push_back (" " );
241
+ }
230
242
} else {
231
243
// If it's not a token, we have to recursively build up the form
232
244
// TODO - add the cursor_pos here
@@ -250,6 +262,9 @@ std::vector<std::string> apply_formatting(const FormatterTreeNode& curr_node,
250
262
if ((next_ref.metadata .node_type == " comment" && next_ref.metadata .is_inline ) ||
251
263
(curr_node.formatting_config .has_constant_pairs &&
252
264
constant_pairs::is_element_second_in_constant_pair (curr_node, next_ref, i + 1 ))) {
265
+ // TODO
266
+ // has issues with not consolidating first lines, this should probably just be moved to
267
+ // outside this loop for simplicity, do it later
253
268
if (next_ref.token ) {
254
269
form_lines.at (form_lines.size () - 1 ) += fmt::format (" {}" , next_ref.token .value ());
255
270
i++;
@@ -260,6 +275,10 @@ std::vector<std::string> apply_formatting(const FormatterTreeNode& curr_node,
260
275
}
261
276
i++;
262
277
}
278
+ if (!curr_node.metadata .is_top_level && next_ref.metadata .node_type == " comment" &&
279
+ (i + 1 ) == (int )curr_node.refs .size ()) {
280
+ form_lines.push_back (" " );
281
+ }
263
282
}
264
283
}
265
284
// If we are at the top level, potential separate with a new line
@@ -288,6 +307,9 @@ std::vector<std::string> apply_formatting(const FormatterTreeNode& curr_node,
288
307
// Apply necessary indentation to each line and add parens
289
308
if (!curr_node.metadata .is_top_level ) {
290
309
std::string form_surround_start = " (" ;
310
+ if (curr_node.node_prefix ) {
311
+ form_surround_start = fmt::format (" {}(" , curr_node.node_prefix .value ());
312
+ }
291
313
std::string form_surround_end = " )" ;
292
314
form_lines[0 ] = fmt::format (" {}{}" , form_surround_start, form_lines[0 ]);
293
315
form_lines[form_lines.size () - 1 ] =
0 commit comments