diff --git a/common/formatter/formatter.cpp b/common/formatter/formatter.cpp index e4eaf82456..68ca4867d2 100644 --- a/common/formatter/formatter.cpp +++ b/common/formatter/formatter.cpp @@ -288,8 +288,12 @@ std::vector apply_formatting(const FormatterTreeNode& curr_node, } // Consolidate any lines if the configuration requires it + // TODO there is a hack here so that multi-line forms that are consolidated still line up properly + // i have to make consolidate a more first-class feature of the config if (curr_node.formatting_config.inline_until_index(form_lines)) { std::vector new_form_lines = {}; + const auto original_form_head_width = str_util::split(form_lines.at(0), '\n').at(0).length(); + bool consolidating_lines = true; for (int i = 0; i < (int)form_lines.size(); i++) { if (i < curr_node.formatting_config.inline_until_index(form_lines)) { if (new_form_lines.empty()) { @@ -298,7 +302,13 @@ std::vector apply_formatting(const FormatterTreeNode& curr_node, new_form_lines.at(0) += fmt::format(" {}", form_lines.at(i)); } } else { - new_form_lines.push_back(form_lines.at(i)); + if (str_util::starts_with(form_lines.at(i), " ") && consolidating_lines) { + new_form_lines.push_back(fmt::format( + "{}{}", str_util::repeat(original_form_head_width, " "), form_lines.at(i))); + } else { + consolidating_lines = false; + new_form_lines.push_back(form_lines.at(i)); + } } } form_lines = new_form_lines; diff --git a/test/common/formatter/corpus/conditions.test.gc b/test/common/formatter/corpus/conditions.test.gc index a29617a5ad..31c462aaaa 100644 --- a/test/common/formatter/corpus/conditions.test.gc +++ b/test/common/formatter/corpus/conditions.test.gc @@ -25,3 +25,20 @@ Non-Inlinable If (if arg1 (symbol->string (-> arg0 type symbol) (-> arg0 type symbol) (-> arg0 type symbol) (-> arg0 type symbol)) (symbol->string (-> arg0 type symbol) (-> arg0 type symbol) (-> arg0 type symbol) (-> arg0 type symbol))) + +=== +Multiline condition hang +=== + +(when (and (-> this ignore-menu-toggle?) + (or (not (cpad-hold? 0 l1)) (not (cpad-hold? 0 r1))) + (or (and (-> this opened-with-start?) (not (cpad-hold? 0 start)) (not (cpad-hold? 0 start))) (and (not (-> this opened-with-start?)) (not (cpad-hold? 0 select))))) + (set! (-> this ignore-menu-toggle?) #f)) + +--- + +(when (and (-> this ignore-menu-toggle?) + (or (not (cpad-hold? 0 l1)) (not (cpad-hold? 0 r1))) + (or (and (-> this opened-with-start?) (not (cpad-hold? 0 start)) (not (cpad-hold? 0 start))) + (and (not (-> this opened-with-start?)) (not (cpad-hold? 0 select))))) + (set! (-> this ignore-menu-toggle?) #f))