This commit is contained in:
parent
91ae2d4fc3
commit
47bf248e95
32
src/dfmt.d
32
src/dfmt.d
|
@ -594,6 +594,13 @@ private:
|
||||||
if (current.type == tok!"{")
|
if (current.type == tok!"{")
|
||||||
{
|
{
|
||||||
depth++;
|
depth++;
|
||||||
|
if (assumeSorted(astInformation.structInitStartLocations)
|
||||||
|
.equalRange(tokens[index].index).length)
|
||||||
|
{
|
||||||
|
writeToken();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (config.braceStyle == BraceStyle.otbs)
|
if (config.braceStyle == BraceStyle.otbs)
|
||||||
{
|
{
|
||||||
write(" ");
|
write(" ");
|
||||||
|
@ -608,7 +615,16 @@ private:
|
||||||
index++;
|
index++;
|
||||||
newline();
|
newline();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (current.type == tok!"}")
|
else if (current.type == tok!"}")
|
||||||
|
{
|
||||||
|
if (assumeSorted(astInformation.structInitEndLocations)
|
||||||
|
.equalRange(tokens[index].index).length)
|
||||||
|
{
|
||||||
|
writeToken();
|
||||||
|
depth--;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// Silly hack to format enums better.
|
// Silly hack to format enums better.
|
||||||
if (peekBackIs(tok!"identifier"))
|
if (peekBackIs(tok!"identifier"))
|
||||||
|
@ -641,6 +657,7 @@ private:
|
||||||
newline();
|
newline();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
formatStep();
|
formatStep();
|
||||||
}
|
}
|
||||||
|
@ -950,6 +967,8 @@ struct ASTInformation
|
||||||
sort(unaryLocations);
|
sort(unaryLocations);
|
||||||
sort(attributeDeclarationLines);
|
sort(attributeDeclarationLines);
|
||||||
sort(caseEndLocations);
|
sort(caseEndLocations);
|
||||||
|
sort(structInitStartLocations);
|
||||||
|
sort(structInitEndLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Locations of end braces for struct bodies
|
/// Locations of end braces for struct bodies
|
||||||
|
@ -966,6 +985,12 @@ struct ASTInformation
|
||||||
|
|
||||||
/// Case statement colon locations
|
/// Case statement colon locations
|
||||||
size_t[] caseEndLocations;
|
size_t[] caseEndLocations;
|
||||||
|
|
||||||
|
/// Opening braces of struct initializers
|
||||||
|
size_t[] structInitStartLocations;
|
||||||
|
|
||||||
|
/// Closing braces of struct initializers
|
||||||
|
size_t[] structInitEndLocations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Collects information from the AST that is useful for the formatter
|
/// Collects information from the AST that is useful for the formatter
|
||||||
|
@ -1004,6 +1029,13 @@ final class FormatVisitor : ASTVisitor
|
||||||
functionBody.accept(this);
|
functionBody.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override void visit(const StructInitializer structInitializer)
|
||||||
|
{
|
||||||
|
astInformation.structInitStartLocations ~= structInitializer.startLocation;
|
||||||
|
astInformation.structInitEndLocations ~= structInitializer.endLocation;
|
||||||
|
structInitializer.accept(this);
|
||||||
|
}
|
||||||
|
|
||||||
override void visit(const EnumBody enumBody)
|
override void visit(const EnumBody enumBody)
|
||||||
{
|
{
|
||||||
astInformation.doubleNewlineLocations ~= enumBody.endLocation;
|
astInformation.doubleNewlineLocations ~= enumBody.endLocation;
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
immutable NameId[] namesA =
|
||||||
|
[
|
||||||
|
{"Aacgr", 0x00386}, // GREEK CAPITAL LETTER ALPHA WITH TONOS
|
||||||
|
{"aacgr", 0x003AC}, // GREEK SMALL LETTER ALPHA WITH TONOS
|
||||||
|
];
|
|
@ -0,0 +1,3 @@
|
||||||
|
immutable NameId[] namesA = [{"Aacgr", 0x00386}, // GREEK CAPITAL LETTER ALPHA WITH TONOS
|
||||||
|
{"aacgr", 0x003AC}, // GREEK SMALL LETTER ALPHA WITH TONOS
|
||||||
|
];
|
Loading…
Reference in New Issue