Skip to content

Commit

Permalink
Tweak formatting engine to ignore elastic trivia for local functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Feb 15, 2018
1 parent 22058f1 commit 436817b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,59 @@ void Goo()
}");
}

[WorkItem(23872, "https://github.com/dotnet/roslyn/issues/23872")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseLocalFunction)]
public async Task TestSimpleInitialization_SingleLine4()
{
await TestInRegularAndScriptAsync(
@"using System;
class C
{
void Goo()
{
Func<int, int[]> [||]onUpdateSolutionCancel = x => { return null; };
}
}",
@"using System;
class C
{
void Goo()
{
int[] onUpdateSolutionCancel(int x) { return null; }
}
}");
}

[WorkItem(23872, "https://github.com/dotnet/roslyn/issues/23872")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseLocalFunction)]
public async Task TestSimpleInitialization_SingleLine5()
{

await TestInRegularAndScriptAsync(
@"using System;
using System.Threading.Tasks;
class C
{
void Goo()
{
Func<int, Task<int[]>> [||]onUpdateSolutionCancel = async x => { return null; };
}
}",
@"using System;
using System.Threading.Tasks;
class C
{
void Goo()
{
async Task<int[]> onUpdateSolutionCancel(int x) { return null; }
}
}");
}

[WorkItem(23872, "https://github.com/dotnet/roslyn/issues/23872")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseLocalFunction)]
public async Task TestCastInitialization_SingleLine1()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,7 @@ private LocalFunctionStatementSyntax CreateLocalFunctionStatement(

var invokeMethod = delegateType.DelegateInvokeMethod;

// The presence of elastic trivia in the return type will cause the formatting engine
// to wrap a local function that could stay on a single line. Remove all the elastic
// trivia added by default to get good behavior for both single line and multiline
// lambdas.
var returnType = RemoveAllElasticTrivia(invokeMethod.GenerateReturnTypeSyntax());
var returnType = invokeMethod.GenerateReturnTypeSyntax();

var identifier = localDeclaration.Declaration.Variables[0].Identifier;
var typeParameterList = default(TypeParameterListSyntax);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ private void AddSpecificNodesSuppressOperations(List<SuppressOperation> list, Sy
if (node is AnonymousFunctionExpressionSyntax ||
node is LocalFunctionStatementSyntax)
{
AddSuppressWrappingIfOnSingleLineOperation(
list, node.GetFirstToken(includeZeroWidth: true), node.GetLastToken(includeZeroWidth: true));
AddSuppressWrappingIfOnSingleLineOperation(list,
node.GetFirstToken(includeZeroWidth: true),
node.GetLastToken(includeZeroWidth: true),
SuppressOption.IgnoreElastic);
return;
}

Expand Down

0 comments on commit 436817b

Please sign in to comment.