Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert chain indentation in an argument list #574

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/dfmt/formatter.d
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
{
Expand All @@ -1643,6 +1647,10 @@ private:
{
pushWrapIndent();
writeToken();
if (indents.topIs(tok!"."))
{
indents.pop;
}
newline();
}
else
Expand Down
13 changes: 13 additions & 0 deletions tests/allman/argument_chain_indent.d.ref
Original file line number Diff line number Diff line change
@@ -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__);
}
}
}
15 changes: 15 additions & 0 deletions tests/allman/argument_chain_keep_breaks.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class C
{
void f()
{
if (true)
{
f(
array.map!(a => a.prop)
.array
.to!string,
__FILE__,
__LINE__);
}
}
}
1 change: 1 addition & 0 deletions tests/argument_chain_indent.args
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--single_indent=true
28 changes: 28 additions & 0 deletions tests/argument_chain_indent.d
Original file line number Diff line number Diff line change
@@ -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__);
}
}
}
2 changes: 2 additions & 0 deletions tests/argument_chain_keep_breaks.args
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--single_indent=true
--keep_line_breaks=true
15 changes: 15 additions & 0 deletions tests/argument_chain_keep_breaks.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class C
{
void f()
{
if (true)
{
f(
array.map!(a => a.prop)
.array
.to!string,
__FILE__,
__LINE__);
}
}
}
11 changes: 11 additions & 0 deletions tests/knr/argument_chain_indent.d.ref
Original file line number Diff line number Diff line change
@@ -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__);
}
}
}
13 changes: 13 additions & 0 deletions tests/knr/argument_chain_keep_breaks.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class C {
void f()
{
if (true) {
f(
array.map!(a => a.prop)
.array
.to!string,
__FILE__,
__LINE__);
}
}
}
10 changes: 10 additions & 0 deletions tests/otbs/argument_chain_indent.d.ref
Original file line number Diff line number Diff line change
@@ -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__,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't there be a new line after the .map,? Or at least wrap after the 3rd __FILE__ and not after the 5th (because the other lines below also wrap around that column)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it is how line breaks are currently added. It was the main reason we wanted to have --keep-line-breaks, so such things can be adjusted manually because in the complicated code it is difficult to calculate the right way to add line breaks (if there is the right way).

__FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__,
__FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __LINE__);
}
}
}
12 changes: 12 additions & 0 deletions tests/otbs/argument_chain_keep_breaks.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class C {
void f() {
if (true) {
f(
array.map!(a => a.prop)
.array
.to!string,
__FILE__,
__LINE__);
}
}
}