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

Auto-indentation on colon for switches with patterns #9443

Merged
merged 1 commit into from
Mar 3, 2016
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 @@ -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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh, should have caught that when I fixed the other switch issues 😦

}

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