From 70ab4e0872b5291fce05b84df8b208c42cf985ac Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 31 Jul 2019 11:17:31 -0700 Subject: [PATCH 1/3] Fix formatting of nullable class constraint --- .../Formatting/Rules/TokenBasedFormattingRule.cs | 2 +- .../CSharpTest/Formatting/FormattingTests.cs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Workspaces/CSharp/Portable/Formatting/Rules/TokenBasedFormattingRule.cs b/src/Workspaces/CSharp/Portable/Formatting/Rules/TokenBasedFormattingRule.cs index 622174d4f49e8..b6faa60d4d88e 100644 --- a/src/Workspaces/CSharp/Portable/Formatting/Rules/TokenBasedFormattingRule.cs +++ b/src/Workspaces/CSharp/Portable/Formatting/Rules/TokenBasedFormattingRule.cs @@ -370,7 +370,7 @@ public override AdjustSpacesOperation GetAdjustSpacesOperation(SyntaxToken previ // nullable if (currentToken.Kind() == SyntaxKind.QuestionToken && - currentToken.Parent.Kind() == SyntaxKind.NullableType) + currentToken.Parent.IsKind(SyntaxKind.NullableType, SyntaxKind.ClassConstraint)) { return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine); } diff --git a/src/Workspaces/CSharpTest/Formatting/FormattingTests.cs b/src/Workspaces/CSharpTest/Formatting/FormattingTests.cs index 83a438f8cba24..98bb17db2a608 100644 --- a/src/Workspaces/CSharpTest/Formatting/FormattingTests.cs +++ b/src/Workspaces/CSharpTest/Formatting/FormattingTests.cs @@ -9280,5 +9280,21 @@ public void FixMyType() } }", changedOptionSet: changingOptions); } + + [Fact, Trait(Traits.Feature, Traits.Features.Formatting)] + public async Task ClassConstraint() + { + await AssertFormatAsync( + @" +class Program + where T : class? +{ +}", + @" +class Program + where T : class ? +{ +}"); + } } } From 538b4c3739799a3d1ca1678d6b479d7a4fa4f9eb Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 31 Jul 2019 11:23:41 -0700 Subject: [PATCH 2/3] Fix formatting of single line property patterns --- .../Formatting/Rules/BaseFormattingRule.cs | 5 ++ .../CSharpTest/Formatting/FormattingTests.cs | 54 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/Workspaces/CSharp/Portable/Formatting/Rules/BaseFormattingRule.cs b/src/Workspaces/CSharp/Portable/Formatting/Rules/BaseFormattingRule.cs index fef71496e2a37..86b445ac16686 100644 --- a/src/Workspaces/CSharp/Portable/Formatting/Rules/BaseFormattingRule.cs +++ b/src/Workspaces/CSharp/Portable/Formatting/Rules/BaseFormattingRule.cs @@ -184,6 +184,11 @@ protected void AddBraceSuppressOperations(List list, SyntaxNo // include lambda itself. firstTokenOfNode = node.Parent.GetFirstToken(includeZeroWidth: true); } + else if (node.IsKind(SyntaxKindEx.PropertyPatternClause)) + { + // include the pattern recursive pattern syntax and/or subpattern + firstTokenOfNode = firstTokenOfNode.GetPreviousToken(); + } // suppress wrapping on whole construct that owns braces and also brace pair itself if // it is on same line diff --git a/src/Workspaces/CSharpTest/Formatting/FormattingTests.cs b/src/Workspaces/CSharpTest/Formatting/FormattingTests.cs index 98bb17db2a608..ac85e8914d252 100644 --- a/src/Workspaces/CSharpTest/Formatting/FormattingTests.cs +++ b/src/Workspaces/CSharpTest/Formatting/FormattingTests.cs @@ -9294,6 +9294,60 @@ class Program class Program where T : class ? { +}"); + } + + [Fact, Trait(Traits.Feature, Traits.Features.Formatting)] + public async Task SingleLinePropertyPattern1() + { + await AssertFormatAsync( + @" +using System.Collections.Generic; +class Program +{ + public void FixMyType() + { + _ = new List() is + { + Count: { }, + }; + } +}", + @" +using System.Collections.Generic; +class Program +{ + public void FixMyType() + { + _ = new List() is + { + Count:{}, + }; + } +}"); + } + + [Fact, Trait(Traits.Feature, Traits.Features.Formatting)] + public async Task SingleLinePropertyPattern2() + { + await AssertFormatAsync( + @" +using System.Collections.Generic; +class Program +{ + public void FixMyType(object o) + { + _ = o is List { Count: { } }; + } +}", + @" +using System.Collections.Generic; +class Program +{ + public void FixMyType(object o) + { + _ = o is List{Count:{}}; + } }"); } } From 15999cdd73c583562705a6c0e0fbe7d7a97844fd Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Wed, 31 Jul 2019 16:56:42 -0700 Subject: [PATCH 3/3] Move comment to correct line of code --- .../ProjectSystem/RunningDocumentTableEventTracker.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/RunningDocumentTableEventTracker.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/RunningDocumentTableEventTracker.cs index 2f45d40845587..03cf87825d12d 100644 --- a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/RunningDocumentTableEventTracker.cs +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/RunningDocumentTableEventTracker.cs @@ -34,12 +34,12 @@ public RunningDocumentTableEventTracker(IThreadingContext threadingContext, IVsE Contract.ThrowIfNull(runningDocumentTable); Contract.ThrowIfNull(listener); - // Advise / Unadvise for the RDT is free threaded past 16.0 _foregroundAffinitization = new ForegroundThreadAffinitizedObject(threadingContext, assertIsForeground: false); _runningDocumentTable = (IVsRunningDocumentTable4)runningDocumentTable; _editorAdaptersFactoryService = editorAdaptersFactoryService; _listener = listener; + // Advise / Unadvise for the RDT is free threaded past 16.0 ((IVsRunningDocumentTable)_runningDocumentTable).AdviseRunningDocTableEvents(this, out _runningDocumentTableEventsCookie); }