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

condensing new lines after a comment down to a single line #1446

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -13,7 +13,6 @@ string formatMe;
string keepNewLine;
// csharpier-ignore-end


// csharpier-ignore-start
string removeNewLine;
// csharpier-ignore-end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var x = 1;

// condense down to just a single extra line

var y = 2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var x = 1;

// condense down to just a single extra line




var y = 2;
6 changes: 5 additions & 1 deletion Src/CSharpier/SyntaxPrinter/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ private static Doc PrivatePrintLeadingTrivia(

if (printNewLines && kind == SyntaxKind.EndOfLineTrivia)
{
if (docs.Count > 0 && docs[^1] == Doc.HardLineSkipBreakIfFirstInGroup)
{
printNewLines = false;
}
docs.Add(Doc.HardLineSkipBreakIfFirstInGroup);
}
if (kind is not (SyntaxKind.EndOfLineTrivia or SyntaxKind.WhitespaceTrivia))
Expand Down Expand Up @@ -317,7 +321,7 @@ void AddLeadingComment(CommentType commentType)
}
}

while (skipLastHardline && docs.Any() && docs.Last() is HardLine or NullDoc)
while (skipLastHardline && docs.Count != 0 && docs.Last() is HardLine or NullDoc)
{
docs.RemoveAt(docs.Count - 1);
}
Expand Down
Loading