mirror of
https://github.com/dlang-community/dfmt.git
synced 2025-04-29 06:39:55 +03:00
This commit is contained in:
parent
91ae2d4fc3
commit
47bf248e95
3 changed files with 67 additions and 27 deletions
32
src/dfmt.d
32
src/dfmt.d
|
@ -594,6 +594,13 @@ private:
|
|||
if (current.type == tok!"{")
|
||||
{
|
||||
depth++;
|
||||
if (assumeSorted(astInformation.structInitStartLocations)
|
||||
.equalRange(tokens[index].index).length)
|
||||
{
|
||||
writeToken();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (config.braceStyle == BraceStyle.otbs)
|
||||
{
|
||||
write(" ");
|
||||
|
@ -608,7 +615,16 @@ private:
|
|||
index++;
|
||||
newline();
|
||||
}
|
||||
}
|
||||
else if (current.type == tok!"}")
|
||||
{
|
||||
if (assumeSorted(astInformation.structInitEndLocations)
|
||||
.equalRange(tokens[index].index).length)
|
||||
{
|
||||
writeToken();
|
||||
depth--;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Silly hack to format enums better.
|
||||
if (peekBackIs(tok!"identifier"))
|
||||
|
@ -641,6 +657,7 @@ private:
|
|||
newline();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
formatStep();
|
||||
}
|
||||
|
@ -950,6 +967,8 @@ struct ASTInformation
|
|||
sort(unaryLocations);
|
||||
sort(attributeDeclarationLines);
|
||||
sort(caseEndLocations);
|
||||
sort(structInitStartLocations);
|
||||
sort(structInitEndLocations);
|
||||
}
|
||||
|
||||
/// Locations of end braces for struct bodies
|
||||
|
@ -966,6 +985,12 @@ struct ASTInformation
|
|||
|
||||
/// Case statement colon locations
|
||||
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
|
||||
|
@ -1004,6 +1029,13 @@ final class FormatVisitor : ASTVisitor
|
|||
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)
|
||||
{
|
||||
astInformation.doubleNewlineLocations ~= enumBody.endLocation;
|
||||
|
|
5
tests/issue0017.d
Normal file
5
tests/issue0017.d
Normal file
|
@ -0,0 +1,5 @@
|
|||
immutable NameId[] namesA =
|
||||
[
|
||||
{"Aacgr", 0x00386}, // GREEK CAPITAL LETTER ALPHA WITH TONOS
|
||||
{"aacgr", 0x003AC}, // GREEK SMALL LETTER ALPHA WITH TONOS
|
||||
];
|
3
tests/issue0017.d.ref
Normal file
3
tests/issue0017.d.ref
Normal file
|
@ -0,0 +1,3 @@
|
|||
immutable NameId[] namesA = [{"Aacgr", 0x00386}, // GREEK CAPITAL LETTER ALPHA WITH TONOS
|
||||
{"aacgr", 0x003AC}, // GREEK SMALL LETTER ALPHA WITH TONOS
|
||||
];
|
Loading…
Add table
Add a link
Reference in a new issue