Fix #120
This commit is contained in:
parent
0c0bcf3bf3
commit
5b68b60877
24
src/dfmt.d
24
src/dfmt.d
|
|
@ -207,8 +207,8 @@ private:
|
||||||
if (index < tokens.length)
|
if (index < tokens.length)
|
||||||
{
|
{
|
||||||
immutable t = tokens[index].type;
|
immutable t = tokens[index].type;
|
||||||
if (t == tok!"identifier" || isStringLiteral(t) || isNumberLiteral(t)
|
if (t == tok!"identifier" || isStringLiteral(t)
|
||||||
|| t == tok!"characterLiteral")
|
|| isNumberLiteral(t) || t == tok!"characterLiteral")
|
||||||
write(" ");
|
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()
|
void formatRightBrace()
|
||||||
{
|
{
|
||||||
if (astInformation.structInitEndLocations.canFindIndex(tokens[index].index))
|
if (!peekBackIsSlashSlash()
|
||||||
|
&& astInformation.structInitEndLocations.canFindIndex(tokens[index].index))
|
||||||
{
|
{
|
||||||
writeToken();
|
writeToken();
|
||||||
}
|
}
|
||||||
else if (astInformation.funLitEndLocations.canFindIndex(tokens[index].index))
|
else if (!peekBackIsSlashSlash()
|
||||||
|
&& astInformation.funLitEndLocations.canFindIndex(tokens[index].index))
|
||||||
{
|
{
|
||||||
write(" ");
|
write(" ");
|
||||||
writeToken();
|
writeToken();
|
||||||
|
|
@ -593,12 +601,12 @@ private:
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Silly hack to format enums better.
|
// Silly hack to format enums better.
|
||||||
if (peekBackIsLiteralOrIdent() || peekBackIs(tok!","))
|
if (peekBackIsLiteralOrIdent() || peekBackIs(tok!",", true))
|
||||||
newline();
|
newline();
|
||||||
write("}");
|
write("}");
|
||||||
if (index < tokens.length - 1
|
if (index < tokens.length - 1
|
||||||
&& astInformation.doubleNewlineLocations.canFindIndex(tokens[index].index)
|
&& astInformation.doubleNewlineLocations.canFindIndex(tokens[index].index)
|
||||||
&& !peekIs(tok!"}"))
|
&& !peekIs(tok!"}") && !peekIs(tok!";"))
|
||||||
{
|
{
|
||||||
write("\n");
|
write("\n");
|
||||||
currentLineLength = 0;
|
currentLineLength = 0;
|
||||||
|
|
@ -606,7 +614,7 @@ private:
|
||||||
}
|
}
|
||||||
if (config.braceStyle == BraceStyle.otbs && currentIs(tok!"else"))
|
if (config.braceStyle == BraceStyle.otbs && currentIs(tok!"else"))
|
||||||
write(" ");
|
write(" ");
|
||||||
if (!peekIs(tok!",") && !peekIs(tok!")"))
|
if (!peekIs(tok!",") && !peekIs(tok!")") && !peekIs(tok!";"))
|
||||||
{
|
{
|
||||||
index++;
|
index++;
|
||||||
newline();
|
newline();
|
||||||
|
|
@ -1105,7 +1113,7 @@ private:
|
||||||
|
|
||||||
immutable bool hasCurrent = index + 1 < tokens.length;
|
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)
|
&& !assumeSorted(astInformation.funLitEndLocations).equalRange(tokens[index].index).empty)
|
||||||
{
|
{
|
||||||
write(" ");
|
write(" ");
|
||||||
|
|
|
||||||
|
|
@ -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