formatter: fix multi-line form consolidation (#3336)

pull/3338/head
Tyler Wilding 2024-01-25 16:46:15 -05:00 committed by GitHub
parent 0ea718a5ee
commit 0236e36a53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View File

@ -288,8 +288,12 @@ std::vector<std::string> 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<std::string> 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<std::string> 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;

View File

@ -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))