fix #236 - Allow constraints to be indented by a single tab merged-on-behalf-of: BBasile <BBasile@users.noreply.github.com>
This commit is contained in:
parent
95905cdbf1
commit
b01c624ef0
|
|
@ -4,9 +4,6 @@ set -e
|
||||||
|
|
||||||
if [[ $BUILD == dub ]]; then
|
if [[ $BUILD == dub ]]; then
|
||||||
dub build --build=release
|
dub build --build=release
|
||||||
|
|
||||||
mkdir bin
|
|
||||||
mv dfmt ./bin
|
|
||||||
elif [[ $DC == ldc2 ]]; then
|
elif [[ $DC == ldc2 ]]; then
|
||||||
git submodule update --init --recursive
|
git submodule update --init --recursive
|
||||||
make ldc -j2
|
make ldc -j2
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ found in .editorconfig files.
|
||||||
* **--max_line_length**: See **max_line_length** below
|
* **--max_line_length**: See **max_line_length** below
|
||||||
* **--soft_max_line_length**: See **dfmt_soft_max_line_length** below
|
* **--soft_max_line_length**: See **dfmt_soft_max_line_length** below
|
||||||
* **--outdent_attributes**: See **dfmt_outdent_attributes** below
|
* **--outdent_attributes**: See **dfmt_outdent_attributes** below
|
||||||
|
* **--single_template_constraint_indent**: See **dfmt_template_constraint_style** below
|
||||||
* **--space_after_cast**: See **dfmt_space_after_cast** below
|
* **--space_after_cast**: See **dfmt_space_after_cast** below
|
||||||
* **--space_before_function_parameters**: See **dfmt_space_before_function_parameters** below
|
* **--space_before_function_parameters**: See **dfmt_space_before_function_parameters** below
|
||||||
* **--split_operator_at_line_end**: See **dfmt_split_operator_at_line_end** below
|
* **--split_operator_at_line_end**: See **dfmt_split_operator_at_line_end** below
|
||||||
|
|
@ -105,6 +106,7 @@ dfmt_space_before_function_parameters | `true`, `false` | `false` | Insert space
|
||||||
dfmt_selective_import_space | `true`, `false` | `true` | Insert space after the module name and before the `:` for selective imports.
|
dfmt_selective_import_space | `true`, `false` | `true` | Insert space after the module name and before the `:` for selective imports.
|
||||||
dfmt_compact_labeled_statements | `true`, `false` | `true` | Place labels on the same line as the labeled `switch`, `for`, `foreach`, or `while` statement.
|
dfmt_compact_labeled_statements | `true`, `false` | `true` | Place labels on the same line as the labeled `switch`, `for`, `foreach`, or `while` statement.
|
||||||
dfmt_template_constraint_style | `conditional_newline_indent` `conditional_newline` `always_newline` `always_newline_indent` | `conditional_newline_indent` | Control the formatting of template constraints.
|
dfmt_template_constraint_style | `conditional_newline_indent` `conditional_newline` `always_newline` `always_newline_indent` | `conditional_newline_indent` | Control the formatting of template constraints.
|
||||||
|
dfmt_single_template_constraint_indent | `true`, `false` | `false` | Set if the constraints are indented by a single tab instead of two. Has only an effect for if indentation style if set to `always_newline_indent` or `conditional_newline_indent`.
|
||||||
|
|
||||||
## Terminology
|
## Terminology
|
||||||
* Braces - `{` and `}`
|
* Braces - `{` and `}`
|
||||||
|
|
|
||||||
4
dub.json
4
dub.json
|
|
@ -5,5 +5,7 @@
|
||||||
"license": "BSL-1.0",
|
"license": "BSL-1.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"libdparse": "~>0.8.0-alpha.5"
|
"libdparse": "~>0.8.0-alpha.5"
|
||||||
}
|
},
|
||||||
|
"targetPath" : "bin/",
|
||||||
|
"targetName" : "dfmt",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit ee0fa01ab74b6bf27bed3c7bdb9d6fb789963342
|
Subproject commit 687c0ca751747ebe498c183da1a3ee3119d57932
|
||||||
|
|
@ -53,6 +53,8 @@ struct Config
|
||||||
OptionalBoolean dfmt_compact_labeled_statements;
|
OptionalBoolean dfmt_compact_labeled_statements;
|
||||||
///
|
///
|
||||||
TemplateConstraintStyle dfmt_template_constraint_style;
|
TemplateConstraintStyle dfmt_template_constraint_style;
|
||||||
|
///
|
||||||
|
OptionalBoolean dfmt_single_template_constraint_indent;
|
||||||
|
|
||||||
mixin StandardEditorConfigFields;
|
mixin StandardEditorConfigFields;
|
||||||
|
|
||||||
|
|
@ -79,6 +81,7 @@ struct Config
|
||||||
dfmt_selective_import_space = OptionalBoolean.t;
|
dfmt_selective_import_space = OptionalBoolean.t;
|
||||||
dfmt_compact_labeled_statements = OptionalBoolean.t;
|
dfmt_compact_labeled_statements = OptionalBoolean.t;
|
||||||
dfmt_template_constraint_style = TemplateConstraintStyle.conditional_newline_indent;
|
dfmt_template_constraint_style = TemplateConstraintStyle.conditional_newline_indent;
|
||||||
|
dfmt_single_template_constraint_indent = OptionalBoolean.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -324,6 +324,7 @@ private:
|
||||||
|
|
||||||
void formatConstraint()
|
void formatConstraint()
|
||||||
{
|
{
|
||||||
|
import dfmt.editorconfig : OB = OptionalBoolean;
|
||||||
with (TemplateConstraintStyle) final switch (config.dfmt_template_constraint_style)
|
with (TemplateConstraintStyle) final switch (config.dfmt_template_constraint_style)
|
||||||
{
|
{
|
||||||
case unspecified:
|
case unspecified:
|
||||||
|
|
@ -342,15 +343,19 @@ private:
|
||||||
immutable l = currentLineLength + betweenParenLength(tokens[index + 1 .. $]);
|
immutable l = currentLineLength + betweenParenLength(tokens[index + 1 .. $]);
|
||||||
if (l > config.dfmt_soft_max_line_length)
|
if (l > config.dfmt_soft_max_line_length)
|
||||||
{
|
{
|
||||||
pushWrapIndent(tok!"!");
|
config.dfmt_single_template_constraint_indent == OB.t ?
|
||||||
|
pushWrapIndent() : pushWrapIndent(tok!"!");
|
||||||
newline();
|
newline();
|
||||||
}
|
}
|
||||||
else if (peekBackIs(tok!")"))
|
else if (peekBackIs(tok!")"))
|
||||||
write(" ");
|
write(" ");
|
||||||
break;
|
break;
|
||||||
case always_newline_indent:
|
case always_newline_indent:
|
||||||
pushWrapIndent(tok!"!");
|
{
|
||||||
newline();
|
config.dfmt_single_template_constraint_indent == OB.t ?
|
||||||
|
pushWrapIndent() : pushWrapIndent(tok!"!");
|
||||||
|
newline();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// if
|
// if
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,9 @@ else
|
||||||
case "compact_labeled_statements":
|
case "compact_labeled_statements":
|
||||||
optConfig.dfmt_compact_labeled_statements = optVal;
|
optConfig.dfmt_compact_labeled_statements = optVal;
|
||||||
break;
|
break;
|
||||||
|
case "single_template_constraint_indent":
|
||||||
|
optConfig.dfmt_single_template_constraint_indent = optVal;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false, "Invalid command-line switch");
|
assert(false, "Invalid command-line switch");
|
||||||
}
|
}
|
||||||
|
|
@ -139,6 +142,7 @@ else
|
||||||
"space_before_function_parameters", &handleBooleans,
|
"space_before_function_parameters", &handleBooleans,
|
||||||
"split_operator_at_line_end", &handleBooleans,
|
"split_operator_at_line_end", &handleBooleans,
|
||||||
"compact_labeled_statements", &handleBooleans,
|
"compact_labeled_statements", &handleBooleans,
|
||||||
|
"single_template_constraint_indent", &handleBooleans,
|
||||||
"tab_width", &optConfig.tab_width,
|
"tab_width", &optConfig.tab_width,
|
||||||
"template_constraint_style", &optConfig.dfmt_template_constraint_style);
|
"template_constraint_style", &optConfig.dfmt_template_constraint_style);
|
||||||
// dfmt on
|
// dfmt on
|
||||||
|
|
@ -329,6 +333,7 @@ Formatting Options:
|
||||||
--space_after_cast
|
--space_after_cast
|
||||||
--space_before_function_parameters
|
--space_before_function_parameters
|
||||||
--selective_import_space
|
--selective_import_space
|
||||||
|
--single_template_constraint_indent
|
||||||
--split_operator_at_line_end
|
--split_operator_at_line_end
|
||||||
--compact_labeled_statements
|
--compact_labeled_statements
|
||||||
--template_constraint_style
|
--template_constraint_style
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
void foo()()
|
||||||
|
if (dogs && pigs && birds && ants && foxes && flies && cats && bugs && bees
|
||||||
|
&& cows && sheeps && monkeys && whales)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void foo()() if (dogs && pigs && birds)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
void foo()()
|
||||||
|
if (dogs && pigs && birds && ants && foxes && flies && cats && bugs && bees
|
||||||
|
&& cows && sheeps && monkeys && whales)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void foo()()
|
||||||
|
if (dogs && pigs && birds)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
--template_constraint_style=conditional_newline_indent
|
||||||
|
--single_template_constraint_indent=true
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
void foo()() if (dogs && pigs && birds && ants && foxes && flies && cats && bugs && bees && cows && sheeps && monkeys && whales)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void foo()() if (dogs && pigs && birds) {}
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
--template_constraint_style=always_newline_indent
|
||||||
|
--single_template_constraint_indent=true
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
void foo()() if (dogs && pigs && birds && ants && foxes && flies && cats && bugs && bees && cows && sheeps && monkeys && whales)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void foo()() if (dogs && pigs && birds) {}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
void foo()()
|
||||||
|
if (dogs && pigs && birds && ants && foxes && flies && cats && bugs && bees
|
||||||
|
&& cows && sheeps && monkeys && whales) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void foo()() if (dogs && pigs && birds) {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
void foo()()
|
||||||
|
if (dogs && pigs && birds && ants && foxes && flies && cats && bugs && bees
|
||||||
|
&& cows && sheeps && monkeys && whales) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void foo()()
|
||||||
|
if (dogs && pigs && birds) {
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue