Compare commits

...

3 Commits

6 changed files with 67 additions and 7 deletions

View File

@ -454,14 +454,31 @@ final class FormatVisitor : ASTVisitor
override void visit(const FunctionCallExpression functionCall) override void visit(const FunctionCallExpression functionCall)
{ {
// Check if function has any arguments. visit(functionCall.arguments);
if (functionCall.arguments.namedArgumentList is null) functionCall.accept(this);
}
override void visit(const NewExpression newCall)
{
visit(newCall.arguments);
newCall.accept(this);
}
override void visit(const NewAnonClassExpression newAnonClassCall)
{
visit(newAnonClassCall.constructorArguments);
newAnonClassCall.accept(this);
}
private void visit(const Arguments arguments)
{
// Check if call has any arguments.
if (!arguments || arguments.namedArgumentList is null)
{ {
functionCall.accept(this);
return; return;
} }
foreach (item; functionCall.arguments.namedArgumentList.items) foreach (item; arguments.namedArgumentList.items)
{ {
// Do nothing if not a named argument. // Do nothing if not a named argument.
if (item.name == tok!"") if (item.name == tok!"")
@ -479,8 +496,6 @@ final class FormatVisitor : ASTVisitor
} }
} }
} }
functionCall.accept(this);
} }
private: private:

View File

@ -1783,6 +1783,8 @@ private:
if (hasCurrent) if (hasCurrent)
{ {
const isNamedArg = index + 1 < tokens.length
&& astInformation.namedArgumentColonLocations.canFindIndex(tokens[index + 1].index);
if (currentIs(tok!"else")) if (currentIs(tok!"else"))
{ {
immutable i = indents.indentToMostRecent(tok!"if"); immutable i = indents.indentToMostRecent(tok!"if");
@ -1791,7 +1793,7 @@ private:
if (mostRecent != -1) if (mostRecent != -1)
indentLevel = mostRecent; indentLevel = mostRecent;
} }
else if (currentIs(tok!"identifier") && peekIs(tok!":")) else if (currentIs(tok!"identifier") && peekIs(tok!":") && !isNamedArg)
{ {
if (peekBackIs(tok!"}", true) || peekBackIs(tok!";", true)) if (peekBackIs(tok!"}", true) || peekBackIs(tok!";", true))
indents.popTempIndents(); indents.popTempIndents();

View File

@ -26,3 +26,13 @@ void main()
temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1); temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1);
} }
void test()
{
return Struct(foo: field.foo, bar: field.bar, baz: field.baz);
return new Class(foo: field.foo, bar: field.bar, baz: field.baz);
// anonymous class
return new class(foo: field.foo, bar: field.bar, baz: field.baz) Class
{
};
}

View File

@ -29,3 +29,19 @@ void main()
temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1); temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1);
} }
void test() {
return Struct(
foo: field.foo,
bar: field.bar,
baz: field.baz);
return new Class(
foo: field.foo,
bar: field.bar,
baz: field.baz);
// anonymous class
return new class(
foo: field.foo,
bar: field.bar,
baz: field.baz) Class { };
}

View File

@ -25,3 +25,12 @@ void main()
temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1); temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1);
} }
void test()
{
return Struct(foo: field.foo, bar: field.bar, baz: field.baz);
return new Class(foo: field.foo, bar: field.bar, baz: field.baz);
// anonymous class
return new class(foo: field.foo, bar: field.bar, baz: field.baz) Class {
};
}

View File

@ -22,3 +22,11 @@ void main() {
temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1); temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1);
} }
void test() {
return Struct(foo: field.foo, bar: field.bar, baz: field.baz);
return new Class(foo: field.foo, bar: field.bar, baz: field.baz);
// anonymous class
return new class(foo: field.foo, bar: field.bar, baz: field.baz) Class {
};
}