From 8d42254d47b3006b8e07f396b06575b5e2b06641 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sat, 6 Aug 2022 00:21:53 +0200 Subject: [PATCH] Fix indentation of callchains with comments Weird formatting and indentation of multiline callchains with comments in the middle. --- src/dfmt/formatter.d | 3 +++ tests/allman/comments.d.ref | 2 +- tests/knr/comments.d.ref | 2 +- tests/otbs/comments.d.ref | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 63ec50ff..ab258c6e 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -499,6 +499,9 @@ private: if (peekIs(tok!"(") && (peekBackIs(tok!")") || peekBack2Is(tok!"!"))) pushWrapIndent(tok!"("); + + if (peekIs(tok!".") && !indents.topIs(tok!".")) + indents.push(tok!"."); } writeToken(); immutable j = justAddedExtraNewline; diff --git a/tests/allman/comments.d.ref b/tests/allman/comments.d.ref index 7139949e..2e9d54d3 100644 --- a/tests/allman/comments.d.ref +++ b/tests/allman/comments.d.ref @@ -2,6 +2,6 @@ int /*sneaky*/ foo( /*comments*/ ) /*everywhere*/ { // comment on its own line foo() // comment on same line - .bar(); // also on same line + .bar(); // also on same line /* again */ // same line } diff --git a/tests/knr/comments.d.ref b/tests/knr/comments.d.ref index 7139949e..2e9d54d3 100644 --- a/tests/knr/comments.d.ref +++ b/tests/knr/comments.d.ref @@ -2,6 +2,6 @@ int /*sneaky*/ foo( /*comments*/ ) /*everywhere*/ { // comment on its own line foo() // comment on same line - .bar(); // also on same line + .bar(); // also on same line /* again */ // same line } diff --git a/tests/otbs/comments.d.ref b/tests/otbs/comments.d.ref index c809b085..80f5313f 100644 --- a/tests/otbs/comments.d.ref +++ b/tests/otbs/comments.d.ref @@ -1,6 +1,6 @@ int /*sneaky*/ foo( /*comments*/ ) /*everywhere*/ { // comment on its own line foo() // comment on same line - .bar(); // also on same line + .bar(); // also on same line /* again */ // same line }