This commit is contained in:
Hackerpilot 2015-06-08 03:05:11 -07:00
parent 959405eda5
commit bef02a3b55
8 changed files with 53 additions and 13 deletions

View File

@ -36,7 +36,6 @@ 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
* **--outdent_labels**: See **dfmt_outdent_labels** below
* **--space_after_cast**: See **dfmt_space_after_cast** below * **--space_after_cast**: See **dfmt_space_after_cast** 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
* **--tab_width**: See **tab_width** below * **--tab_width**: See **tab_width** below
@ -90,7 +89,6 @@ Property Name | Allowed Values | Default Value | Description
--------------|----------------|---------------|------------ --------------|----------------|---------------|------------
dfmt_brace_style | `allman`, `otbs`, or `stroustrup` | `allman` | [See Wikipedia](https://en.wikipedia.org/wiki/Brace_style) dfmt_brace_style | `allman`, `otbs`, or `stroustrup` | `allman` | [See Wikipedia](https://en.wikipedia.org/wiki/Brace_style)
dfmt_soft_max_line_length | positive integers | `80` | The formatting process will usually keep lines below this length, but they may be up to max_line_length columns long. dfmt_soft_max_line_length | positive integers | `80` | The formatting process will usually keep lines below this length, but they may be up to max_line_length columns long.
dfmt_outdent_labels (Not yet implemented) | `true`, `false` | `true` | Decrease the indentation of labels
dfmt_align_switch_statements (Not yet implemented) | `true`, `false` | `true` | Align labels, cases, and defaults with their enclosing switch dfmt_align_switch_statements (Not yet implemented) | `true`, `false` | `true` | Align labels, cases, and defaults with their enclosing switch
dfmt_outdent_attributes (Not yet implemented) | `true`, `false` | `true` | Decrease the indentation level of attributes dfmt_outdent_attributes (Not yet implemented) | `true`, `false` | `true` | Decrease the indentation level of attributes
dfmt_split_operator_at_line_end | `true`, `false` | `false` | Place operators on the end of the previous line when splitting lines dfmt_split_operator_at_line_end | `true`, `false` | `false` | Place operators on the end of the previous line when splitting lines

View File

@ -29,8 +29,6 @@ struct Config
/// ///
OptionalBoolean dfmt_outdent_attributes; OptionalBoolean dfmt_outdent_attributes;
/// ///
OptionalBoolean dfmt_outdent_labels;
///
int dfmt_soft_max_line_length = -1; int dfmt_soft_max_line_length = -1;
/// ///
OptionalBoolean dfmt_space_after_cast; OptionalBoolean dfmt_space_after_cast;

View File

@ -475,6 +475,8 @@ private:
{ {
if (isCase && !indents.topIs(tok!"case") && config.dfmt_align_switch_statements == OptionalBoolean.f) if (isCase && !indents.topIs(tok!"case") && config.dfmt_align_switch_statements == OptionalBoolean.f)
indents.push(tok!"case"); indents.push(tok!"case");
else if (isAttribute && !indents.topIs(tok!"@") && config.dfmt_outdent_attributes == OptionalBoolean.f)
indents.push(tok!"@");
newline(); newline();
} }
@ -1120,7 +1122,7 @@ private:
else if (currentIs(tok!"}")) else if (currentIs(tok!"}"))
{ {
indents.popTempIndents(); indents.popTempIndents();
if (indents.topIs(tok!"case")) while (indents.topIs(tok!"case") || indents.topIs(tok!"@"))
indents.pop(); indents.pop();
if (indents.topIs(tok!"{")) if (indents.topIs(tok!"{"))
{ {
@ -1143,6 +1145,8 @@ private:
} }
} }
else if (astInformation.attributeDeclarationLines.canFindIndex(current.line)) else if (astInformation.attributeDeclarationLines.canFindIndex(current.line))
{
if (config.dfmt_outdent_attributes == OptionalBoolean.t)
{ {
immutable l = indents.indentToMostRecent(tok!"{"); immutable l = indents.indentToMostRecent(tok!"{");
if (l != -1) if (l != -1)
@ -1150,10 +1154,16 @@ private:
} }
else else
{ {
while (indents.topIsTemp() && (peekBackIsOneOf(true, tok!"}", tok!";") && indents.top != tok!";")) if (indents.topIs(tok!"@"))
{
indents.pop(); indents.pop();
indentLevel = indents.indentLevel;
} }
}
else
{
while (indents.topIsTemp() && (peekBackIsOneOf(true, tok!"}", tok!";")
&& indents.top != tok!";"))
indents.pop();
indentLevel = indents.indentLevel; indentLevel = indents.indentLevel;
} }
indent(); indent();

View File

@ -12,7 +12,8 @@ import std.d.lexer;
*/ */
bool isWrapIndent(IdType type) pure nothrow @nogc @safe bool isWrapIndent(IdType type) pure nothrow @nogc @safe
{ {
return type != tok!"{" && type != tok!"case" && type != tok!"]" && isOperator(type); return type != tok!"{" && type != tok!"case" && type != tok!"@"
&& type != tok!"]" && isOperator(type);
} }
/** /**
@ -20,7 +21,7 @@ bool isWrapIndent(IdType type) pure nothrow @nogc @safe
*/ */
bool isTempIndent(IdType type) pure nothrow @nogc @safe bool isTempIndent(IdType type) pure nothrow @nogc @safe
{ {
return type != tok!"{" && type != tok!"case"; return type != tok!"{" && type != tok!"case" && type != tok!"@";
} }
/** /**

View File

@ -0,0 +1,11 @@
class SomeClass
{
public:
int x;
int y;
private:
int z;
}
public:
void doStuff();

1
tests/issue0130.args Normal file
View File

@ -0,0 +1 @@
--outdent_attributes=false

11
tests/issue0130.d Normal file
View File

@ -0,0 +1,11 @@
class SomeClass
{
public:
int x;
int y;
private:
int z;
}
public:
void doStuff();

View File

@ -0,0 +1,10 @@
class SomeClass {
public:
int x;
int y;
private:
int z;
}
public:
void doStuff();