From 214249e7fb898944d259c59fcd01545f41508185 Mon Sep 17 00:00:00 2001 From: Divyansh Shukla Date: Fri, 11 Jun 2021 02:34:10 +0200 Subject: [PATCH 1/8] Better print generic methods --- .../ClassDeclaration/ClassDeclarations.cst | 6 +-- .../ConstructorDeclarations.cst | 17 ++++++-- .../DelegateDeclarations.cst | 3 +- .../ObnoxiousEdgeCases/ObnoxiousEdgeCases.cst | 3 +- .../TypeParameterConstraintClauses.cst | 27 +++++++------ .../SyntaxPrinter/ConstraintClauses.cs | 39 ++++++++++++++----- .../BaseMethodDeclaration.cs | 2 + .../ConstructorInitializer.cs | 4 +- 8 files changed, 66 insertions(+), 35 deletions(-) diff --git a/Src/CSharpier.Tests/TestFiles/ClassDeclaration/ClassDeclarations.cst b/Src/CSharpier.Tests/TestFiles/ClassDeclaration/ClassDeclarations.cst index d043add19..f34f0ae34 100644 --- a/Src/CSharpier.Tests/TestFiles/ClassDeclaration/ClassDeclarations.cst +++ b/Src/CSharpier.Tests/TestFiles/ClassDeclaration/ClassDeclarations.cst @@ -14,8 +14,7 @@ public class ThisIsSomeLongNameAndItShouldFormatWell1 AndYetAnotherLongClassName, AndStillOneMore { } -public class SimpleGeneric - where T : new() { } +public class SimpleGeneric where T : new() { } public class LongTypeConstraints where T : SomeLongNameThatJustKeepsGoing, @@ -33,8 +32,7 @@ public class LongerClassNameWithLotsOfGenerics< TThirdLongName__________________ > : SomeBaseClass { } -public class SimpleGeneric : BaseClass - where T : new() { } +public class SimpleGeneric : BaseClass where T : new() { } public class ThisIsSomeLongNameAndItShouldFormatWell2 : AnotherLongClassName, diff --git a/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst b/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst index 17071289f..e86420d75 100644 --- a/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst +++ b/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst @@ -22,11 +22,20 @@ public class BasicClass public class Initializers : BasicClass { - public Initializers() - : this(true) { } + public Initializers() : this(true) { } - public Initializers(string value) - : base(value) { } + public Initializers(string value) : base(value) { } + + public Initializers( + string parameter1, + string parameter2, + string parameter3, + string parameter4 + ) : base(false) + { + _parameter1 = parameter1; + _parameter2 = parameter2; + } } public class Exactly80 diff --git a/Src/CSharpier.Tests/TestFiles/DelegateDeclaration/DelegateDeclarations.cst b/Src/CSharpier.Tests/TestFiles/DelegateDeclaration/DelegateDeclarations.cst index 87948bd2f..333276b1a 100644 --- a/Src/CSharpier.Tests/TestFiles/DelegateDeclaration/DelegateDeclarations.cst +++ b/Src/CSharpier.Tests/TestFiles/DelegateDeclaration/DelegateDeclarations.cst @@ -2,6 +2,5 @@ class ClassName { delegate void Delegate(); - delegate void Delegate<[System.Obsolete()] out T>() - where T : struct; + delegate void Delegate<[System.Obsolete()] out T>() where T : struct; } diff --git a/Src/CSharpier.Tests/TestFiles/ObnoxiousEdgeCases/ObnoxiousEdgeCases.cst b/Src/CSharpier.Tests/TestFiles/ObnoxiousEdgeCases/ObnoxiousEdgeCases.cst index d17723b8f..c3851d5e9 100644 --- a/Src/CSharpier.Tests/TestFiles/ObnoxiousEdgeCases/ObnoxiousEdgeCases.cst +++ b/Src/CSharpier.Tests/TestFiles/ObnoxiousEdgeCases/ObnoxiousEdgeCases.cst @@ -60,8 +60,7 @@ class ClassName DynamicallyAccessedMemberTypes.PublicConstructors)] TAccountClaimsPrincipalFactory>( this IRemoteAuthenticationBuilder builder - ) - where TAccountClaimsPrincipalFactory : AccountClaimsPrincipalFactory => + ) where TAccountClaimsPrincipalFactory : AccountClaimsPrincipalFactory => builder.AddAccountClaimsPrincipalFactory< RemoteAuthenticationState, RemoteUserAccount, diff --git a/Src/CSharpier.Tests/TestFiles/TypeParameterConstraintClause/TypeParameterConstraintClauses.cst b/Src/CSharpier.Tests/TestFiles/TypeParameterConstraintClause/TypeParameterConstraintClauses.cst index b750bd8ff..724186fa3 100644 --- a/Src/CSharpier.Tests/TestFiles/TypeParameterConstraintClause/TypeParameterConstraintClauses.cst +++ b/Src/CSharpier.Tests/TestFiles/TypeParameterConstraintClause/TypeParameterConstraintClauses.cst @@ -1,25 +1,28 @@ -delegate void Delegate() - where T : struct; +delegate void Delegate() where T : struct; -class ClassName - where T : class +class ClassName where T : class { - void MethodName() - where T : class + void MethodName() where T : class { - void LocalFunction() - where T : class + void LocalFunction() where T : class { return; } } + + public static ReturnType MethodName( + string parameter1, + string parameter2 + ) where T : class + where U : class + { + return; + } } -interface InterfaceName - where T : class { } +interface InterfaceName where T : class { } -struct Struct - where T : class { } +struct Struct where T : class { } class ClassName where N : new() diff --git a/Src/CSharpier/SyntaxPrinter/ConstraintClauses.cs b/Src/CSharpier/SyntaxPrinter/ConstraintClauses.cs index 367808353..9fe9e9ad5 100644 --- a/Src/CSharpier/SyntaxPrinter/ConstraintClauses.cs +++ b/Src/CSharpier/SyntaxPrinter/ConstraintClauses.cs @@ -16,19 +16,40 @@ public static Doc Print(IEnumerable constra { return Doc.Null; } + else if (constraintClausesList.Count == 1) + { + return Doc.Group( + Doc.Indent( + Doc.Line, + Doc.Join( + Doc.Line, + constraintClausesList.Select(TypeParameterConstraintClause.Print) + ) + ) + ); + } - var docs = new List + if (constraintClausesList[0].Parent is MethodDeclarationSyntax) { - Doc.Indent( - Doc.HardLine, - Doc.Join( - Doc.HardLine, - constraintClausesList.Select(TypeParameterConstraintClause.Print) + return Doc.Concat( + " ", + Doc.Align( + 2, + Doc.Join( + Doc.HardLine, + constraintClausesList.Select(TypeParameterConstraintClause.Print) + ) ) - ) - }; + ); + } - return Doc.Concat(docs); + return Doc.Indent( + Doc.HardLine, + Doc.Join( + Doc.HardLine, + constraintClausesList.Select(TypeParameterConstraintClause.Print) + ) + ); } } } diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs index 9027ecec4..5b7f95039 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs @@ -168,6 +168,8 @@ public static Doc Print(CSharpSyntaxNode node) { docs.Add( groupId != null + && constraintClauses.Count() < 2 + && constructorInitializer == null ? Block.PrintWithConditionalSpace(body, groupId) : Block.Print(body) ); diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs index 121f0e929..08d1a6b9b 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs @@ -8,8 +8,8 @@ public static class ConstructorInitializer { public static Doc Print(ConstructorInitializerSyntax node) { - return Doc.Indent( - Doc.HardLine, + return Doc.Concat( + " ", Token.PrintWithSuffix(node.ColonToken, " "), Token.Print(node.ThisOrBaseKeyword), ArgumentList.Print(node.ArgumentList) From ea719268017ad77214741f1297b978ad7892ea79 Mon Sep 17 00:00:00 2001 From: Divyansh Shukla Date: Fri, 11 Jun 2021 14:17:19 +0200 Subject: [PATCH 2/8] Update tests --- .../ConstructorDeclarations.cst | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst b/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst index e86420d75..c74a662d6 100644 --- a/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst +++ b/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst @@ -27,15 +27,18 @@ public class Initializers : BasicClass public Initializers(string value) : base(value) { } public Initializers( - string parameter1, - string parameter2, - string parameter3, - string parameter4 - ) : base(false) - { - _parameter1 = parameter1; - _parameter2 = parameter2; - } + string reallyLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongParameter + ) : base( + reallyLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongParameterIMeanIt + ) { } + + public Initializers( + string reallyLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongParameter + ) : base(false) { } + + public ReallyLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogMethodName() : base( + false + ) { } } public class Exactly80 From f78a66fc31862e078fc443eddb98ac68edb486f7 Mon Sep 17 00:00:00 2001 From: Divyansh Shukla Date: Sat, 12 Jun 2021 00:22:10 +0200 Subject: [PATCH 3/8] Update rules --- .../ConstructorDeclarations.cst | 5 ++--- .../SyntaxNodePrinters/BaseMethodDeclaration.cs | 9 ++++++++- .../ConstructorInitializer.cs | 17 ++++++++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst b/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst index c74a662d6..d4941d2c7 100644 --- a/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst +++ b/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst @@ -36,9 +36,8 @@ public class Initializers : BasicClass string reallyLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongParameter ) : base(false) { } - public ReallyLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogMethodName() : base( - false - ) { } + public ReallyLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogMethodName() + : base(false) { } } public class Exactly80 diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs index 5b7f95039..78ddae8b7 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs @@ -149,7 +149,14 @@ public static Doc Print(CSharpSyntaxNode node) if (constructorInitializer != null) { - declarationGroup.Add(ConstructorInitializer.Print(constructorInitializer)); + declarationGroup.Add( + groupId != null + ? ConstructorInitializer.PrintWithConditionalSpace( + constructorInitializer, + groupId + ) + : ConstructorInitializer.Print(constructorInitializer) + ); } if (modifiers.HasValue && modifiers.Value.Count > 0) diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs index 08d1a6b9b..bd8d7589f 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs @@ -1,15 +1,26 @@ using CSharpier.DocTypes; -using CSharpier.SyntaxPrinter; using Microsoft.CodeAnalysis.CSharp.Syntax; namespace CSharpier.SyntaxPrinter.SyntaxNodePrinters { public static class ConstructorInitializer { + public static Doc PrintWithConditionalSpace( + ConstructorInitializerSyntax node, + string groupId + ) { + return Print(node, groupId); + } + public static Doc Print(ConstructorInitializerSyntax node) { - return Doc.Concat( - " ", + return Print(node, null); + } + + private static Doc Print(ConstructorInitializerSyntax node, string? groupId) + { + return Doc.Group( + Doc.Indent(groupId != null ? Doc.IfBreak(" ", Doc.Line, groupId) : Doc.Line), Token.PrintWithSuffix(node.ColonToken, " "), Token.Print(node.ThisOrBaseKeyword), ArgumentList.Print(node.ArgumentList) From d8de71fc44d74bde492f93d723ad8a28114d7efe Mon Sep 17 00:00:00 2001 From: Divyansh Shukla Date: Sat, 12 Jun 2021 00:53:35 +0200 Subject: [PATCH 4/8] Update more rules --- .../ConstructorDeclaration/ConstructorDeclarations.cst | 5 +++++ .../SyntaxNodePrinters/ConstructorInitializer.cs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst b/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst index d4941d2c7..75dd24466 100644 --- a/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst +++ b/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst @@ -38,6 +38,11 @@ public class Initializers : BasicClass public ReallyLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogMethodName() : base(false) { } + + public ReallyLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogMethodName() + : base( + reallyLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongParameterIMeanIt + ) { } } public class Exactly80 diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs index bd8d7589f..6c43037d8 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs @@ -23,7 +23,7 @@ private static Doc Print(ConstructorInitializerSyntax node, string? groupId) Doc.Indent(groupId != null ? Doc.IfBreak(" ", Doc.Line, groupId) : Doc.Line), Token.PrintWithSuffix(node.ColonToken, " "), Token.Print(node.ThisOrBaseKeyword), - ArgumentList.Print(node.ArgumentList) + groupId != null ? ArgumentList.Print(node.ArgumentList) : Doc.Indent(ArgumentList.Print(node.ArgumentList)) ); } } From 6a1defde3d794d198b9997afb3ea4112cb1e9422 Mon Sep 17 00:00:00 2001 From: Divyansh Shukla Date: Sat, 12 Jun 2021 01:02:25 +0200 Subject: [PATCH 5/8] Update formatting --- .../SyntaxNodePrinters/ConstructorInitializer.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs index 6c43037d8..45fa0f76c 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs @@ -23,7 +23,9 @@ private static Doc Print(ConstructorInitializerSyntax node, string? groupId) Doc.Indent(groupId != null ? Doc.IfBreak(" ", Doc.Line, groupId) : Doc.Line), Token.PrintWithSuffix(node.ColonToken, " "), Token.Print(node.ThisOrBaseKeyword), - groupId != null ? ArgumentList.Print(node.ArgumentList) : Doc.Indent(ArgumentList.Print(node.ArgumentList)) + groupId != null + ? ArgumentList.Print(node.ArgumentList) + : Doc.Indent(ArgumentList.Print(node.ArgumentList)) ); } } From f34bce04d0b80d9f9c6071b79bb3e0cee0409649 Mon Sep 17 00:00:00 2001 From: Divyansh Shukla Date: Sat, 12 Jun 2021 12:21:55 +0200 Subject: [PATCH 6/8] Update rules again --- .../TypeParameterConstraintClauses.cst | 16 ++++-- .../SyntaxPrinter/ConstraintClauses.cs | 56 ++++++++----------- .../BaseMethodDeclaration.cs | 6 +- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Src/CSharpier.Tests/TestFiles/TypeParameterConstraintClause/TypeParameterConstraintClauses.cst b/Src/CSharpier.Tests/TestFiles/TypeParameterConstraintClause/TypeParameterConstraintClauses.cst index 724186fa3..c51401acb 100644 --- a/Src/CSharpier.Tests/TestFiles/TypeParameterConstraintClause/TypeParameterConstraintClauses.cst +++ b/Src/CSharpier.Tests/TestFiles/TypeParameterConstraintClause/TypeParameterConstraintClauses.cst @@ -10,14 +10,18 @@ class ClassName where T : class } } + public static ReturnType MethodName() + where T : class + where U : class { } + + public static ReturnType MethodName(string parameter) + where T : class + where U : class { } + public static ReturnType MethodName( - string parameter1, - string parameter2 + string reallyLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongParameterIMeanIt ) where T : class - where U : class - { - return; - } + where U : class { } } interface InterfaceName where T : class { } diff --git a/Src/CSharpier/SyntaxPrinter/ConstraintClauses.cs b/Src/CSharpier/SyntaxPrinter/ConstraintClauses.cs index 9fe9e9ad5..a14267bd0 100644 --- a/Src/CSharpier/SyntaxPrinter/ConstraintClauses.cs +++ b/Src/CSharpier/SyntaxPrinter/ConstraintClauses.cs @@ -8,47 +8,39 @@ namespace CSharpier.SyntaxPrinter { public static class ConstraintClauses { + public static Doc PrintWithConditionalSpace( + IEnumerable constraintClauses, + string groupId + ) { + return Print(constraintClauses, groupId); + } + public static Doc Print(IEnumerable constraintClauses) { + return Print(constraintClauses, null); + } + + private static Doc Print( + IEnumerable constraintClauses, + string? groupId + ) { var constraintClausesList = constraintClauses.ToList(); if (constraintClausesList.Count == 0) { return Doc.Null; } - else if (constraintClausesList.Count == 1) - { - return Doc.Group( - Doc.Indent( - Doc.Line, - Doc.Join( - Doc.Line, - constraintClausesList.Select(TypeParameterConstraintClause.Print) - ) - ) - ); - } - - if (constraintClausesList[0].Parent is MethodDeclarationSyntax) - { - return Doc.Concat( - " ", - Doc.Align( - 2, - Doc.Join( - Doc.HardLine, - constraintClausesList.Select(TypeParameterConstraintClause.Print) - ) - ) - ); - } - - return Doc.Indent( + var prefix = constraintClausesList.Count >= 2 ? Doc.HardLine : Doc.Line; + var body = Doc.Join( Doc.HardLine, - Doc.Join( - Doc.HardLine, - constraintClausesList.Select(TypeParameterConstraintClause.Print) - ) + constraintClausesList.Select(TypeParameterConstraintClause.Print) + ); + + return Doc.Group( + Doc.Indent(groupId != null ? Doc.IfBreak(" ", prefix, groupId) : prefix), + groupId != null + ? Doc.IfBreak(Doc.Align(2, body), Doc.Indent(body), groupId) + : Doc.Indent(body) ); } } diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs index 78ddae8b7..fd1ba3a91 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs @@ -170,7 +170,11 @@ public static Doc Print(CSharpSyntaxNode node) docs.Add(Doc.Group(declarationGroup)); - docs.Add(ConstraintClauses.Print(constraintClauses)); + docs.Add( + groupId != null + ? ConstraintClauses.PrintWithConditionalSpace(constraintClauses, groupId) + : ConstraintClauses.Print(constraintClauses) + ); if (body != null) { docs.Add( From ed2c5650f39fcad1a5e08f8b94cd998c70b56109 Mon Sep 17 00:00:00 2001 From: Divyansh Shukla Date: Sat, 12 Jun 2021 12:23:22 +0200 Subject: [PATCH 7/8] Simplify logic --- .../SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs index fd1ba3a91..074d7552a 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BaseMethodDeclaration.cs @@ -179,8 +179,6 @@ public static Doc Print(CSharpSyntaxNode node) { docs.Add( groupId != null - && constraintClauses.Count() < 2 - && constructorInitializer == null ? Block.PrintWithConditionalSpace(body, groupId) : Block.Print(body) ); From b5cd65a638048183ea3f2d6d35033e4738a24030 Mon Sep 17 00:00:00 2001 From: Divyansh Shukla Date: Sat, 12 Jun 2021 15:26:42 +0200 Subject: [PATCH 8/8] Fix comment handling --- .../ConstructorDeclaration/ConstructorDeclarations.cst | 8 ++++++++ .../SyntaxNodePrinters/ConstructorInitializer.cs | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst b/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst index 75dd24466..43b884916 100644 --- a/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst +++ b/Src/CSharpier.Tests/TestFiles/ConstructorDeclaration/ConstructorDeclarations.cst @@ -43,6 +43,14 @@ public class Initializers : BasicClass : base( reallyLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongParameterIMeanIt ) { } + + public Initializers( + string value + ) /*Comment*/ + : base(value) { } + + public ReallyLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogMethodName() + /*Comment*/: base(false) { } } public class Exactly80 diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs index 45fa0f76c..641bc3d69 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ConstructorInitializer.cs @@ -19,9 +19,12 @@ public static Doc Print(ConstructorInitializerSyntax node) private static Doc Print(ConstructorInitializerSyntax node, string? groupId) { + var colonToken = Token.PrintWithSuffix(node.ColonToken, " "); return Doc.Group( Doc.Indent(groupId != null ? Doc.IfBreak(" ", Doc.Line, groupId) : Doc.Line), - Token.PrintWithSuffix(node.ColonToken, " "), + groupId != null + ? Doc.IfBreak(Doc.Align(2, colonToken), Doc.Indent(colonToken), groupId) + : Doc.Indent(colonToken), Token.Print(node.ThisOrBaseKeyword), groupId != null ? ArgumentList.Print(node.ArgumentList)