Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving the formatting of lambda's with expression bodies. #331

Merged
merged 1 commit into from
Jun 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,11 @@ public class ClassName

private Func<SomeObjectIn, bool> SomeFieldFunc = (someValue) => true;

private Func<SomeObjectIn, bool> SomeFieldFunc = (someValue) => SometimesBreaksThisWay(
someValue
);
private Func<SomeObjectIn, bool> SomeFieldFunc = (someValue) =>
SometimesBreaksThisWay(someValue);

private Func<SomeObjectIn, bool> SomeFieldFunc = (
someValue
) => OrWhenLongerBreaksThisWay________(someValue);
private Func<SomeObjectIn, bool> SomeFieldFunc = (someValue) =>
OrWhenLongerBreaksThisWay________(someValue);

private Func<SomeObjectIn_________________________, bool> SomeFieldFuncWithALongName_________ =
(someValue) => SomeOtherLongerMethod(someValue);
Expand All @@ -91,17 +89,14 @@ public class ClassName
private Func<
SomeLongObjectIn__________________________________,
bool
> SomeFieldFuncWithALongName = (someValue) => SometimesBreaksThisWay(
someValue,
SomeOtherLongValue
);
> SomeFieldFuncWithALongName = (someValue) =>
SometimesBreaksThisWay(someValue, SomeOtherLongValue);

private Func<
SomeLongObjectIn__________________________________,
bool
> SomeFieldFuncWithALongName = (
someValue_____________________________
) => SometimesBreaksThisWay(someValue, SomeOtherLongValue);
> SomeFieldFuncWithALongName = (someValue_____________________________) =>
SometimesBreaksThisWay(someValue, SomeOtherLongValue);
}

struct S
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ public class ClassName
this.Where(async () => true);
this.Where(static () => true);
this.Where(async static () => true);
this.SomeMethod(
(longParameter__________________, longParameter_________________) =>
longParameter________________
);

this.SomeMethod(
(
a11111111111111111111111111111,
b222222222222222222222222222222
) => someLongNameThatWillDoStuff
longerParameter_________________________,
longerParameter_________________________,
longerParameter_________________________
) => evenLongerParameter
);

var task = Task.Factory.StartNew(
Expand All @@ -29,9 +35,8 @@ public class ClassName
}
);

Action find = () => EntryPointDiscoverer.FindStaticEntryMethod(
typeof(IEnumerable<>).Assembly
);
Action find = () =>
EntryPointDiscoverer.FindStaticEntryMethod(typeof(IEnumerable<>).Assembly);

var @delegate = (Action<string>)((s) => { });

Expand All @@ -53,5 +58,15 @@ public class ClassName
}
)
};

CallSomeMethod(
() =>
CallAnotherMethodWithParameters(
someParameter,
someParameter___________________________________
)
> someValue,
anotherParameter
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ class ClassName
var captureUnmatchedValuesParameters______________________________ =
new List<IPropertySymbol>();

Func<SyntaxTrivia, bool> s_isVisualBasicCommentTrivia = (syntaxTrivia) =>
syntaxTrivia.IsKind(VisualBasic.SyntaxKind.CommentTrivia);

Func<SyntaxTrivia, bool> s_isVisualBasicCommentTrivia = (
syntaxTrivia
syntaxTrivia_________________________________
) => syntaxTrivia.IsKind(VisualBasic.SyntaxKind.CommentTrivia);

Action find = () => EntryPointDiscoverer.FindStaticEntryMethod(
typeof(IEnumerable<>).Assembly
);
Action find = () =>
EntryPointDiscoverer.FindStaticEntryMethod(typeof(IEnumerable<>).Assembly);

Action find = () =>
EntryPointDiscoverer.FindStaticEntryMethod(
typeof(IEnumerable<>).Assembly_________________________________________
);

var arrayCreationExpression1 = new byte[100];
var arrayCreationExpression2 = new byte[
Expand Down
10 changes: 6 additions & 4 deletions Src/CSharpier/SyntaxPrinter/ArgumentListLikeSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ SyntaxToken closeParenToken
Doc.Concat(
Token.Print(openParenToken),
arguments.Any()
? Doc.Indent(
Doc.SoftLine,
SeparatedSyntaxList.Print(arguments, Argument.Print, Doc.Line)
? Doc.Concat(
Doc.Indent(
Doc.SoftLine,
SeparatedSyntaxList.Print(arguments, Argument.Print, Doc.Line)
),
Doc.SoftLine
)
: Doc.Null,
arguments.Any() ? Doc.SoftLine : Doc.Null,
Token.Print(closeParenToken)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ public static Doc Print(ParenthesizedLambdaExpressionSyntax node)
Modifiers.Print(node.Modifiers),
ParameterList.Print(node.ParameterList),
" ",
Token.PrintWithSuffix(
node.ArrowToken,
node.Block
is not null
and { Statements: { Count: > 0 } } ? Doc.HardLine : " "
)
Token.Print(node.ArrowToken)
};
if (node.ExpressionBody != null)
{
docs.Add(Node.Print(node.ExpressionBody));
docs.Add(Doc.Group(Doc.Indent(Doc.Line, Node.Print(node.ExpressionBody))));
}
else if (node.Block != null)
{
if (node.Block.Statements.Count > 0)
{
docs.Add(Doc.HardLine);
}
else
{
docs.Add(" ");
}

docs.Add(Block.Print(node.Block));
}

Expand Down