Merge branch 'master' of https://github.com/dlang-community/dfmt into master

This commit is contained in:
Hackerpilot 2020-08-11 14:21:51 -07:00
commit 0ff045669e
14 changed files with 106 additions and 12 deletions

View File

@ -4,7 +4,7 @@
"targetType": "autodetect", "targetType": "autodetect",
"license": "BSL-1.0", "license": "BSL-1.0",
"dependencies": { "dependencies": {
"libdparse": "~>0.14.0" "libdparse": ">=0.14.0 <0.16.0"
}, },
"targetPath" : "bin/", "targetPath" : "bin/",
"targetName" : "dfmt", "targetName" : "dfmt",

@ -1 +1 @@
Subproject commit 597d9a697b1f8a51fb2f441c61d0c6cc4eadc6d1 Subproject commit 1557eb079a2d5958e0a7136f942eea0922d58e8a

View File

@ -212,7 +212,9 @@ private:
{ {
immutable t = tokens[index].type; immutable t = tokens[index].type;
if (t == tok!"identifier" || isStringLiteral(t) if (t == tok!"identifier" || isStringLiteral(t)
|| isNumberLiteral(t) || t == tok!"characterLiteral") || isNumberLiteral(t) || t == tok!"characterLiteral"
// a!"b" function()
|| t == tok!"function" || t == tok!"delegate")
write(" "); write(" ");
} }
} }
@ -1620,16 +1622,21 @@ private:
{ {
import std.range : assumeSorted; import std.range : assumeSorted;
import std.algorithm.comparison : min; import std.algorithm.comparison : min;
import std.algorithm.searching : countUntil; import std.algorithm.searching : canFind, countUntil;
// The end of the tokens considered by the line break algorithm is // The end of the tokens considered by the line break algorithm is
// either the expression end index or the next mandatory line break, // either the expression end index or the next mandatory line break
// whichever is first. // or a newline inside a string literal, whichever is first.
auto r = assumeSorted(astInformation.ufcsHintLocations).upperBound(tokens[i].index); auto r = assumeSorted(astInformation.ufcsHintLocations).upperBound(tokens[i].index);
immutable ufcsBreakLocation = r.empty immutable ufcsBreakLocation = r.empty
? size_t.max ? size_t.max
: tokens[i .. $].countUntil!(t => t.index == r.front) + i; : tokens[i .. $].countUntil!(t => t.index == r.front) + i;
immutable size_t j = min(expressionEndIndex(i), ufcsBreakLocation); immutable multilineStringLocation = tokens[i .. $]
.countUntil!(t => t.text.canFind('\n'));
immutable size_t j = min(
expressionEndIndex(i),
ufcsBreakLocation,
multilineStringLocation == -1 ? size_t.max : multilineStringLocation + i + 1);
// Use magical negative value for array literals and wrap indents // Use magical negative value for array literals and wrap indents
immutable inLvl = (indents.topIsWrap() || indents.topIs(tok!"]")) ? -indentLevel immutable inLvl = (indents.topIsWrap() || indents.topIs(tok!"]")) ? -indentLevel
: indentLevel; : indentLevel;
@ -1713,7 +1720,14 @@ private:
} }
else if (currentIs(tok!"case") || currentIs(tok!"default")) else if (currentIs(tok!"case") || currentIs(tok!"default"))
{ {
if (peekBackIs(tok!"}", true) || peekBackIs(tok!";", true))
if (peekBackIs(tok!"}", true) || peekBackIs(tok!";", true)
/**
* The following code is valid and should be indented flatly
* case A:
* case B:
*/
|| peekBackIs(tok!":", true))
{ {
indents.popTempIndents(); indents.popTempIndents();
if (indents.topIs(tok!"case")) if (indents.topIs(tok!"case"))
@ -1830,7 +1844,11 @@ private:
case tok!"wstringLiteral": case tok!"wstringLiteral":
case tok!"dstringLiteral": case tok!"dstringLiteral":
immutable o = current.text.retro().countUntil('\n'); immutable o = current.text.retro().countUntil('\n');
currentLineLength += o == -1 ? current.text.length : o; if (o == -1) {
currentLineLength += current.text.length;
} else {
currentLineLength = cast(uint) o;
}
break; break;
default: default:
currentLineLength += current.text.length; currentLineLength += current.text.length;

View File

@ -172,9 +172,6 @@ size_t[] chooseLineBreakTokens(size_t index, const Token[] tokens,
void validMoves(OR)(auto ref OR output, const Token[] tokens, immutable short[] depths, void validMoves(OR)(auto ref OR output, const Token[] tokens, immutable short[] depths,
uint current, const Config* config, int currentLineLength, int indentLevel) uint current, const Config* config, int currentLineLength, int indentLevel)
{ {
import std.algorithm : sort, canFind, min;
import std.array : insertInPlace;
foreach (i, token; tokens) foreach (i, token; tokens)
{ {
if (!isBreakToken(token.type) || (((1 << i) & current) != 0)) if (!isBreakToken(token.type) || (((1 << i) & current) != 0))

View File

@ -0,0 +1,7 @@
string BuildForwardCall()
{
return `static if (is(typeof(mocked___.` ~ methodString ~ argsPassed ~ `)))
{
return (mocked___.` ~ methodString ~ argsPassed ~ `);
}`;
}

View File

@ -0,0 +1,15 @@
module tests.issue0483;
void main()
{
switch (0)
{
case 1:
case 2:
label:
case 3:
break;
default:
break;
}
}

View File

@ -0,0 +1,5 @@
alias f1 = S function();
alias f2 = S!"foo" function();
alias f3 = S!5 function();
alias f4 = S!S function();
alias f5 = S!(S) function();

7
tests/issue0476.d Normal file
View File

@ -0,0 +1,7 @@
string BuildForwardCall()
{
return `static if (is(typeof(mocked___.` ~ methodString ~ argsPassed ~ `)))
{
return (mocked___.` ~ methodString ~ argsPassed ~ `);
}`;
}

1
tests/issue0483.args Normal file
View File

@ -0,0 +1 @@
--align_switch_statements=false

15
tests/issue0483.d Normal file
View File

@ -0,0 +1,15 @@
module tests.issue0483;
void main()
{
switch (0)
{
case 1:
case 2:
label:
case 3:
break;
default:
break;
}
}

5
tests/issue0497.d Normal file
View File

@ -0,0 +1,5 @@
alias f1 = S function();
alias f2 = S!"foo" function();
alias f3 = S!5 function();
alias f4 = S!S function();
alias f5 = S!(S) function();

View File

@ -0,0 +1,6 @@
string BuildForwardCall() {
return `static if (is(typeof(mocked___.` ~ methodString ~ argsPassed ~ `)))
{
return (mocked___.` ~ methodString ~ argsPassed ~ `);
}`;
}

View File

@ -0,0 +1,13 @@
module tests.issue0483;
void main() {
switch (0) {
case 1:
case 2:
label:
case 3:
break;
default:
break;
}
}

View File

@ -0,0 +1,5 @@
alias f1 = S function();
alias f2 = S!"foo" function();
alias f3 = S!5 function();
alias f4 = S!S function();
alias f5 = S!(S) function();