Fix #120
This commit is contained in:
parent
0c0bcf3bf3
commit
5b68b60877
26
src/dfmt.d
26
src/dfmt.d
|
|
@ -207,8 +207,8 @@ private:
|
|||
if (index < tokens.length)
|
||||
{
|
||||
immutable t = tokens[index].type;
|
||||
if (t == tok!"identifier" || isStringLiteral(t) || isNumberLiteral(t)
|
||||
|| t == tok!"characterLiteral")
|
||||
if (t == tok!"identifier" || isStringLiteral(t)
|
||||
|| isNumberLiteral(t) || t == tok!"characterLiteral")
|
||||
write(" ");
|
||||
}
|
||||
}
|
||||
|
|
@ -579,13 +579,21 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
bool peekBackIsSlashSlash()
|
||||
{
|
||||
return index > 0 && tokens[index - 1].type == tok!"comment"
|
||||
&& tokens[index - 1].text[0 .. 2] == "//";
|
||||
}
|
||||
|
||||
void formatRightBrace()
|
||||
{
|
||||
if (astInformation.structInitEndLocations.canFindIndex(tokens[index].index))
|
||||
if (!peekBackIsSlashSlash()
|
||||
&& astInformation.structInitEndLocations.canFindIndex(tokens[index].index))
|
||||
{
|
||||
writeToken();
|
||||
}
|
||||
else if (astInformation.funLitEndLocations.canFindIndex(tokens[index].index))
|
||||
else if (!peekBackIsSlashSlash()
|
||||
&& astInformation.funLitEndLocations.canFindIndex(tokens[index].index))
|
||||
{
|
||||
write(" ");
|
||||
writeToken();
|
||||
|
|
@ -593,12 +601,12 @@ private:
|
|||
else
|
||||
{
|
||||
// Silly hack to format enums better.
|
||||
if (peekBackIsLiteralOrIdent() || peekBackIs(tok!","))
|
||||
if (peekBackIsLiteralOrIdent() || peekBackIs(tok!",", true))
|
||||
newline();
|
||||
write("}");
|
||||
if (index < tokens.length - 1
|
||||
&& astInformation.doubleNewlineLocations.canFindIndex(tokens[index].index)
|
||||
&& !peekIs(tok!"}"))
|
||||
&& !peekIs(tok!"}") && !peekIs(tok!";"))
|
||||
{
|
||||
write("\n");
|
||||
currentLineLength = 0;
|
||||
|
|
@ -606,7 +614,7 @@ private:
|
|||
}
|
||||
if (config.braceStyle == BraceStyle.otbs && currentIs(tok!"else"))
|
||||
write(" ");
|
||||
if (!peekIs(tok!",") && !peekIs(tok!")"))
|
||||
if (!peekIs(tok!",") && !peekIs(tok!")") && !peekIs(tok!";"))
|
||||
{
|
||||
index++;
|
||||
newline();
|
||||
|
|
@ -1105,7 +1113,7 @@ private:
|
|||
|
||||
immutable bool hasCurrent = index + 1 < tokens.length;
|
||||
|
||||
if (hasCurrent && tokens[index].type == tok!"}"
|
||||
if (!peekBackIsSlashSlash() && hasCurrent && tokens[index].type == tok!"}"
|
||||
&& !assumeSorted(astInformation.funLitEndLocations).equalRange(tokens[index].index).empty)
|
||||
{
|
||||
write(" ");
|
||||
|
|
@ -1244,7 +1252,7 @@ private:
|
|||
{
|
||||
// You know what's awesome? Windows can't handle its own line
|
||||
// endings correctly.
|
||||
version(Windows)
|
||||
version (Windows)
|
||||
output.put(current.text.replace("\r", ""));
|
||||
else
|
||||
output.put(current.text);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
auto fun = { int i; // Comment
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
auto fun = {
|
||||
int i; // Comment
|
||||
};
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
auto fun = { int i; // Comment
|
||||
};
|
||||
Loading…
Reference in New Issue