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 lines above comments in enums #525

Merged
merged 1 commit into from
Dec 21, 2021
Merged
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
@@ -0,0 +1,15 @@
public enum SubCode
{
First,

// keep line
BasicComment,

/* keep line */
MultiLineComment,

/// keep line
XmlComment,

DoNotKeepLine
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public enum SubCode
{
First,

// keep line
BasicComment,

/* keep line */
MultiLineComment,

/// keep line
XmlComment,
DoNotKeepLine
}
6 changes: 5 additions & 1 deletion Src/CSharpier/DocPrinter/PropagateBreaks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier/DocTypes/Doc.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CSharpier.DocTypes;

internal class Doc
internal abstract class Doc
{
public static implicit operator Doc(string value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ public static Doc Print(EnumMemberDeclarationSyntax node)
{
var docs = new List<Doc>
{
node.GetLeadingTrivia()
.Any(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On an unrelated note, you reckon there should be an indent here? Since it's the start of a method chain?

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)
Expand Down