Skip to content

Commit

Permalink
Very long chained calls in array literals are indented weirdly
Browse files Browse the repository at this point in the history
  • Loading branch information
belka-ew authored and WebFreak001 committed Jul 28, 2022
1 parent 4947bee commit 026a58e
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/dfmt/formatter.d
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,8 @@ private:
indents.pop();
if (indents.topIs(tok!"("))
indents.pop();
if (indents.topIs(tok!"."))
indents.pop();

if (onNextLine)
{
Expand Down Expand Up @@ -1440,7 +1442,8 @@ private:
if (ufcsWrap || linebreakHints.canFind(index) || onNextLine
|| (linebreakHints.length == 0 && currentLineLength + nextTokenLength() > config.max_line_length))
{
pushWrapIndent();
if (!indents.topIs(tok!"."))
indents.push(tok!".");
if (!peekBackIs(tok!"comment"))
newline();
if (ufcsWrap || onNextLine)
Expand Down
29 changes: 29 additions & 0 deletions tests/allman/issue0494.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
void main()
{
const a1 = [
builder.rebuild!((x, y, z) => x + y + z)
.rebuild!(x => x)
.rebuild!(x => x),
];

const a2 = [
builder.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
builder.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
];

foo([
line1,
value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c).value,
]);
}

void foo()
{
afdsafds.asdf.flub;
}
34 changes: 34 additions & 0 deletions tests/allman/issue0494_keep_line_break.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
void main()
{
const a1 = [
builder
.rebuild!((x, y, z) => x + y + z)
.rebuild!(x => x)
.rebuild!(x => x),
];

const a2 = [
builder
.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
builder
.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
];

foo([
line1,
value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c).value,
]);
}

void foo()
{
afdsafds
.asdf
.flub;
}
33 changes: 33 additions & 0 deletions tests/issue0494.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
void main()
{
const a1 = [
builder
.rebuild!((x, y, z) => x + y + z)
.rebuild!(x => x)
.rebuild!(x => x),
];

const a2 = [
builder
.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
builder
.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
];

foo([
line1,
value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c).value,
]);
}

void foo() {
afdsafds
.asdf
.flub;
}
1 change: 1 addition & 0 deletions tests/issue0494_keep_line_break.args
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--keep_line_breaks=true
33 changes: 33 additions & 0 deletions tests/issue0494_keep_line_break.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
void main()
{
const a1 = [
builder
.rebuild!((x, y, z) => x + y + z)
.rebuild!(x => x)
.rebuild!(x => x),
];

const a2 = [
builder
.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
builder
.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
];

foo([
line1,
value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c).value,
]);
}

void foo() {
afdsafds
.asdf
.flub;
}
29 changes: 29 additions & 0 deletions tests/knr/issue0494.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
void main()
{
const a1 = [
builder.rebuild!((x, y, z) => x + y + z)
.rebuild!(x => x)
.rebuild!(x => x),
];

const a2 = [
builder.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
builder.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
];

foo([
line1,
value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c).value,
]);
}

void foo()
{
afdsafds.asdf.flub;
}
34 changes: 34 additions & 0 deletions tests/knr/issue0494_keep_line_break.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
void main()
{
const a1 = [
builder
.rebuild!((x, y, z) => x + y + z)
.rebuild!(x => x)
.rebuild!(x => x),
];

const a2 = [
builder
.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
builder
.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
];

foo([
line1,
value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c).value,
]);
}

void foo()
{
afdsafds
.asdf
.flub;
}
27 changes: 27 additions & 0 deletions tests/otbs/issue0494.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
void main() {
const a1 = [
builder.rebuild!((x, y, z) => x + y + z)
.rebuild!(x => x)
.rebuild!(x => x),
];

const a2 = [
builder.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
builder.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
];

foo([
line1,
value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c).value,
]);
}

void foo() {
afdsafds.asdf.flub;
}
32 changes: 32 additions & 0 deletions tests/otbs/issue0494_keep_line_break.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
void main() {
const a1 = [
builder
.rebuild!((x, y, z) => x + y + z)
.rebuild!(x => x)
.rebuild!(x => x),
];

const a2 = [
builder
.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
builder
.rebuild!(x => x)
.rebuild!(x => x)
.rebuild!(x => x),
];

foo([
line1,
value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c)
.propertyCallBlaBlaBla(a, b, c).value,
]);
}

void foo() {
afdsafds
.asdf
.flub;
}

0 comments on commit 026a58e

Please sign in to comment.