@@ -67,8 +67,8 @@ void apply_formatting_config(
6767 //
6868 // Otherwise, we always default to a hang.
6969 //
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
7272 // configurations. These are explicitly prepended with `parent_mutable_`
7373 if (!predefined_config) {
7474 if (curr_node.metadata .is_top_level ) {
@@ -104,6 +104,8 @@ void apply_formatting_config(
104104 }
105105 // If we are hanging, lets determine the indentation width since it is based on the form itself
106106 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
107109 curr_node.formatting_config .indentation_width = hang_indentation_width (curr_node);
108110 }
109111 // iterate through the refs
@@ -123,6 +125,7 @@ void apply_formatting_config(
123125 }
124126}
125127
128+ // TODO - this doesn't account for paren's width contribution!
126129int get_total_form_inlined_width (const FormatterTreeNode& curr_node) {
127130 if (curr_node.token ) {
128131 return curr_node.token ->length ();
@@ -196,12 +199,15 @@ std::vector<std::string> apply_formatting(const FormatterTreeNode& curr_node,
196199 using namespace formatter_rules ;
197200 if (!curr_node.token && curr_node.refs .empty ()) {
198201 // special case to handle an empty list
202+ if (curr_node.node_prefix ) {
203+ return {fmt::format (" {}()" , curr_node.node_prefix .value ())};
204+ }
199205 return {" ()" };
200206 }
201207
202208 // If its a token, just print the token and move on
203209 if (curr_node.token ) {
204- return {curr_node.token . value ()};
210+ return {curr_node.token_str ()};
205211 }
206212
207213 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,
220226 // Add new line entry
221227 if (ref.token ) {
222228 // Cleanup block-comments
223- std::string val = ref.token . value ();
229+ std::string val = ref.token_str ();
224230 if (ref.metadata .node_type == " block_comment" ) {
225231 // TODO - change this sanitization to return a list of lines instead of a single new-lined
226232 // line
227- val = comments::format_block_comment (ref.token . value ());
233+ val = comments::format_block_comment (ref.token_str ());
228234 }
229235 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+ }
230242 } else {
231243 // If it's not a token, we have to recursively build up the form
232244 // TODO - add the cursor_pos here
@@ -250,6 +262,9 @@ std::vector<std::string> apply_formatting(const FormatterTreeNode& curr_node,
250262 if ((next_ref.metadata .node_type == " comment" && next_ref.metadata .is_inline ) ||
251263 (curr_node.formatting_config .has_constant_pairs &&
252264 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
253268 if (next_ref.token ) {
254269 form_lines.at (form_lines.size () - 1 ) += fmt::format (" {}" , next_ref.token .value ());
255270 i++;
@@ -260,6 +275,10 @@ std::vector<std::string> apply_formatting(const FormatterTreeNode& curr_node,
260275 }
261276 i++;
262277 }
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+ }
263282 }
264283 }
265284 // 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,
288307 // Apply necessary indentation to each line and add parens
289308 if (!curr_node.metadata .is_top_level ) {
290309 std::string form_surround_start = " (" ;
310+ if (curr_node.node_prefix ) {
311+ form_surround_start = fmt::format (" {}(" , curr_node.node_prefix .value ());
312+ }
291313 std::string form_surround_end = " )" ;
292314 form_lines[0 ] = fmt::format (" {}{}" , form_surround_start, form_lines[0 ]);
293315 form_lines[form_lines.size () - 1 ] =
0 commit comments