Skip to content

Commit 0f029e2

Browse files
authored
Allow Razor to create a formatting options, and send them to OOP (#79458)
2 parents a8d4395 + d903f6c commit 0f029e2

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/Tools/ExternalAccess/Razor/Features/RazorCSharpFormattingInteractionService.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System;
65
using System.Collections.Generic;
76
using System.Collections.Immutable;
87
using System.Threading;
@@ -23,6 +22,14 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.Razor
2322
/// </summary>
2423
internal static class RazorCSharpFormattingInteractionService
2524
{
25+
public static RazorCSharpSyntaxFormattingOptions GetRazorCSharpSyntaxFormattingOptions(SolutionServices services)
26+
{
27+
var legacyOptionsService = services.GetService<ILegacyGlobalOptionsWorkspaceService>();
28+
var options = legacyOptionsService?.GetSyntaxFormattingOptions(services.GetLanguageServices(LanguageNames.CSharp))
29+
?? CSharpSyntaxFormattingOptions.Default;
30+
return new RazorCSharpSyntaxFormattingOptions((CSharpSyntaxFormattingOptions)options);
31+
}
32+
2633
/// <summary>
2734
/// Returns the text changes necessary to format the document after the user enters a
2835
/// character. The position provided is the position of the caret in the document after

src/Tools/ExternalAccess/Razor/Features/RazorCSharpSyntaxFormattingOptions.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Runtime.Serialization;
67
using Microsoft.CodeAnalysis.CodeStyle;
78
using Microsoft.CodeAnalysis.CSharp.Formatting;
89

@@ -11,17 +12,18 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.Razor.Features
1112
/// <summary>
1213
/// Wrapper for CSharpSyntaxFormattingOptions for Razor external access.
1314
/// </summary>
15+
[DataContract]
1416
internal sealed record class RazorCSharpSyntaxFormattingOptions(
15-
RazorSpacePlacement Spacing,
16-
RazorBinaryOperatorSpacingOptions SpacingAroundBinaryOperator,
17-
RazorNewLinePlacement NewLines,
18-
RazorLabelPositionOptions LabelPositioning,
19-
RazorIndentationPlacement Indentation,
20-
bool WrappingKeepStatementsOnSingleLine,
21-
bool WrappingPreserveSingleLine,
22-
RazorNamespaceDeclarationPreference NamespaceDeclarations,
23-
bool PreferTopLevelStatements,
24-
int CollectionExpressionWrappingLength)
17+
[property: DataMember] RazorSpacePlacement Spacing,
18+
[property: DataMember] RazorBinaryOperatorSpacingOptions SpacingAroundBinaryOperator,
19+
[property: DataMember] RazorNewLinePlacement NewLines,
20+
[property: DataMember] RazorLabelPositionOptions LabelPositioning,
21+
[property: DataMember] RazorIndentationPlacement Indentation,
22+
[property: DataMember] bool WrappingKeepStatementsOnSingleLine,
23+
[property: DataMember] bool WrappingPreserveSingleLine,
24+
[property: DataMember] RazorNamespaceDeclarationPreference NamespaceDeclarations,
25+
[property: DataMember] bool PreferTopLevelStatements,
26+
[property: DataMember] int CollectionExpressionWrappingLength)
2527
{
2628
public static readonly RazorCSharpSyntaxFormattingOptions Default = new();
2729

0 commit comments

Comments
 (0)