Merge pull request from dlang-community/master

Allow comments in selective imports. ()
This commit is contained in:
Bastiaan Veelo 2018-10-29 12:04:52 +01:00 committed by GitHub
commit 5274e5531e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 107 additions and 24 deletions

View File

@ -523,29 +523,20 @@ private:
if (config.dfmt_selective_import_space)
write(" ");
writeToken();
write(" ");
}
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;
const len = tokenLength(tokens[i]);
assert(len >= 0);
lengthOfNextChunk += len;
}
assert(lengthOfNextChunk > 0);
writeToken();
if (currentLineLength + 1 + lengthOfNextChunk >= config.dfmt_soft_max_line_length)
{
pushWrapIndent(tok!",");
newline();
}
else
if (!currentIs(tok!"comment"))
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
formatStep();

View File

@ -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();

View File

@ -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;

View File

@ -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
tests/issue0384.d Normal file
View File

@ -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;

View File

@ -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();

View File

@ -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;