Skip to content

Commit 2ca0209

Browse files
author
dotnet-automerge-bot
authored
Merge pull request #37776 from dotnet/merges/master-to-features/param-nullchecking
Merge master to features/param-nullchecking
2 parents 401bd1c + 0bca157 commit 2ca0209

File tree

4 files changed

+77
-2
lines changed

4 files changed

+77
-2
lines changed

src/VisualStudio/Core/Def/Implementation/ProjectSystem/RunningDocumentTableEventTracker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ public RunningDocumentTableEventTracker(IThreadingContext threadingContext, IVsE
3434
Contract.ThrowIfNull(runningDocumentTable);
3535
Contract.ThrowIfNull(listener);
3636

37-
// Advise / Unadvise for the RDT is free threaded past 16.0
3837
_foregroundAffinitization = new ForegroundThreadAffinitizedObject(threadingContext, assertIsForeground: false);
3938
_runningDocumentTable = (IVsRunningDocumentTable4)runningDocumentTable;
4039
_editorAdaptersFactoryService = editorAdaptersFactoryService;
4140
_listener = listener;
4241

42+
// Advise / Unadvise for the RDT is free threaded past 16.0
4343
((IVsRunningDocumentTable)_runningDocumentTable).AdviseRunningDocTableEvents(this, out _runningDocumentTableEventsCookie);
4444
}
4545

src/Workspaces/CSharp/Portable/Formatting/Rules/BaseFormattingRule.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ protected void AddBraceSuppressOperations(List<SuppressOperation> list, SyntaxNo
184184
// include lambda itself.
185185
firstTokenOfNode = node.Parent.GetFirstToken(includeZeroWidth: true);
186186
}
187+
else if (node.IsKind(SyntaxKindEx.PropertyPatternClause))
188+
{
189+
// include the pattern recursive pattern syntax and/or subpattern
190+
firstTokenOfNode = firstTokenOfNode.GetPreviousToken();
191+
}
187192

188193
// suppress wrapping on whole construct that owns braces and also brace pair itself if
189194
// it is on same line

src/Workspaces/CSharp/Portable/Formatting/Rules/TokenBasedFormattingRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public override AdjustSpacesOperation GetAdjustSpacesOperation(SyntaxToken previ
370370

371371
// nullable
372372
if (currentToken.Kind() == SyntaxKind.QuestionToken &&
373-
currentToken.Parent.Kind() == SyntaxKind.NullableType)
373+
currentToken.Parent.IsKind(SyntaxKind.NullableType, SyntaxKind.ClassConstraint))
374374
{
375375
return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
376376
}

src/Workspaces/CSharpTest/Formatting/FormattingTests.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9280,5 +9280,75 @@ public void FixMyType()
92809280
}
92819281
}", changedOptionSet: changingOptions);
92829282
}
9283+
9284+
[Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
9285+
public async Task ClassConstraint()
9286+
{
9287+
await AssertFormatAsync(
9288+
@"
9289+
class Program<T>
9290+
where T : class?
9291+
{
9292+
}",
9293+
@"
9294+
class Program<T>
9295+
where T : class ?
9296+
{
9297+
}");
9298+
}
9299+
9300+
[Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
9301+
public async Task SingleLinePropertyPattern1()
9302+
{
9303+
await AssertFormatAsync(
9304+
@"
9305+
using System.Collections.Generic;
9306+
class Program
9307+
{
9308+
public void FixMyType()
9309+
{
9310+
_ = new List<int>() is
9311+
{
9312+
Count: { },
9313+
};
9314+
}
9315+
}",
9316+
@"
9317+
using System.Collections.Generic;
9318+
class Program
9319+
{
9320+
public void FixMyType()
9321+
{
9322+
_ = new List<int>() is
9323+
{
9324+
Count:{},
9325+
};
9326+
}
9327+
}");
9328+
}
9329+
9330+
[Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
9331+
public async Task SingleLinePropertyPattern2()
9332+
{
9333+
await AssertFormatAsync(
9334+
@"
9335+
using System.Collections.Generic;
9336+
class Program
9337+
{
9338+
public void FixMyType(object o)
9339+
{
9340+
_ = o is List<int> { Count: { } };
9341+
}
9342+
}",
9343+
@"
9344+
using System.Collections.Generic;
9345+
class Program
9346+
{
9347+
public void FixMyType(object o)
9348+
{
9349+
_ = o is List<int>{Count:{}};
9350+
}
9351+
}");
9352+
}
92839353
}
92849354
}

0 commit comments

Comments
 (0)