From 727472c365f7ee6634d9d01ccab0db498e551b16 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Mon, 20 Mar 2023 17:59:35 +0100 Subject: [PATCH] Keep "(" indentation with a "]" in the same line --- src/dfmt/formatter.d | 6 ++++++ tests/allman/keep_break_in_array_arg.d.ref | 5 +++++ tests/keep_break_in_array_arg.d | 5 +++++ tests/knr/keep_break_in_array_arg.d.ref | 5 +++++ tests/otbs/keep_break_in_array_arg.d.ref | 4 ++++ 5 files changed, 25 insertions(+) diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 34d5eaf..b65db90 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -720,6 +720,12 @@ private: void revertParenIndentation() { + import std.algorithm.searching : canFind, until; + + if (tokens[index .. $].until!(tok => tok.line != current.line).canFind!(x => x.type == tok!"]")) + { + return; + } if (parenDepthOnLine) { foreach (i; 0 .. parenDepthOnLine) diff --git a/tests/allman/keep_break_in_array_arg.d.ref b/tests/allman/keep_break_in_array_arg.d.ref index 88bc23f..0c3de1c 100644 --- a/tests/allman/keep_break_in_array_arg.d.ref +++ b/tests/allman/keep_break_in_array_arg.d.ref @@ -4,3 +4,8 @@ unittest x ]); } + +void f(T[] x, + const U y) +{ +} diff --git a/tests/keep_break_in_array_arg.d b/tests/keep_break_in_array_arg.d index 88bc23f..aa4cd4c 100644 --- a/tests/keep_break_in_array_arg.d +++ b/tests/keep_break_in_array_arg.d @@ -4,3 +4,8 @@ unittest x ]); } + +void f(T[] x, + const U y) +{ +} diff --git a/tests/knr/keep_break_in_array_arg.d.ref b/tests/knr/keep_break_in_array_arg.d.ref index 5f56bb7..4025544 100644 --- a/tests/knr/keep_break_in_array_arg.d.ref +++ b/tests/knr/keep_break_in_array_arg.d.ref @@ -3,3 +3,8 @@ unittest { x ]); } + +void f(T[] x, + const U y) +{ +} diff --git a/tests/otbs/keep_break_in_array_arg.d.ref b/tests/otbs/keep_break_in_array_arg.d.ref index 5f56bb7..7da40ee 100644 --- a/tests/otbs/keep_break_in_array_arg.d.ref +++ b/tests/otbs/keep_break_in_array_arg.d.ref @@ -3,3 +3,7 @@ unittest { x ]); } + +void f(T[] x, + const U y) { +}