From 1bf1b64cbbc5e70fe46de4aa2e18ec3885003825 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Tue, 2 Apr 2019 23:03:40 +0200 Subject: [PATCH 1/2] Format `{}` property pattern (#34619) --- .../AutomaticBraceCompletionTests.cs | 6 +- .../Rules/TokenBasedFormattingRule.cs | 8 ++ .../CSharpTest/Formatting/FormattingTests.cs | 101 ++++++++++++++++-- 3 files changed, 104 insertions(+), 11 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticBraceCompletionTests.cs b/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticBraceCompletionTests.cs index 2885a9dd05e8..638e3f3c6ca1 100644 --- a/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticBraceCompletionTests.cs +++ b/src/EditorFeatures/CSharpTest/AutomaticCompletion/AutomaticBraceCompletionTests.cs @@ -388,7 +388,7 @@ class C { void M() { - _ = this is { } + _ = this is {} } }"; @@ -431,7 +431,7 @@ class C { void M() { - _ = this is { } + _ = this is {} M(); } }"; @@ -476,7 +476,7 @@ class C { void M() { - _ = this is (1, 2) { } + _ = this is (1, 2) {} M(); } }"; diff --git a/src/Workspaces/CSharp/Portable/Formatting/Rules/TokenBasedFormattingRule.cs b/src/Workspaces/CSharp/Portable/Formatting/Rules/TokenBasedFormattingRule.cs index 9cbe3b6fbc8b..1c9fb66e5cbf 100644 --- a/src/Workspaces/CSharp/Portable/Formatting/Rules/TokenBasedFormattingRule.cs +++ b/src/Workspaces/CSharp/Portable/Formatting/Rules/TokenBasedFormattingRule.cs @@ -257,6 +257,14 @@ public override AdjustSpacesOperation GetAdjustSpacesOperation(SyntaxToken previ return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine); } + // empty {} in pattern + if (previousToken.Kind() == SyntaxKind.OpenBraceToken && + currentToken.Kind() == SyntaxKind.CloseBraceToken && + currentToken.Parent.IsKind(SyntaxKindEx.PropertyPatternClause)) + { + return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine); + } + // attribute case // , [ if (previousToken.Kind() == SyntaxKind.CommaToken && currentToken.Kind() == SyntaxKind.OpenBracketToken && currentToken.Parent is AttributeListSyntax) diff --git a/src/Workspaces/CSharpTest/Formatting/FormattingTests.cs b/src/Workspaces/CSharpTest/Formatting/FormattingTests.cs index 5dff817509dc..a8416263d3ae 100644 --- a/src/Workspaces/CSharpTest/Formatting/FormattingTests.cs +++ b/src/Workspaces/CSharpTest/Formatting/FormattingTests.cs @@ -5142,7 +5142,7 @@ void M() { { void M() { - _ = this is C(1, 2) { }; + _ = this is C(1, 2) {}; } }"; // no space separates the type and the positional pattern @@ -5165,7 +5165,7 @@ void M() { { void M() { - _ = this is C (1, 2) { }; + _ = this is C (1, 2) {}; } }"; await AssertFormatAsync(expectedCode, code, changedOptionSet: changingOptions); @@ -5188,8 +5188,8 @@ void M() { { void M() { - _ = this is C( 1, 2 ) { }; - _ = this is C() { }; + _ = this is C( 1, 2 ) {}; + _ = this is C() {}; } }"; await AssertFormatAsync(expectedCode, code, changedOptionSet: changingOptions); @@ -5212,8 +5212,8 @@ void M() { { void M() { - _ = this is C(1, 2) { }; - _ = this is C( ) { }; + _ = this is C(1, 2) {}; + _ = this is C( ) {}; } }"; await AssertFormatAsync(expectedCode, code, changedOptionSet: changingOptions); @@ -5290,7 +5290,7 @@ void M() { { void M() { - _ = this is { } + _ = this is {} M(); } }"; @@ -5313,7 +5313,7 @@ void M() { { void M() { - _ = this is (1, 2) { } + _ = this is (1, 2) {} M(); } }"; @@ -9069,6 +9069,91 @@ public void Foo() }"); } + [Fact, Trait(Traits.Feature, Traits.Features.Formatting)] + public async Task EmptyIsPropertyPattern() + { + var code = @" +class C +{ + void M() + { + _ = x is { } + } +} +"; + var expected = @" +class C +{ + void M() + { + _ = x is {} + } +} +"; + + await AssertFormatAsync(expected, code); + } + + [Fact, Trait(Traits.Feature, Traits.Features.Formatting)] + public async Task EmptySwitchCasePropertyPattern() + { + var code = @" +class C +{ + void M() + { + switch (x) + { + case { } + } + } +} +"; + var expected = @" +class C +{ + void M() + { + switch (x) + { + case {} + } + } +} +"; + + await AssertFormatAsync(expected, code); + } + + [Fact, Trait(Traits.Feature, Traits.Features.Formatting)] + public async Task EmptySwitchExpressionCasePropertyPattern() + { + var code = @" +class C +{ + void M() + { + _ = x switch + { + { } => + } +} +"; + var expected = @" +class C +{ + void M() + { + _ = x switch + { + {} => + } +} +"; + + await AssertFormatAsync(expected, code); + } + [Theory, Trait(Traits.Feature, Traits.Features.Formatting)] [WorkItem(31571, "https://github.com/dotnet/roslyn/issues/31571")] [WorkItem(33910, "https://github.com/dotnet/roslyn/issues/33910")] From f78e51726ab21cf7958aa81bc250f3bfd7fdbae7 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Tue, 2 Apr 2019 23:49:35 +0200 Subject: [PATCH 2/2] Update Language Feature Status.md (#34680) --- docs/Language Feature Status.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/Language Feature Status.md b/docs/Language Feature Status.md index 03fb96c09c8d..c1c2f8be1867 100644 --- a/docs/Language Feature Status.md +++ b/docs/Language Feature Status.md @@ -10,7 +10,7 @@ efforts behind them. | Feature | Branch | State | Developers | Reviewer | LDM Champ | | ------- | ------ | ----- | ---------- | -------- | --------- | -| [Default Interface Methods](https://github.com/dotnet/csharplang/blob/master/proposals/default-interface-methods.md) | [defaultInterfaceImplementation](https://github.com/dotnet/roslyn/tree/features/DefaultInterfaceImplementation) | [Prototype](https://github.com/dotnet/roslyn/issues/19217) | [AlekseyTs](https://github.com/AlekseyTs) | [gafter](https://github.com/gafter) | [gafter](https://github.com/gafter) | +| [Default Interface Methods](https://github.com/dotnet/csharplang/blob/master/proposals/default-interface-methods.md) | [defaultInterfaceImplementation](https://github.com/dotnet/roslyn/tree/features/DefaultInterfaceImplementation) | [Merged to dev16.1 preview2](https://github.com/dotnet/roslyn/issues/19217) | [AlekseyTs](https://github.com/AlekseyTs) | [gafter](https://github.com/gafter) | [gafter](https://github.com/gafter) | | [Nullable reference type](https://github.com/dotnet/csharplang/blob/master/proposals/nullable-reference-types.md) | [NullableReferenceTypes](https://github.com/dotnet/roslyn/tree/features/NullableReferenceTypes) | [Merged to dev16.0 preview1](https://github.com/dotnet/roslyn/issues/22152) | [cston](https://github.com/cston), [jcouv](https://github.com/jcouv) | [AlekseyTs](https://github.com/AlekseyTs), [333fred](https://github.com/333fred) | [mattwar](https://github.com/mattwar) | | [Recursive patterns](https://github.com/dotnet/csharplang/blob/master/proposals/patterns.md) | [recursive-patterns](https://github.com/dotnet/roslyn/tree/features/recursive-patterns) | [Merged to dev16.0 preview2](https://github.com/dotnet/roslyn/issues/25935) | [gafter](https://github.com/gafter) | [agocke](https://github.com/agocke), [cston](https://github.com/cston) | [gafter](https://github.com/gafter) | | [Async streams](https://github.com/dotnet/csharplang/blob/master/proposals/async-streams.md) | [async-streams](https://github.com/dotnet/roslyn/tree/features/async-streams) | [Merged to dev16.0 preview1](https://github.com/dotnet/roslyn/issues/24037) | [jcouv](https://github.com/jcouv) | [agocke](https://github.com/agocke) | [stephentoub](https://github.com/stephentoub) | @@ -26,14 +26,14 @@ efforts behind them. | [stackalloc in nested contexts](https://github.com/dotnet/csharplang/issues/1412) | [nested-stackalloc](https://github.com/dotnet/roslyn/tree/features/nested-stackalloc) | [In Progress](https://github.com/dotnet/roslyn/issues/28968) | [gafter](https://github.com/gafter) | - | [gafter](https://github.com/gafter) | [Unmanaged generic structs](https://github.com/dotnet/csharplang/issues/1744) | master | [Merged to dev16.1 preview1](https://github.com/dotnet/roslyn/issues/31374) | [RikkiGibson](https://github.com/RikkiGibson) | - | [jaredpar](https://github.com/jaredpar) | | [Static local functions](https://github.com/dotnet/csharplang/issues/1565) | master | [Merged in dev16.0 preview2](https://github.com/dotnet/roslyn/issues/32069) | [cston](https://github.com/cston) | [jaredpar](https://github.com/jaredpar) | [jcouv](https://github.com/jcouv) -| [Readonly members](https://github.com/dotnet/csharplang/issues/1710) | [readonly-members](https://github.com/dotnet/roslyn/tree/features/readonly-members) | [Prototype](https://github.com/dotnet/roslyn/issues/32911) | [RikkiGibson](https://github.com/RikkiGibson) | TBD | [jaredpar](https://github.com/jaredpar) +| [Readonly members](https://github.com/dotnet/csharplang/issues/1710) | [readonly-members](https://github.com/dotnet/roslyn/tree/features/readonly-members) | [Merged to dev16.1 preview2](https://github.com/dotnet/roslyn/issues/32911) | [RikkiGibson](https://github.com/RikkiGibson) | TBD | [jaredpar](https://github.com/jaredpar) # VB 16.0 | Feature | Branch | State | Developers | Reviewer | LDM Champ | | ------- | ------ | ----- | ---------- | -------- | --------- | -| [Line continuation comments](https://github.com/dotnet/vblang/issues/65) | [continuation-comments](https://github.com/dotnet/roslyn/tree/features/continuation-comments) | Prototype | [paul1956](https://github.com/paul1956) | [AlekseyTs](https://github.com/AlekseyTs) | [gafter](https://github.com/gafter) | -| [Relax null coalesing operator requirements](https://github.com/dotnet/vblang/issues/339) | [null-operator-enhancements](https://github.com/dotnet/roslyn/tree/features/null-operator-enhancements) | In Progress | [333fred](https://github.com/333fred) | [cston](https://github.com/cston) | [gafter](https://github.com/gafter) | +| [Line continuation comments](https://github.com/dotnet/vblang/issues/65) | [continuation-comments](https://github.com/dotnet/roslyn/tree/features/continuation-comments) | Merged in 16.1 (preview2) | [paul1956](https://github.com/paul1956) | [AlekseyTs](https://github.com/AlekseyTs) | [gafter](https://github.com/gafter) | +| [Relax null-coalescing operator requirements](https://github.com/dotnet/vblang/issues/339) | [null-operator-enhancements](https://github.com/dotnet/roslyn/tree/features/null-operator-enhancements) | Merged in 16.0 | [333fred](https://github.com/333fred) | [cston](https://github.com/cston) | [gafter](https://github.com/gafter) | # C# 7.3