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

Keep extra new lines before block #391

Merged
merged 2 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class ClassName
}

public void LongMethodNameForceLineBreak(
string oneoneoneoneoneoneoneoneone,
string twotwotwotwotwotwotwotwo,
string threethreethreethreethreethree
string firstParameter___________,
string secondParameter___________,
string thirdParameter___________
) {
return;
}
Expand All @@ -23,12 +23,12 @@ public class ClassName
string three
) { }

public void ReallyLongMethodNameWithoutAnyParametersShouldNewLineBrace111111()
public void ReallyLongMethodNameWithoutAnyParametersShouldNewLineBrace_______()
{
return;
}

public void DoStuff(
public void MethodName(
// leading
string one, // trailing
string two,
Expand All @@ -37,12 +37,12 @@ public class ClassName
var x = 0;
}

public void DoStuff(string one, string two) { }
public void MethodName(string one, string two) { }

public void DoStuff()
public void MethodName()
{
DoStuff();
DoStuff();
MethodName();
MethodName();
}

private Doc MethodWithParameters__________________(
Expand All @@ -68,6 +68,15 @@ public class ClassName
return;
}
}

public void MethodName()
{
var keepNextExtraLine = 1;

{
return;
}
}
}

class ExplicitInterfaceSpecifier : IDisposable
Expand Down
6 changes: 5 additions & 1 deletion Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static Doc Print(BlockSyntax node, string? groupId)
DocUtilities.RemoveInitialDoubleHardLine(innerDoc);
}

return Doc.Group(
var result = Doc.Group(
groupId != null
? Doc.IfBreak(" ", Doc.Line, groupId)
: node.Parent is ParenthesizedLambdaExpressionSyntax or BlockSyntax
Expand All @@ -59,6 +59,10 @@ private static Doc Print(BlockSyntax node, string? groupId)
node.Statements.Count == 0 ? " " : Doc.Concat(innerDoc, statementSeparator),
Token.Print(node.CloseBraceToken)
);

return node.Parent is BlockSyntax
? Doc.Concat(ExtraNewLines.Print(node), result)
: result;
}
}
}