Skip to content

Commit

Permalink
condensing new lines after a comment down to a single line (#1446)
Browse files Browse the repository at this point in the history
closes #1443
  • Loading branch information
belav authored Jan 20, 2025
1 parent 6eb1253 commit 2d852d1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
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

0 comments on commit 2d852d1

Please sign in to comment.