diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/EnumDeclarationComments.cst b/Src/CSharpier.Tests/FormattingTests/TestFiles/EnumDeclarationComments.cst new file mode 100644 index 000000000..cdff995b3 --- /dev/null +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/EnumDeclarationComments.cst @@ -0,0 +1,15 @@ +public enum SubCode +{ + First, + + // keep line + BasicComment, + + /* keep line */ + MultiLineComment, + + /// keep line + XmlComment, + + DoNotKeepLine +} diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/EnumDeclarationComments.expected.cst b/Src/CSharpier.Tests/FormattingTests/TestFiles/EnumDeclarationComments.expected.cst new file mode 100644 index 000000000..62a7c9601 --- /dev/null +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/EnumDeclarationComments.expected.cst @@ -0,0 +1,14 @@ +public enum SubCode +{ + First, + + // keep line + BasicComment, + + /* keep line */ + MultiLineComment, + + /// keep line + XmlComment, + DoNotKeepLine +} diff --git a/Src/CSharpier/DocPrinter/PropagateBreaks.cs b/Src/CSharpier/DocPrinter/PropagateBreaks.cs index cba98bba7..8ea14be74 100644 --- a/Src/CSharpier/DocPrinter/PropagateBreaks.cs +++ b/Src/CSharpier/DocPrinter/PropagateBreaks.cs @@ -2,7 +2,11 @@ namespace CSharpier.DocPrinter; internal static class PropagateBreaks { - private static readonly Doc TraverseDocOnExitStackMarker = new(); + private class MarkerDoc : Doc + { + } + + private static readonly MarkerDoc TraverseDocOnExitStackMarker = new(); public static void RunOn(Doc document) { diff --git a/Src/CSharpier/DocTypes/Doc.cs b/Src/CSharpier/DocTypes/Doc.cs index 357d9a476..b045d7d58 100644 --- a/Src/CSharpier/DocTypes/Doc.cs +++ b/Src/CSharpier/DocTypes/Doc.cs @@ -1,6 +1,6 @@ namespace CSharpier.DocTypes; -internal class Doc +internal abstract class Doc { public static implicit operator Doc(string value) { diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/EnumMemberDeclaration.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/EnumMemberDeclaration.cs index b1fc2a812..e5c3db2f5 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/EnumMemberDeclaration.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/EnumMemberDeclaration.cs @@ -6,6 +6,17 @@ public static Doc Print(EnumMemberDeclarationSyntax node) { var docs = new List { + node.GetLeadingTrivia() + .Any( + o => + o.Kind() + is SyntaxKind.SingleLineCommentTrivia + or SyntaxKind.MultiLineCommentTrivia + or SyntaxKind.SingleLineDocumentationCommentTrivia + or SyntaxKind.MultiLineDocumentationCommentTrivia + ) + ? ExtraNewLines.Print(node) + : Doc.Null, AttributeLists.Print(node, node.AttributeLists), Modifiers.Print(node.Modifiers), Token.Print(node.Identifier)