From db2ad1354bdec5ef85fe603eb79ac85981ed750f Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Wed, 20 Jan 2016 17:00:46 -0800 Subject: [PATCH] Fix #221 --- src/dfmt/formatter.d | 10 +++++----- tests/allman/issue0221.d.ref | 5 +++++ tests/issue0221.d | 6 ++++++ tests/otbs/issue0221.d.ref | 4 ++++ 4 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 tests/allman/issue0221.d.ref create mode 100644 tests/issue0221.d create mode 100644 tests/otbs/issue0221.d.ref diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index a20cdc7..cf8d9ab 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -209,8 +209,7 @@ private: else if ((isBlockHeader() || currentIs(tok!"version") || currentIs(tok!"debug")) && peekIs(tok!"(", false)) { - if (!assumeSorted(astInformation.constraintLocations) - .equalRange(current.index).empty) + if (!assumeSorted(astInformation.constraintLocations).equalRange(current.index).empty) formatConstrtaint(); else formatBlockHeader(); @@ -365,7 +364,9 @@ private: immutable canAddNewline = currTokenLine - prevTokenEndLine < 1; if (peekBackIsOperator() && !isSeparationToken(t)) pushWrapIndent(t); - if (prevTokenEndLine == currTokenLine || (t == tok!")" && peekIs(tok!"{"))) + if (peekBackIs(tok!")") && !canAddNewline && prevTokenEndLine < currTokenLine) + write(" "); + else if (prevTokenEndLine == currTokenLine || (t == tok!")" && peekIs(tok!"{"))) write(" "); else if (canAddNewline || (peekIs(tok!"{") && t == tok!"}")) newline(); @@ -1157,8 +1158,7 @@ private: newline(); } else if (!peekIs(tok!"}") && (linebreakHints.canFind(index) - || (linebreakHints.length == 0 - && currentLineLength > config.max_line_length))) + || (linebreakHints.length == 0 && currentLineLength > config.max_line_length))) { pushWrapIndent(); writeToken(); diff --git a/tests/allman/issue0221.d.ref b/tests/allman/issue0221.d.ref new file mode 100644 index 0000000..b34755e --- /dev/null +++ b/tests/allman/issue0221.d.ref @@ -0,0 +1,5 @@ +unittest +{ + static if (stuff) // comment + things(); +} diff --git a/tests/issue0221.d b/tests/issue0221.d new file mode 100644 index 0000000..1bee081 --- /dev/null +++ b/tests/issue0221.d @@ -0,0 +1,6 @@ +unittest +{ + static if (stuff) + // comment + things(); +} diff --git a/tests/otbs/issue0221.d.ref b/tests/otbs/issue0221.d.ref new file mode 100644 index 0000000..a036bb7 --- /dev/null +++ b/tests/otbs/issue0221.d.ref @@ -0,0 +1,4 @@ +unittest { + static if (stuff) // comment + things(); +}