Skip to content
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 @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ protected void AddBraceSuppressOperations(List<SuppressOperation> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
70 changes: 70 additions & 0 deletions src/Workspaces/CSharpTest/Formatting/FormattingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9280,5 +9280,75 @@ public void FixMyType()
}
}", changedOptionSet: changingOptions);
}

[Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
public async Task ClassConstraint()
{
await AssertFormatAsync(
@"
class Program<T>
where T : class?
{
}",
@"
class Program<T>
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<int>() is
{
Count: { },
};
}
}",
@"
using System.Collections.Generic;
class Program
{
public void FixMyType()
{
_ = new List<int>() 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<int> { Count: { } };
}
}",
@"
using System.Collections.Generic;
class Program
{
public void FixMyType(object o)
{
_ = o is List<int>{Count:{}};
}
}");
}
}
}