diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 1165fcb..47ae31f 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -612,22 +612,7 @@ private: immutable bool arrayInitializerStart = p == tok!"[" && astInformation.arrayStartLocations.canFindIndex(tokens[index - 1].index); - if (p == tok!"[" && config.dfmt_keep_line_breaks == OptionalBoolean.t) - { - IndentStack.Details detail; - - detail.wrap = false; - detail.temp = false; - detail.breakEveryItem = false; - detail.mini = tokens[index].line == tokens[index - 1].line; - - indents.push(tok!"]", detail); - if (!detail.mini) - { - newline(); - } - } - else if (arrayInitializerStart && isMultilineAt(index - 1)) + if (arrayInitializerStart && isMultilineAt(index - 1)) { if (peekBack2Is(tok!"(")) { indents.pop(); @@ -653,6 +638,21 @@ private: linebreakHints = chooseLineBreakTokens(index, tokens[index .. j], depths[index .. j], config, currentLineLength, indentLevel); } + else if (p == tok!"[" && config.dfmt_keep_line_breaks == OptionalBoolean.t) + { + IndentStack.Details detail; + + detail.wrap = false; + detail.temp = false; + detail.breakEveryItem = false; + detail.mini = tokens[index].line == tokens[index - 1].line; + + indents.push(tok!"]", detail); + if (!detail.mini) + { + newline(); + } + } else if (arrayInitializerStart) { // This is a short (non-breaking) array/AA value diff --git a/tests/allman/keep_break_in_array_chain.d.ref b/tests/allman/keep_break_in_array_chain.d.ref new file mode 100644 index 0000000..b6c691a --- /dev/null +++ b/tests/allman/keep_break_in_array_chain.d.ref @@ -0,0 +1,7 @@ +unittest +{ + functionLengthDoesMatter([ + firstFunctionInChain("A").seconFunctionInChain("B").value, + firstFunctionInChain("A").seconFunctionInChain("B").value + ]); +} diff --git a/tests/keep_break_in_array_chain.d b/tests/keep_break_in_array_chain.d new file mode 100644 index 0000000..03771ef --- /dev/null +++ b/tests/keep_break_in_array_chain.d @@ -0,0 +1,7 @@ +unittest +{ + functionLengthDoesMatter([ + firstFunctionInChain("A").seconFunctionInChain("B").value, + firstFunctionInChain("A").seconFunctionInChain("B").value + ]); +} diff --git a/tests/keep_break_in_array_chain.d.args b/tests/keep_break_in_array_chain.d.args new file mode 100644 index 0000000..7e7e52d --- /dev/null +++ b/tests/keep_break_in_array_chain.d.args @@ -0,0 +1 @@ +--keep_line_breaks=true diff --git a/tests/otbs/keep_break_in_array_chain.d.ref b/tests/otbs/keep_break_in_array_chain.d.ref new file mode 100644 index 0000000..b8cf577 --- /dev/null +++ b/tests/otbs/keep_break_in_array_chain.d.ref @@ -0,0 +1,6 @@ +unittest { + functionLengthDoesMatter([ + firstFunctionInChain("A").seconFunctionInChain("B").value, + firstFunctionInChain("A").seconFunctionInChain("B").value + ]); +}