From 7f41c8ae7f5babdac4ce7869d6f04c67701a0fcd Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Sat, 12 Jan 2019 12:25:46 +0100 Subject: [PATCH] fix array item access regression --- src/dfmt/formatter.d | 13 ++++++++++++- tests/allman/array_access.d.ref | 7 +++++++ tests/array_access.d | 4 ++++ tests/otbs/array_access.d.ref | 6 ++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/allman/array_access.d.ref create mode 100644 tests/array_access.d create mode 100644 tests/otbs/array_access.d.ref diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 7b5f6a5..1a13a45 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -611,6 +611,15 @@ private: indents.push(tok!"]", detail); } + else if (p == tok!"[") + { + // array item access + IndentStack.Details detail; + detail.wrap = false; + detail.temp = true; + detail.mini = true; + indents.push(tok!"]", detail); + } else if (!currentIs(tok!")") && !currentIs(tok!"]") && (linebreakHints.canFindIndex(index - 1) || (linebreakHints.length == 0 && currentLineLength > config.max_line_length))) @@ -664,7 +673,7 @@ private: indents.popWrapIndents(); if (indents.topIs(tok!"]")) { - if (!indents.topDetails.mini) + if (!indents.topDetails.mini && !indents.topDetails.temp) newline(); else indents.pop(); @@ -839,6 +848,8 @@ private: } else if (astInformation.funLitStartLocations.canFindIndex(tIndex)) { + indents.popWrapIndents(); + sBraceDepth++; if (peekBackIsOneOf(true, tok!")", tok!"identifier")) write(" "); diff --git a/tests/allman/array_access.d.ref b/tests/allman/array_access.d.ref new file mode 100644 index 0000000..7c7a6cc --- /dev/null +++ b/tests/allman/array_access.d.ref @@ -0,0 +1,7 @@ +unittest +{ + foo([ + target.value.region[1], target.value.region[1], + target.value.region[1], target.value.region[1], target.value.region[1] + ]); +} diff --git a/tests/array_access.d b/tests/array_access.d new file mode 100644 index 0000000..9a96e57 --- /dev/null +++ b/tests/array_access.d @@ -0,0 +1,4 @@ +unittest +{ + foo([target.value.region[1], target.value.region[1], target.value.region[1], target.value.region[1], target.value.region[1]]); +} \ No newline at end of file diff --git a/tests/otbs/array_access.d.ref b/tests/otbs/array_access.d.ref new file mode 100644 index 0000000..7a2ac55 --- /dev/null +++ b/tests/otbs/array_access.d.ref @@ -0,0 +1,6 @@ +unittest { + foo([ + target.value.region[1], target.value.region[1], + target.value.region[1], target.value.region[1], target.value.region[1] + ]); +}