Skip to content

Commit

Permalink
Merge pull request #9443 from gafter/patterns-9097
Browse files Browse the repository at this point in the history
Auto-indentation on colon for switches with patterns
  • Loading branch information
gafter committed Mar 3, 2016
2 parents 2e0db2c + 7620427 commit d4e0d61
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private static bool TokenShouldNotFormatOnReturn(SyntaxToken token)
private static bool TokenShouldNotFormatOnTypeChar(SyntaxToken token)
{
return (token.IsKind(SyntaxKind.CloseParenToken) && !token.Parent.IsKind(SyntaxKind.UsingStatement)) ||
(token.IsKind(SyntaxKind.ColonToken) && !(token.Parent.IsKind(SyntaxKind.LabeledStatement) || token.Parent.IsKind(SyntaxKind.CaseSwitchLabel) || token.Parent.IsKind(SyntaxKind.DefaultSwitchLabel)));
(token.IsKind(SyntaxKind.ColonToken) && !(token.Parent.IsKind(SyntaxKind.LabeledStatement) || token.Parent is SwitchLabelSyntax));
}

public async Task<IList<TextChange>> GetFormattingChangesAsync(Document document, char typedChar, int caretPosition, CancellationToken cancellationToken)
Expand Down
84 changes: 84 additions & 0 deletions src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,90 @@ static void Main(string[] args)
await AssertFormatAfterTypeCharAsync(code, expected);
}

[WorkItem(9097, "https://github.com/dotnet/roslyn/issues/9097")]
[WpfFact, Trait(Traits.Feature, Traits.Features.Formatting)]
public async Task ColonInPatternSwitchCase01()
{
var code = @"class Program
{
static void Main()
{
switch(f)
{
case int i :$$ break;
}
}
}";

var expected = @"class Program
{
static void Main()
{
switch(f)
{
case int i: break;
}
}
}";
await AssertFormatAfterTypeCharAsync(code, expected);
}

[WorkItem(9097, "https://github.com/dotnet/roslyn/issues/9097")]
[WpfFact, Trait(Traits.Feature, Traits.Features.Formatting)]
public async Task ColonInPatternSwitchCase02()
{
var code = @"class Program
{
static void Main()
{
switch(f)
{
case Point ( int i , int j ) :$$ break;
}
}
}";

var expected = @"class Program
{
static void Main()
{
switch(f)
{
case Point(int i, int j): break;
}
}
}";
await AssertFormatAfterTypeCharAsync(code, expected);
}

[WorkItem(9097, "https://github.com/dotnet/roslyn/issues/9097")]
[WpfFact, Trait(Traits.Feature, Traits.Features.Formatting)]
public async Task ColonInPatternSwitchCase03()
{
var code = @"class Program
{
static void Main()
{
switch(f)
{
case Point {X is 1,Y is 2} :$$ break;
}
}
}";

var expected = @"class Program
{
static void Main()
{
switch(f)
{
case Point { X is 1, Y is 2 }: break;
}
}
}";
await AssertFormatAfterTypeCharAsync(code, expected);
}

[WorkItem(464, "https://github.com/dotnet/roslyn/issues/464")]
[WorkItem(908729, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")]
[WpfFact, Trait(Traits.Feature, Traits.Features.Formatting)]
Expand Down

0 comments on commit d4e0d61

Please sign in to comment.