From d3942b3a7739125c194b5114762b9fae40dbb6b8 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 15 Jan 2023 19:47:57 +0100 Subject: [PATCH] Revert chain indentation in an argument list --- src/dfmt/formatter.d | 8 ++++++ tests/allman/argument_chain_indent.d.ref | 13 +++++++++ tests/allman/argument_chain_keep_breaks.d.ref | 15 ++++++++++ tests/argument_chain_indent.args | 1 + tests/argument_chain_indent.d | 28 +++++++++++++++++++ tests/argument_chain_keep_breaks.args | 2 ++ tests/argument_chain_keep_breaks.d | 15 ++++++++++ tests/knr/argument_chain_indent.d.ref | 11 ++++++++ tests/knr/argument_chain_keep_breaks.d.ref | 13 +++++++++ tests/otbs/argument_chain_indent.d.ref | 10 +++++++ tests/otbs/argument_chain_keep_breaks.d.ref | 12 ++++++++ 11 files changed, 128 insertions(+) create mode 100644 tests/allman/argument_chain_indent.d.ref create mode 100644 tests/allman/argument_chain_keep_breaks.d.ref create mode 100644 tests/argument_chain_indent.args create mode 100644 tests/argument_chain_indent.d create mode 100644 tests/argument_chain_keep_breaks.args create mode 100644 tests/argument_chain_keep_breaks.d create mode 100644 tests/knr/argument_chain_indent.d.ref create mode 100644 tests/knr/argument_chain_keep_breaks.d.ref create mode 100644 tests/otbs/argument_chain_indent.d.ref create mode 100644 tests/otbs/argument_chain_keep_breaks.d.ref diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 67d6cf0..c123f0e 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -1625,6 +1625,10 @@ private: const commaLine = tokens[index].line; writeToken(); + if (indents.topIs(tok!".")) + { + indents.pop; + } if (!currentIs(tok!")") && !currentIs(tok!"]") && !currentIs(tok!"}") && !currentIs(tok!"comment")) { @@ -1643,6 +1647,10 @@ private: { pushWrapIndent(); writeToken(); + if (indents.topIs(tok!".")) + { + indents.pop; + } newline(); } else diff --git a/tests/allman/argument_chain_indent.d.ref b/tests/allman/argument_chain_indent.d.ref new file mode 100644 index 0000000..80ccb2f --- /dev/null +++ b/tests/allman/argument_chain_indent.d.ref @@ -0,0 +1,13 @@ +class C +{ + void f() + { + if (true) + { + f(map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map + .map.map.map.map.map.map, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __LINE__); + } + } +} diff --git a/tests/allman/argument_chain_keep_breaks.d.ref b/tests/allman/argument_chain_keep_breaks.d.ref new file mode 100644 index 0000000..8c6dd16 --- /dev/null +++ b/tests/allman/argument_chain_keep_breaks.d.ref @@ -0,0 +1,15 @@ +class C +{ + void f() + { + if (true) + { + f( + array.map!(a => a.prop) + .array + .to!string, + __FILE__, + __LINE__); + } + } +} diff --git a/tests/argument_chain_indent.args b/tests/argument_chain_indent.args new file mode 100644 index 0000000..7bdbaad --- /dev/null +++ b/tests/argument_chain_indent.args @@ -0,0 +1 @@ +--single_indent=true diff --git a/tests/argument_chain_indent.d b/tests/argument_chain_indent.d new file mode 100644 index 0000000..6fc0f4a --- /dev/null +++ b/tests/argument_chain_indent.d @@ -0,0 +1,28 @@ +class C +{ + void f() + { + if (true) + { + f( + map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __LINE__); + } + } +} diff --git a/tests/argument_chain_keep_breaks.args b/tests/argument_chain_keep_breaks.args new file mode 100644 index 0000000..3cc65f7 --- /dev/null +++ b/tests/argument_chain_keep_breaks.args @@ -0,0 +1,2 @@ +--single_indent=true +--keep_line_breaks=true diff --git a/tests/argument_chain_keep_breaks.d b/tests/argument_chain_keep_breaks.d new file mode 100644 index 0000000..8c6dd16 --- /dev/null +++ b/tests/argument_chain_keep_breaks.d @@ -0,0 +1,15 @@ +class C +{ + void f() + { + if (true) + { + f( + array.map!(a => a.prop) + .array + .to!string, + __FILE__, + __LINE__); + } + } +} diff --git a/tests/knr/argument_chain_indent.d.ref b/tests/knr/argument_chain_indent.d.ref new file mode 100644 index 0000000..5c6b87c --- /dev/null +++ b/tests/knr/argument_chain_indent.d.ref @@ -0,0 +1,11 @@ +class C { + void f() + { + if (true) { + f(map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map + .map.map.map.map.map.map, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __LINE__); + } + } +} diff --git a/tests/knr/argument_chain_keep_breaks.d.ref b/tests/knr/argument_chain_keep_breaks.d.ref new file mode 100644 index 0000000..2d80d31 --- /dev/null +++ b/tests/knr/argument_chain_keep_breaks.d.ref @@ -0,0 +1,13 @@ +class C { + void f() + { + if (true) { + f( + array.map!(a => a.prop) + .array + .to!string, + __FILE__, + __LINE__); + } + } +} diff --git a/tests/otbs/argument_chain_indent.d.ref b/tests/otbs/argument_chain_indent.d.ref new file mode 100644 index 0000000..47166fa --- /dev/null +++ b/tests/otbs/argument_chain_indent.d.ref @@ -0,0 +1,10 @@ +class C { + void f() { + if (true) { + f(map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map + .map.map.map.map.map.map, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __LINE__); + } + } +} diff --git a/tests/otbs/argument_chain_keep_breaks.d.ref b/tests/otbs/argument_chain_keep_breaks.d.ref new file mode 100644 index 0000000..7a561d0 --- /dev/null +++ b/tests/otbs/argument_chain_keep_breaks.d.ref @@ -0,0 +1,12 @@ +class C { + void f() { + if (true) { + f( + array.map!(a => a.prop) + .array + .to!string, + __FILE__, + __LINE__); + } + } +}