From 840c3d72c1e8f7b5661f5b8fb0a02d143abd1d70 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:55:28 +0200 Subject: [PATCH 1/2] Add formatting tests with checked and unchecked --- .../SmartTokenFormatterFormatRangeTests.cs | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartTokenFormatterFormatRangeTests.cs b/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartTokenFormatterFormatRangeTests.cs index e636649c95723..42742ac7ca02e 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartTokenFormatterFormatRangeTests.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/Indentation/SmartTokenFormatterFormatRangeTests.cs @@ -3119,6 +3119,66 @@ public void M() AutoFormatToken(code, expected, useTabs); } + [WpfTheory] + [CombinatorialData] + [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] + public void UsingStatementWithNestedCheckedStatement(bool useTabs) + { + var code = @"class C +{ + public void M() + { + using (null) + checked + { + }$$ + } +}"; + + var expected = @"class C +{ + public void M() + { + using (null) + checked + { + } + } +}"; + + AutoFormatToken(code, expected, useTabs); + } + + [WpfTheory] + [CombinatorialData] + [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] + public void UsingStatementWithNestedUncheckedStatement(bool useTabs) + { + var code = @"class C +{ + public void M() + { + using (null) + unchecked + { + }$$ + } +}"; + + var expected = @"class C +{ + public void M() + { + using (null) + unchecked + { + } + } +}"; + + AutoFormatToken(code, expected, useTabs); + } + [WpfTheory] [CombinatorialData] [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] From 5adc5d1ddb7b5d3f0e4da3e5c5e1a5308f63dbb6 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Fri, 2 Oct 2020 17:53:43 +0200 Subject: [PATCH 2/2] Support checked and unchecked statements in formatting --- .../Compiler/CSharp/Utilities/FormattingRangeHelper.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Utilities/FormattingRangeHelper.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Utilities/FormattingRangeHelper.cs index 47422dbdd6132..92abbc3251d48 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Utilities/FormattingRangeHelper.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Utilities/FormattingRangeHelper.cs @@ -368,6 +368,8 @@ private static bool IsSpecialContainingNode(SyntaxNode node) node.Kind() == SyntaxKind.LabeledStatement || node.Kind() == SyntaxKind.LockStatement || node.Kind() == SyntaxKind.FixedStatement || + node.Kind() == SyntaxKind.UncheckedStatement || + node.Kind() == SyntaxKind.CheckedStatement || node.Kind() == SyntaxKind.GetAccessorDeclaration || node.Kind() == SyntaxKind.SetAccessorDeclaration || node.Kind() == SyntaxKind.AddAccessorDeclaration ||