Skip to content

Commit

Permalink
Improving the formatting of lambda's with expression bodies. (#331)
Browse files Browse the repository at this point in the history
closes #176
  • Loading branch information
belav authored Jun 26, 2021
1 parent 29a8d58 commit fbebb34
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 34 deletions.
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

0 comments on commit fbebb34

Please sign in to comment.