diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 3f6d1c7..18f958c 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -1515,7 +1515,7 @@ private: void newline() { import std.range : assumeSorted; - import std.algorithm : max; + import std.algorithm : max, canFind; import dfmt.editorconfig : OptionalBoolean; if (currentIs(tok!"comment") && index > 0 && current.line == tokenEndLine(tokens[index - 1])) @@ -1558,6 +1558,12 @@ private: immutable l = indents.indentToMostRecent(tok!"switch"); if (l != -1 && config.dfmt_align_switch_statements == OptionalBoolean.t) indentLevel = l; + else if (astInformation.structInfoSortedByEndLocation + .canFind!(st => st.startLocation < current.index && current.index < st.endLocation)) { + immutable l2 = indents.indentToMostRecent(tok!"{"); + assert(l2 != -1); + indentLevel = l2 + 1; + } else if (config.dfmt_compact_labeled_statements == OptionalBoolean.f || !isBlockHeader(2) || peek2Is(tok!"if")) { diff --git a/tests/allman/issue0256.d.ref b/tests/allman/issue0256.d.ref index 0a18239..e7463d5 100644 --- a/tests/allman/issue0256.d.ref +++ b/tests/allman/issue0256.d.ref @@ -1,6 +1,8 @@ -void foo() +void main() { - S s1 = {a: 3}; - S s2 = {a: 3, b: "test string"}; - S s3 = {a: 3, b: "test string", c: {x: 3.14, y: 3 + 4}}; + S s = { + someStructMember1: 2, someStructMember2: 42, someStructMember3: null, // foobar + someOtherMember1: objA, someOtherMember2: objB, someOtherMember3: 0, + somethingMore: null, someFlagInThisStruct: -1 + }; } diff --git a/tests/issue0256.d b/tests/issue0256.d index 11dccdf..f4d44dc 100644 --- a/tests/issue0256.d +++ b/tests/issue0256.d @@ -1,6 +1,12 @@ -void foo() -{ - S s1 = { a: 3 }; - S s2 = { a: 3, b:"test string" }; - S s3 = { a: 3, b:"test string", c: {x: 3.14, y: 3 + 4} }; +void main() { + S s = { + someStructMember1: 2, + someStructMember2: 42, + someStructMember3: null, // foobar + someOtherMember1: objA, + someOtherMember2: objB, + someOtherMember3: 0, + somethingMore: null, + someFlagInThisStruct: -1 + }; } diff --git a/tests/otbs/issue0256.d.ref b/tests/otbs/issue0256.d.ref index 576e0bd..2d0098f 100644 --- a/tests/otbs/issue0256.d.ref +++ b/tests/otbs/issue0256.d.ref @@ -1,5 +1,7 @@ -void foo() { - S s1 = {a: 3}; - S s2 = {a: 3, b: "test string"}; - S s3 = {a: 3, b: "test string", c: {x: 3.14, y: 3 + 4}}; +void main() { + S s = { + someStructMember1: 2, someStructMember2: 42, someStructMember3: null, // foobar + someOtherMember1: objA, someOtherMember2: objB, someOtherMember3: 0, + somethingMore: null, someFlagInThisStruct: -1 + }; }