diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/MemberChain_PropertiesConsistent.test b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/MemberChain_PropertiesConsistent.test index a11de94bc..87c72b459 100644 --- a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/MemberChain_PropertiesConsistent.test +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/MemberChain_PropertiesConsistent.test @@ -1,18 +1,18 @@ -var someVariable = - someObject____________.Property_______________.CallMethod______________________(); +var someVariable = someObject____________ + .Property_______________ + .CallMethod______________________(); -var someVariable = someObject.Property.CallMethod(someValue => - someValue.SomeProperty == someOtherValue___________________________ -); +var someVariable = someObject + .Property + .CallMethod(someValue => someValue.SomeProperty == someOtherValue___________________________); var someVariable = someObject .Property() .CallMethod(someValue => someValue.SomeProperty == someOtherValue___________________________); var someVariable = someObject - .Property.CallMethod(someValue => - someValue.SomeProperty == someOtherValue___________________________ - ) + .Property + .CallMethod(someValue => someValue.SomeProperty == someOtherValue___________________________) .CallMethod(); var someVariable = someObject @@ -31,10 +31,8 @@ var someVariable = this.CallMethod() var someVariable = this.Array[1] .CallMethod(someValue => someValue.SomeProperty == someOtherValue___________________________); -var someVariable = this - .Property.CallMethod(someValue => - someValue.SomeProperty == someOtherValue___________________________ - ) +var someVariable = this.Property + .CallMethod(someValue => someValue.SomeProperty == someOtherValue___________________________) .CallMethod(); var someVariable = this.CallMethod() diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/MemberChains.test b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/MemberChains.test index 9581290c8..2c80ecf79 100644 --- a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/MemberChains.test +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/MemberChains.test @@ -48,11 +48,13 @@ var someValue = someOtherValue! .Where(o => someLongCondition__________________________); var someValue = someOtherValue! - .Thing!.Where(o => someLongCondition__________________________) + .Thing! + .Where(o => someLongCondition__________________________) .Where(o => someLongCondition__________________________); var someValue = someOtherValue - .Thing.Where(o => someLongCondition__________________________) + .Thing + .Where(o => someLongCondition__________________________) .Where(o => someLongCondition__________________________); var someValue = someOtherValue @@ -77,7 +79,8 @@ roleNames ); roleNames - .Value.Where(o => o.SomeProperty____________________________________) + .Value + .Where(o => o.SomeProperty____________________________________) .Select(o => o.SomethingElse); return someCondition @@ -105,9 +108,11 @@ CallSomeMethod( someParameter____________________________________ )!; -var someVariable = someObject.Property.CallMethod(someValue => - someValue.SomeProperty == someOtherValue___________________________________ -); +var someVariable = someObject + .Property + .CallMethod(someValue => + someValue.SomeProperty == someOtherValue___________________________________ + ); CallMethod( firstParameter________________________________, @@ -227,41 +232,48 @@ var someValue = CallMethod______________________( .CallMethod__________________(); someThing_______________________ - .Property.CallMethod__________________() + .Property + .CallMethod__________________() .CallMethod__________________(); someThing_______________________ - ?.Property.CallMethod__________________() + ?.Property + .CallMethod__________________() .CallMethod__________________(); someThing_______________________ - .Property!.CallMethod__________________() + .Property! + .CallMethod__________________() .CallMethod__________________(); IEnumerable valueProviderFactories = new ModelBinderAttribute_______().GetValueProviderFactories(config); -var something________________________________________ = x - .SomeProperty.CallMethod(longParameter_____________, longParameter_____________) +var something________________________________________ = x.SomeProperty + .CallMethod(longParameter_____________, longParameter_____________) .CallMethod(); CallMethod(o => - o.Property.CallMethod_____________________________________________________() + o.Property + .CallMethod_____________________________________________________() .CallMethod_____________________________________________________() ); CallMethod( o, - o.Property.CallMethod_____________________________________________________() + o.Property + .CallMethod_____________________________________________________() .CallMethod_____________________________________________________() ); var someValue = someValue - && o.Property.CallMethod_____________________________________________________() + && o.Property + .CallMethod_____________________________________________________() .CallMethod_____________________________________________________(); -o.Property.CallMethod( +o.Property + .CallMethod( someParameter_____________________________, someParameter_____________________________ ) diff --git a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/SpreadElements.test b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/SpreadElements.test index b530ecae1..8d4eb1ecf 100644 --- a/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/SpreadElements.test +++ b/Src/CSharpier.Tests/FormattingTests/TestFiles/cs/SpreadElements.test @@ -11,7 +11,8 @@ int[] someOtherArray = List> list = [ .. attribute - .Targets.Select(target => + .Targets + .Select(target => KeyValuePair.Create( target, context.EntityDefinitions.TryGetValue(target, out var type) ? type.ClassName : null diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs index 11d2092d4..1101c830d 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs @@ -23,9 +23,7 @@ public static Doc PrintMemberChain(ExpressionSyntax node, FormattingContext cont FlattenAndPrintNodes(node, printedNodes, context); - var groups = printedNodes.Any(o => o.Node is InvocationExpressionSyntax) - ? GroupPrintedNodesPrettierStyle(printedNodes) - : GroupPrintedNodesOnLines(printedNodes); + var groups = GroupPrintedNodesOnLines(printedNodes); var oneLine = groups.SelectMany(o => o).Select(o => o.Doc).ToArray(); @@ -248,93 +246,6 @@ or IdentifierNameSyntax return groups; } - private static List> GroupPrintedNodesPrettierStyle( - List printedNodes - ) - { - // We want to group the printed nodes in the following manner - // - // a().b.c().d().e - // will be grouped as - // [ - // [Identifier, InvocationExpression], - // [MemberAccessExpression], [MemberAccessExpression, InvocationExpression], - // [MemberAccessExpression, InvocationExpression], - // [MemberAccessExpression], - // ] - - // so that we can print it as - // a() - // .b.c() - // .d() - // .e - - // TODO #451 this whole thing could possibly just turn into a big loop - // based on the current node, and the next/previous node, decide when to create new groups. - // certain nodes need to stay in the current group, other nodes indicate that a new group needs to be created. - var groups = new List>(); - var currentGroup = new List { printedNodes[0] }; - var index = 1; - for (; index < printedNodes.Count; index++) - { - if (printedNodes[index].Node is InvocationExpressionSyntax) - { - currentGroup.Add(printedNodes[index]); - } - else - { - break; - } - } - - if ( - printedNodes[0].Node is not (InvocationExpressionSyntax or PostfixUnaryExpressionSyntax) - && index < printedNodes.Count - && printedNodes[index].Node - is ElementAccessExpressionSyntax - or PostfixUnaryExpressionSyntax - ) - { - currentGroup.Add(printedNodes[index]); - index++; - } - - groups.Add(currentGroup); - currentGroup = []; - - var hasSeenNodeThatRequiresBreak = false; - for (; index < printedNodes.Count; index++) - { - if ( - hasSeenNodeThatRequiresBreak - && printedNodes[index].Node - is MemberAccessExpressionSyntax - or ConditionalAccessExpressionSyntax - ) - { - groups.Add(currentGroup); - currentGroup = []; - hasSeenNodeThatRequiresBreak = false; - } - - if ( - printedNodes[index].Node - is (InvocationExpressionSyntax or ElementAccessExpressionSyntax) - ) - { - hasSeenNodeThatRequiresBreak = true; - } - currentGroup.Add(printedNodes[index]); - } - - if (currentGroup.Any()) - { - groups.Add(currentGroup); - } - - return groups; - } - private static Doc PrintIndentedGroup(ExpressionSyntax node, IList> groups) { if (groups.Count == 0)