Added partial support for the 'spaces_around_brackets' editorconfig option (only none and inside)

This commit is contained in:
Daniel 'Danol' Čejchan 2017-01-17 13:25:50 +01:00
parent 4a4704896b
commit 920ed7c268
2 changed files with 21 additions and 0 deletions

View File

@ -28,6 +28,13 @@ enum TemplateConstraintStyle
always_newline_indent always_newline_indent
} }
enum SpacesAroundBrackets
{
unspecified,
none,
inside
}
/// Configuration options for formatting /// Configuration options for formatting
struct Config struct Config
{ {
@ -51,6 +58,8 @@ struct Config
OptionalBoolean dfmt_compact_labeled_statements; OptionalBoolean dfmt_compact_labeled_statements;
/// ///
TemplateConstraintStyle dfmt_template_constraint_style; TemplateConstraintStyle dfmt_template_constraint_style;
///
SpacesAroundBrackets spaces_around_brackets;
mixin StandardEditorConfigFields; mixin StandardEditorConfigFields;
@ -76,6 +85,8 @@ 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;
spaces_around_brackets = SpacesAroundBrackets.none;
} }
/** /**

View File

@ -507,6 +507,10 @@ private:
spaceAfterParens = true; spaceAfterParens = true;
parenDepth++; parenDepth++;
} }
if( config.spaces_around_brackets == SpacesAroundBrackets.inside && !currentIs(tok!")") && !currentIs(tok!"]") )
write(" ");
immutable bool arrayInitializerStart = p == tok!"[" && linebreakHints.length != 0 immutable bool arrayInitializerStart = p == tok!"[" && linebreakHints.length != 0
&& astInformation.arrayStartLocations.canFindIndex(tokens[index - 1].index); && astInformation.arrayStartLocations.canFindIndex(tokens[index - 1].index);
if (arrayInitializerStart) if (arrayInitializerStart)
@ -535,6 +539,9 @@ private:
} }
body body
{ {
if( config.spaces_around_brackets == SpacesAroundBrackets.inside )
write(" ");
parenDepth--; parenDepth--;
indents.popWrapIndents(); indents.popWrapIndents();
while (indents.topIsOneOf(tok!"!", tok!")")) while (indents.topIsOneOf(tok!"!", tok!")"))
@ -1084,6 +1091,9 @@ private:
formatColon(); formatColon();
break; break;
case tok!"]": case tok!"]":
if( config.spaces_around_brackets == SpacesAroundBrackets.inside )
write(" ");
indents.popWrapIndents(); indents.popWrapIndents();
if (indents.topIs(tok!"]")) if (indents.topIs(tok!"]"))
newline(); newline();