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

View File

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