Skip to content

Commit

Permalink
Fixing some issues with collection expressions (#1037)
Browse files Browse the repository at this point in the history
closes #1002
closes #1009
  • Loading branch information
belav authored Nov 22, 2023
1 parent d2e6431 commit b12ec2b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Src/CSharpier.Playground/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"commandName": "Executable",
"executablePath": "dotnet",
"comments": "hot reload was not reloading any changes to the csharpier project, just to playground",
"commandLineArgs": "watch run no-hot-reload",
"commandLineArgs": "watch run --no-hot-reload",
"workingDirectory": "$(ProjectDir)",
"launchBrowser": true,
"environmentVariables": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
int[] a = [ 1, 2, 3, 4, 5, 6, 7, 8 ];
List<int> ids = [];

Span<int> b = [ 'a', 'b', 'c', 'd', 'e', 'f', 'h', 'i' ];
int[] a = [1, 2, 3, 4, 5, 6, 7, 8];

Span<int> b = ['a', 'b', 'c', 'd', 'e', 'f', 'h', 'i'];

string[] c =
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ public static Doc Print(CollectionExpressionSyntax node, FormattingContext conte
{
Doc separator = node.Parent
is AssignmentExpressionSyntax
or EqualsValueClauseSyntax { Parent: not PropertyDeclarationSyntax }
or EqualsValueClauseSyntax
{
Parent: not (PropertyDeclarationSyntax or VariableDeclaratorSyntax)
}
? Doc.Line
: Doc.Null;
: Doc.IfBreak(Doc.Line, Doc.Null);

var alwaysBreak =
node.Elements.FirstOrDefault()
Expand All @@ -17,19 +20,21 @@ is AssignmentExpressionSyntax
var result = Doc.Concat(
separator,
Token.Print(node.OpenBracketToken, context),
Doc.Indent(
alwaysBreak ? Doc.HardLine : Doc.Line,
SeparatedSyntaxList.Print(
node.Elements,
Node.Print,
alwaysBreak ? Doc.HardLine : Doc.Line,
context
node.Elements.Any()
? Doc.Indent(
alwaysBreak ? Doc.HardLine : Doc.IfBreak(Doc.Line, Doc.Null),
SeparatedSyntaxList.Print(
node.Elements,
Node.Print,
alwaysBreak ? Doc.HardLine : Doc.Line,
context
)
)
),
: Doc.Null,
node.Elements.Any()
? alwaysBreak
? Doc.HardLine
: Doc.Line
: Doc.IfBreak(Doc.Line, Doc.Null)
: Doc.Null,
Token.Print(node.CloseBracketToken, context)
);
Expand Down

0 comments on commit b12ec2b

Please sign in to comment.