Skip to content

Commit

Permalink
Fixing a number of bugs with collection expressions
Browse files Browse the repository at this point in the history
closes #1049
closes #1047
  • Loading branch information
belav committed Dec 1, 2023
1 parent e705d9a commit 0d78c25
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,55 @@ int[][] d =
[4, 5, 6],
[7, 8, 9]
];

var a = new A { B = [1, 2, 3] };

List<string> items =
[
// My item
"Hello",
];

items.AddRange(
[
"More really long words",
"which span multiple lines",
"are added here",
"and something bad",
"happens"
]
);

class MyClass
{
private readonly List<string> _items;

public MyClass()
{
_items = [];
_items ??= [];
}

public TheoryData<string[]> ArgsData =>
[
[],
[ArgConstants.UseProgramMain],
[ArgConstants.GlobalInteractivity, ArgConstants.WebAssemblyInteractivity],
[
ArgConstants.NoInteractivity,
ArgConstants.UseProgramMain,
ArgConstants.NoHttps,
ArgConstants.Empty
],
];

public ReadOnlySpan<HttpMethod> Methods() =>
[
HttpMethod.None,
HttpMethod.Put,
HttpMethod.Post,
HttpMethod.Patch,
HttpMethod.None,
HttpMethod.Connect,
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ internal static class CollectionExpression
public static Doc Print(CollectionExpressionSyntax node, FormattingContext context)
{
Doc separator = node.Parent
is AssignmentExpressionSyntax
is ArgumentSyntax
or ArrowExpressionClauseSyntax
or ExpressionElementSyntax
or AssignmentExpressionSyntax { Parent: not ObjectCreationExpressionSyntax }
or EqualsValueClauseSyntax
{
Parent: not (PropertyDeclarationSyntax or VariableDeclaratorSyntax)
}
? Doc.Line
? Doc.Null
: Doc.IfBreak(Doc.Line, Doc.Null);

var alwaysBreak =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace CSharpier.SyntaxPrinter.SyntaxNodePrinters;

internal static class ExpressionElement
{
public static Doc Print(ExpressionElementSyntax node, FormattingContext context)
{
return Node.Print(node.Expression, context);
}
}

0 comments on commit 0d78c25

Please sign in to comment.