Use general indent and line braking logic.
- Let a single `pushWrapIndex` take care of indexing. - Remove chunk length calculation entirely. - Comment spacing is funny, fix by special casing. Bonus: comments that appear on a separate line are kept on a separate line.
This commit is contained in:
parent
5c28af1ac7
commit
18c642e091
|
@ -523,28 +523,20 @@ private:
|
||||||
if (config.dfmt_selective_import_space)
|
if (config.dfmt_selective_import_space)
|
||||||
write(" ");
|
write(" ");
|
||||||
writeToken();
|
writeToken();
|
||||||
write(" ");
|
if (!currentIs(tok!"comment"))
|
||||||
}
|
|
||||||
else if (currentIs(tok!","))
|
|
||||||
{
|
|
||||||
// compute length until next ',' or ';'
|
|
||||||
int lengthOfNextChunk;
|
|
||||||
for (size_t i = index + 1; i < tokens.length; i++)
|
|
||||||
{
|
|
||||||
if (tokens[i].type == tok!"," || tokens[i].type == tok!";")
|
|
||||||
break;
|
|
||||||
immutable len = tokens[i].text.length;
|
|
||||||
lengthOfNextChunk += len;
|
|
||||||
}
|
|
||||||
assert(lengthOfNextChunk > 0);
|
|
||||||
writeToken();
|
|
||||||
if (currentLineLength + 1 + lengthOfNextChunk >= config.dfmt_soft_max_line_length)
|
|
||||||
{
|
|
||||||
pushWrapIndent(tok!",");
|
|
||||||
newline();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
write(" ");
|
write(" ");
|
||||||
|
pushWrapIndent(tok!",");
|
||||||
|
}
|
||||||
|
else if (currentIs(tok!"comment"))
|
||||||
|
{
|
||||||
|
if (peekBack.line != current.line)
|
||||||
|
{
|
||||||
|
// The comment appears on its own line, keep it there.
|
||||||
|
if (!peekBackIs(tok!"comment"))
|
||||||
|
// Comments are already properly separated.
|
||||||
|
newline();
|
||||||
|
}
|
||||||
|
formatStep();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
formatStep();
|
formatStep();
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
import std.stdio : readln, /* comment1 */ writeln;
|
||||||
|
import std.stdio : readln, // comment2
|
||||||
|
writeln;
|
||||||
|
import std.stdio : readln,
|
||||||
|
// comment3
|
||||||
|
writeln;
|
||||||
|
import std.stdio : readln,
|
||||||
|
/* comment4 */
|
||||||
|
writeln;
|
||||||
|
import std.stdio : readln, readln, readln, readln, readln, readln, readln,
|
||||||
|
readln, readln, readln, readln,
|
||||||
|
// comment5
|
||||||
|
writeln;
|
||||||
|
import std.stdio : // comment6
|
||||||
|
readln, readln, readln, readln, readln, readln, // comment7
|
||||||
|
// comment8
|
||||||
|
writeln;
|
||||||
|
import std.stdio : /* comment9 */
|
||||||
|
readln, readln, readln, readln, readln, readln, /* comment10 */
|
||||||
|
// comment11
|
||||||
|
writeln;
|
||||||
|
import std.stdio : readln, // comment12
|
||||||
|
readln, readln, readln, readln, readln, readln, // comment13
|
||||||
|
// comment14
|
||||||
|
writeln;
|
||||||
|
import std.stdio : readln,
|
||||||
|
// comment15
|
||||||
|
readln, readln, readln, readln, readln, readln, // comment16
|
||||||
|
// comment17
|
||||||
|
writeln;
|
|
@ -0,0 +1,29 @@
|
||||||
|
import std.stdio : readln, /* comment1 */ writeln;
|
||||||
|
import std.stdio : readln, // comment2
|
||||||
|
writeln;
|
||||||
|
import std.stdio : readln,
|
||||||
|
// comment3
|
||||||
|
writeln;
|
||||||
|
import std.stdio : readln,
|
||||||
|
/* comment4 */
|
||||||
|
writeln;
|
||||||
|
import std.stdio : readln, readln, readln, readln, readln, readln, readln, readln, readln, readln, readln,
|
||||||
|
// comment5
|
||||||
|
writeln;
|
||||||
|
import std.stdio : // comment6
|
||||||
|
readln, readln, readln, readln, readln, readln, // comment7
|
||||||
|
// comment8
|
||||||
|
writeln;
|
||||||
|
import std.stdio : /* comment9 */
|
||||||
|
readln, readln, readln, readln, readln, readln, /* comment10 */
|
||||||
|
// comment11
|
||||||
|
writeln;
|
||||||
|
import std.stdio : readln, // comment12
|
||||||
|
readln, readln, readln, readln, readln, readln, // comment13
|
||||||
|
// comment14
|
||||||
|
writeln;
|
||||||
|
import std.stdio : readln,
|
||||||
|
// comment15
|
||||||
|
readln, readln, readln, readln, readln, readln, // comment16
|
||||||
|
// comment17
|
||||||
|
writeln;
|
|
@ -0,0 +1,30 @@
|
||||||
|
import std.stdio : readln, /* comment1 */ writeln;
|
||||||
|
import std.stdio : readln, // comment2
|
||||||
|
writeln;
|
||||||
|
import std.stdio : readln,
|
||||||
|
// comment3
|
||||||
|
writeln;
|
||||||
|
import std.stdio : readln,
|
||||||
|
/* comment4 */
|
||||||
|
writeln;
|
||||||
|
import std.stdio : readln, readln, readln, readln, readln, readln, readln,
|
||||||
|
readln, readln, readln, readln,
|
||||||
|
// comment5
|
||||||
|
writeln;
|
||||||
|
import std.stdio : // comment6
|
||||||
|
readln, readln, readln, readln, readln, readln, // comment7
|
||||||
|
// comment8
|
||||||
|
writeln;
|
||||||
|
import std.stdio : /* comment9 */
|
||||||
|
readln, readln, readln, readln, readln, readln, /* comment10 */
|
||||||
|
// comment11
|
||||||
|
writeln;
|
||||||
|
import std.stdio : readln, // comment12
|
||||||
|
readln, readln, readln, readln, readln, readln, // comment13
|
||||||
|
// comment14
|
||||||
|
writeln;
|
||||||
|
import std.stdio : readln,
|
||||||
|
// comment15
|
||||||
|
readln, readln, readln, readln, readln, readln, // comment16
|
||||||
|
// comment17
|
||||||
|
writeln;
|
Loading…
Reference in New Issue