Skip to content

Commit fec7394

Browse files
belka-ewWebFreak001
authored andcommitted
Add reflow_property_chains option
Recalculate the splitting of property chains into multiple lines.
1 parent 840aeee commit fec7394

File tree

9 files changed

+71
-2
lines changed

9 files changed

+71
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ found there.
5656
* `--tab_width`: *see tab_width [below](#standard-editorconfig-properties)*
5757
* `--template_constraint_style`: *see dfmt_template_constraint_style [below](#dfmt-specific-properties)*
5858
* `--keep_line_breaks`: *see dfmt_keep_line_breaks [below](#dfmt-specific-properties)*
59+
* `--single_indent`: *see dfmt_single_indent [below](#dfmt-specific-properties)*
60+
* `--reflow_property_chains`: *see dfmt_property_chains [below](#dfmt-specific-properties)*
5961

6062
### Example
6163
```
@@ -117,6 +119,7 @@ dfmt_single_template_constraint_indent | `true`, **`false`** | Set if the constr
117119
dfmt_space_before_aa_colon | `true`, **`false`** | Adds a space after an associative array key before the `:` like in older dfmt versions.
118120
dfmt_keep_line_breaks | `true`, **`false`** | Keep existing line breaks if these don't violate other formatting rules.
119121
dfmt_single_indent | `true`, **`false`** | Set if the code in parens is indented by a single tab instead of two.
122+
dfmt_reflow_property_chains | **`true`**, `false` | Recalculate the splitting of property chains into multiple lines.
120123

121124
## Terminology
122125
* Braces - `{` and `}`

src/dfmt/config.d

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ struct Config
6363
OptionalBoolean dfmt_keep_line_breaks;
6464
///
6565
OptionalBoolean dfmt_single_indent;
66+
///
67+
OptionalBoolean dfmt_reflow_property_chains;
6668

6769
mixin StandardEditorConfigFields;
6870

@@ -93,6 +95,7 @@ struct Config
9395
dfmt_space_before_aa_colon = OptionalBoolean.f;
9496
dfmt_keep_line_breaks = OptionalBoolean.f;
9597
dfmt_single_indent = OptionalBoolean.f;
98+
dfmt_reflow_property_chains = OptionalBoolean.t;
9699
}
97100

98101
/**

src/dfmt/formatter.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,8 @@ private:
14581458
break;
14591459
case tok!".":
14601460
regenLineBreakHintsIfNecessary(index);
1461-
immutable bool ufcsWrap = astInformation.ufcsHintLocations.canFindIndex(current.index);
1461+
immutable bool ufcsWrap = config.dfmt_reflow_property_chains == OptionalBoolean.t
1462+
&& astInformation.ufcsHintLocations.canFindIndex(current.index);
14621463
if (ufcsWrap || linebreakHints.canFind(index) || onNextLine
14631464
|| (linebreakHints.length == 0 && currentLineLength + nextTokenLength() > config.max_line_length))
14641465
{

src/dfmt/main.d

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ else
9898
case "single_indent":
9999
optConfig.dfmt_single_indent = optVal;
100100
break;
101+
case "reflow_property_chains":
102+
optConfig.dfmt_reflow_property_chains = optVal;
103+
break;
101104
default:
102105
assert(false, "Invalid command-line switch");
103106
}
@@ -129,7 +132,8 @@ else
129132
"tab_width", &optConfig.tab_width,
130133
"template_constraint_style", &optConfig.dfmt_template_constraint_style,
131134
"keep_line_breaks", &handleBooleans,
132-
"single_indent", &handleBooleans);
135+
"single_indent", &handleBooleans,
136+
"reflow_property_chains", &handleBooleans);
133137
// dfmt on
134138
}
135139
catch (GetOptException e)
@@ -341,6 +345,7 @@ Formatting Options:
341345
--template_constraint_style
342346
--space_before_aa_colon
343347
--single_indent
348+
--reflow_property_chains
344349
`,
345350
optionsToString!(typeof(Config.dfmt_template_constraint_style)));
346351
}

tests/allman/issue0503.d.ref

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
string f()
2+
{
3+
return duration.total!"seconds".to!string;
4+
}
5+
6+
string g()
7+
{
8+
return duration.total!"seconds"().to!string;
9+
}
10+
11+
string h()
12+
{
13+
return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string
14+
.to!string.to!string.to!string;
15+
}

tests/issue0503.args

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--reflow_property_chains=false

tests/issue0503.d

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
string f()
2+
{
3+
return duration.total!"seconds".to!string;
4+
}
5+
6+
string g()
7+
{
8+
return duration.total!"seconds"().to!string;
9+
}
10+
11+
string h()
12+
{
13+
return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string.to!string.to!string.to!string;
14+
}

tests/knr/issue0503.d.ref

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
string f()
2+
{
3+
return duration.total!"seconds".to!string;
4+
}
5+
6+
string g()
7+
{
8+
return duration.total!"seconds"().to!string;
9+
}
10+
11+
string h()
12+
{
13+
return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string
14+
.to!string.to!string.to!string;
15+
}

tests/otbs/issue0503.d.ref

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
string f() {
2+
return duration.total!"seconds".to!string;
3+
}
4+
5+
string g() {
6+
return duration.total!"seconds"().to!string;
7+
}
8+
9+
string h() {
10+
return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string
11+
.to!string.to!string.to!string;
12+
}

0 commit comments

Comments
 (0)