Merge pull request #473 from belka-ew/break-on-this
keep_line_breaks: multi-line tokens and argument list break
This commit is contained in:
commit
1964f807cf
|
@ -1574,13 +1574,6 @@ private:
|
||||||
newline();
|
newline();
|
||||||
regenLineBreakHints(index - 1);
|
regenLineBreakHints(index - 1);
|
||||||
}
|
}
|
||||||
else if (!peekIs(tok!"}") && (linebreakHints.canFind(index)
|
|
||||||
|| (linebreakHints.length == 0 && currentLineLength > config.max_line_length)))
|
|
||||||
{
|
|
||||||
pushWrapIndent();
|
|
||||||
writeToken();
|
|
||||||
newline();
|
|
||||||
}
|
|
||||||
else if (config.dfmt_keep_line_breaks == OptionalBoolean.t)
|
else if (config.dfmt_keep_line_breaks == OptionalBoolean.t)
|
||||||
{
|
{
|
||||||
const commaLine = tokens[index].line;
|
const commaLine = tokens[index].line;
|
||||||
|
@ -1599,6 +1592,13 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!peekIs(tok!"}") && (linebreakHints.canFind(index)
|
||||||
|
|| (linebreakHints.length == 0 && currentLineLength > config.max_line_length)))
|
||||||
|
{
|
||||||
|
pushWrapIndent();
|
||||||
|
writeToken();
|
||||||
|
newline();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
writeToken();
|
writeToken();
|
||||||
|
@ -2151,10 +2151,22 @@ const pure @safe @nogc:
|
||||||
bool onNextLine() @nogc nothrow pure @safe
|
bool onNextLine() @nogc nothrow pure @safe
|
||||||
{
|
{
|
||||||
import dfmt.editorconfig : OptionalBoolean;
|
import dfmt.editorconfig : OptionalBoolean;
|
||||||
|
import std.algorithm.searching : count;
|
||||||
|
import std.string : representation;
|
||||||
|
|
||||||
return config.dfmt_keep_line_breaks == OptionalBoolean.t
|
if (config.dfmt_keep_line_breaks == OptionalBoolean.f || index <= 0)
|
||||||
&& index > 0
|
{
|
||||||
&& tokens[index - 1].line < tokens[index].line;
|
return false;
|
||||||
|
}
|
||||||
|
// To compare whether 2 tokens are on same line, we need the end line
|
||||||
|
// of the first token (tokens[index - 1]) and the start line of the
|
||||||
|
// second one (tokens[index]). If a token takes multiple lines (e.g. a
|
||||||
|
// multi-line string), we can sum the number of the newlines in the
|
||||||
|
// token and tokens[index - 1].line, the start line.
|
||||||
|
const previousTokenEndLineNo = tokens[index - 1].line
|
||||||
|
+ tokens[index - 1].text.representation.count('\n');
|
||||||
|
|
||||||
|
return previousTokenEndLineNo < tokens[index].line;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bugs: not unicode correct
|
/// Bugs: not unicode correct
|
||||||
|
|
|
@ -21,6 +21,15 @@ int[] func(int argument_1_1, int argument_1_2,
|
||||||
.func(argument_2_1)
|
.func(argument_2_1)
|
||||||
.func(argument_2_2);
|
.func(argument_2_2);
|
||||||
|
|
||||||
|
auto x = func(argument_1_1, argument_1_2,
|
||||||
|
this.argument_2_1, this.argument_2_2,
|
||||||
|
argument_3_1, argument_3_2);
|
||||||
|
|
||||||
|
`
|
||||||
|
<html>
|
||||||
|
</html>
|
||||||
|
`.format!"%s";
|
||||||
|
|
||||||
return [
|
return [
|
||||||
3, 5,
|
3, 5,
|
||||||
5, 7,
|
5, 7,
|
||||||
|
|
|
@ -21,6 +21,15 @@ int[] func(int argument_1_1, int argument_1_2,
|
||||||
.func(argument_2_1)
|
.func(argument_2_1)
|
||||||
.func(argument_2_2);
|
.func(argument_2_2);
|
||||||
|
|
||||||
|
auto x = func(argument_1_1, argument_1_2,
|
||||||
|
this.argument_2_1, this.argument_2_2,
|
||||||
|
argument_3_1, argument_3_2);
|
||||||
|
|
||||||
|
`
|
||||||
|
<html>
|
||||||
|
</html>
|
||||||
|
`.format!"%s";
|
||||||
|
|
||||||
return [
|
return [
|
||||||
3, 5,
|
3, 5,
|
||||||
5, 7,
|
5, 7,
|
||||||
|
|
|
@ -17,6 +17,15 @@ int[] func(int argument_1_1, int argument_1_2,
|
||||||
.func(argument_2_1)
|
.func(argument_2_1)
|
||||||
.func(argument_2_2);
|
.func(argument_2_2);
|
||||||
|
|
||||||
|
auto x = func(argument_1_1, argument_1_2,
|
||||||
|
this.argument_2_1, this.argument_2_2,
|
||||||
|
argument_3_1, argument_3_2);
|
||||||
|
|
||||||
|
`
|
||||||
|
<html>
|
||||||
|
</html>
|
||||||
|
`.format!"%s";
|
||||||
|
|
||||||
return [
|
return [
|
||||||
3, 5,
|
3, 5,
|
||||||
5, 7,
|
5, 7,
|
||||||
|
|
Loading…
Reference in New Issue