Skip to content

Commit d896f6c

Browse files
authored
Print designation on list pattern (#877)
closes #876
1 parent fa57850 commit d896f6c

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

Src/CSharpier.Generators/NodePrinterGenerator.sbntxt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace CSharpier.SyntaxPrinter
99
{
1010
internal static class Node
1111
{
12-
public static Doc Print(SyntaxNode syntaxNode, FormattingContext context)
12+
public static Doc Print(SyntaxNode? syntaxNode, FormattingContext context)
1313
{
1414
if (syntaxNode == null)
1515
{

Src/CSharpier.Tests/FormattingTests/TestFiles/cs/ListPatterns.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ var someValue =
1919
var thirdCharacter,
2020
.. var rest
2121
];
22+
23+
return list switch
24+
{
25+
[var elem] => elem * elem,
26+
[] => 0,
27+
[..] elems => elems.Sum(e => e + e),
28+
};

Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/ListPattern.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ public static Doc Print(ListPatternSyntax node, FormattingContext context)
1111
SeparatedSyntaxList.Print(node.Patterns, Node.Print, Doc.Line, context)
1212
),
1313
Doc.SoftLine,
14-
Token.Print(node.CloseBracketToken, context)
14+
Token.Print(node.CloseBracketToken, context),
15+
node.Designation is not null ? " " : Doc.Null,
16+
Node.Print(node.Designation, context)
1517
);
1618
}
1719
}

0 commit comments

Comments
 (0)