Allow multilineAt to stop at commas
This commit is contained in:
parent
733898e013
commit
eebd341343
|
@ -809,11 +809,9 @@ private:
|
||||||
if (astInformation.structInitStartLocations.canFindIndex(tIndex))
|
if (astInformation.structInitStartLocations.canFindIndex(tIndex))
|
||||||
{
|
{
|
||||||
sBraceDepth++;
|
sBraceDepth++;
|
||||||
auto e = expressionEndIndex(index);
|
immutable bool multiline = isMultilineAt(index);
|
||||||
immutable int l = currentLineLength + tokens[index .. e].map!(a => tokenLength(a))
|
|
||||||
.sum();
|
|
||||||
writeToken();
|
writeToken();
|
||||||
if (l > config.dfmt_soft_max_line_length)
|
if (multiline)
|
||||||
{
|
{
|
||||||
import std.algorithm.searching : find;
|
import std.algorithm.searching : find;
|
||||||
|
|
||||||
|
@ -1729,7 +1727,7 @@ private:
|
||||||
|
|
||||||
const pure @safe @nogc:
|
const pure @safe @nogc:
|
||||||
|
|
||||||
size_t expressionEndIndex(size_t i) nothrow
|
size_t expressionEndIndex(size_t i, bool matchComma = false) nothrow
|
||||||
{
|
{
|
||||||
immutable bool braces = i < tokens.length && tokens[i].type == tok!"{";
|
immutable bool braces = i < tokens.length && tokens[i].type == tok!"{";
|
||||||
immutable bool brackets = i < tokens.length && tokens[i].type == tok!"[";
|
immutable bool brackets = i < tokens.length && tokens[i].type == tok!"[";
|
||||||
|
@ -1740,6 +1738,8 @@ const pure @safe @nogc:
|
||||||
break;
|
break;
|
||||||
if (depths[i] < d)
|
if (depths[i] < d)
|
||||||
break;
|
break;
|
||||||
|
if (!braces && !brackets && matchComma && depths[i] == d && tokens[i].type == tok!",")
|
||||||
|
break;
|
||||||
if (!braces && !brackets && (tokens[i].type == tok!";" || tokens[i].type == tok!"{"))
|
if (!braces && !brackets && (tokens[i].type == tok!";" || tokens[i].type == tok!"{"))
|
||||||
break;
|
break;
|
||||||
i++;
|
i++;
|
||||||
|
@ -1749,14 +1749,14 @@ const pure @safe @nogc:
|
||||||
|
|
||||||
/// Returns: true when the expression starting at index goes over the line length limit.
|
/// Returns: true when the expression starting at index goes over the line length limit.
|
||||||
/// Uses matching `{}` or `[]` or otherwise takes everything up until a semicolon or opening brace using expressionEndIndex.
|
/// Uses matching `{}` or `[]` or otherwise takes everything up until a semicolon or opening brace using expressionEndIndex.
|
||||||
bool isMultilineAt(size_t i)
|
bool isMultilineAt(size_t i, bool matchComma = false)
|
||||||
{
|
{
|
||||||
import std.algorithm : map, sum, canFind;
|
import std.algorithm : map, sum, canFind;
|
||||||
|
|
||||||
auto e = expressionEndIndex(i);
|
auto e = expressionEndIndex(i, matchComma);
|
||||||
immutable int l = currentLineLength + tokens[i .. e].map!(a => tokenLength(a)).sum();
|
immutable int l = currentLineLength + tokens[i .. e].map!(a => tokenLength(a)).sum();
|
||||||
return l > config.dfmt_soft_max_line_length
|
return l > config.dfmt_soft_max_line_length || tokens[i .. e].canFind!(
|
||||||
|| tokens[i .. e].canFind!(a => a.type == tok!"comment" || isBlockHeaderToken(a.type))();
|
a => a.type == tok!"comment" || isBlockHeaderToken(a.type))();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool peekIsKeyword() nothrow
|
bool peekIsKeyword() nothrow
|
||||||
|
|
Loading…
Reference in New Issue