Skip to content

Commit

Permalink
Adding test case and tracking the code that caused the problem
Browse files Browse the repository at this point in the history
closes #1130
  • Loading branch information
belav committed Jan 17, 2024
1 parent 7d09173 commit 63b97dc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,9 @@ class ClassName

IEnumerable<ValueProviderFactory> valueProviderFactories =
new ModelBinderAttribute_______().GetValueProviderFactories(config);

var something________________________________________ = x.SomeProperty
.CallMethod(longParameter_____________, longParameter_____________)
.CallMethod();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,14 @@ List<PrintedNode> printedNodes
// will be grouped as
// [
// [Identifier, InvocationExpression],
// [MemberAccessExpression]
// [MemberAccessExpression, InvocationExpression],
// [MemberAccessExpression], [MemberAccessExpression, InvocationExpression],
// [MemberAccessExpression, InvocationExpression],
// [MemberAccessExpression],
// ]

// so that we can print it as
// a()
// .b
// .c()
// .b.c()
// .d()
// .e

Expand All @@ -262,16 +260,45 @@ List<PrintedNode> printedNodes
}
}

if (
printedNodes[0].Node is not (InvocationExpressionSyntax or PostfixUnaryExpressionSyntax)
&& index < printedNodes.Count
&& printedNodes[index].Node
is ElementAccessExpressionSyntax
or PostfixUnaryExpressionSyntax
)
if (printedNodes[0].Node is not InvocationExpressionSyntax)
{
currentGroup.Add(printedNodes[index]);
index++;
for (; index + 1 < printedNodes.Count; ++index)
{
/* this handles the special case where we want ?.Property on the same line
someThing_______________________?.Property
.CallMethod__________________()
.CallMethod__________________();
*/
if (
printedNodes[index].Node is ConditionalAccessExpressionSyntax
&& printedNodes[index + 1].Node
is MemberBindingExpressionSyntax { Parent: MemberAccessExpressionSyntax }
)
{
currentGroup.Add(printedNodes[index]);
currentGroup.Add(printedNodes[index + 1]);
index++;
continue;
}

if (
(
IsMemberish(printedNodes[index].Node)
&& (
IsMemberish(printedNodes[index + 1].Node)
|| printedNodes[index + 1].Node is PostfixUnaryExpressionSyntax
)
)
|| printedNodes[index].Node is PostfixUnaryExpressionSyntax
)
{
currentGroup.Add(printedNodes[index]);
}
else
{
break;
}
}
}

groups.Add(currentGroup);
Expand Down Expand Up @@ -314,6 +341,11 @@ or MemberBindingExpressionSyntax
return groups;
}

private static bool IsMemberish(CSharpSyntaxNode node)
{
return node is MemberAccessExpressionSyntax or ConditionalAccessExpressionSyntax;
}

private static Doc PrintIndentedGroup(ExpressionSyntax node, IList<List<PrintedNode>> groups)
{
if (groups.Count == 0)
Expand Down

0 comments on commit 63b97dc

Please sign in to comment.