Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow comments in selective imports. #403

Merged
merged 4 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions src/dfmt/formatter.d
Original file line number Diff line number Diff line change
Expand Up @@ -523,29 +523,20 @@ private:
if (config.dfmt_selective_import_space)
write(" ");
writeToken();
write(" ");
if (!currentIs(tok!"comment"))
write(" ");
pushWrapIndent(tok!",");
}
else if (currentIs(tok!","))
else if (currentIs(tok!"comment"))
{
// 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;
const len = tokenLength(tokens[i]);
assert(len >= 0);
lengthOfNextChunk += len;
}
assert(lengthOfNextChunk > 0);
writeToken();
if (currentLineLength + 1 + lengthOfNextChunk >= config.dfmt_soft_max_line_length)
if (peekBack.line != current.line)
{
pushWrapIndent(tok!",");
newline();
// The comment appears on its own line, keep it there.
if (!peekBackIs(tok!"comment"))
// Comments are already properly separated.
newline();
}
else
write(" ");
formatStep();
}
else
formatStep();
Expand Down
3 changes: 2 additions & 1 deletion tests/allman/issue0349.d.ref
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import super_long_import_module_name : withSuperLongSymbolNames, andAlsoLotsOfThem;
import super_long_import_module_name : withSuperLongSymbolNames,
andAlsoLotsOfThem;
andAlsoLotsOfThem, lotsAnsLots, andLots, andLotsOfThem, lineExceeds120;

private:
void foo();
30 changes: 30 additions & 0 deletions tests/allman/issue0384.d.ref
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions tests/issue0349.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import super_long_import_module_name : withSuperLongSymbolNames, andAlsoLotsOfThem;
import super_long_import_module_name : withSuperLongSymbolNames, andAlsoLotsOfThem, lotsAnsLots, andLots, andLotsOfThem, lineExceeds120;

private:
void foo();
29 changes: 29 additions & 0 deletions tests/issue0384.d
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion tests/otbs/issue0349.d.ref
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import super_long_import_module_name : withSuperLongSymbolNames, andAlsoLotsOfThem;
import super_long_import_module_name : withSuperLongSymbolNames,
andAlsoLotsOfThem;
andAlsoLotsOfThem, lotsAnsLots, andLots, andLotsOfThem, lineExceeds120;

private:
void foo();
30 changes: 30 additions & 0 deletions tests/otbs/issue0384.d.ref
Original file line number Diff line number Diff line change
@@ -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;