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 @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
Expand All @@ -23,6 +22,14 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.Razor
/// </summary>
internal static class RazorCSharpFormattingInteractionService
{
public static RazorCSharpSyntaxFormattingOptions GetRazorCSharpSyntaxFormattingOptions(SolutionServices services)
{
var legacyOptionsService = services.GetService<ILegacyGlobalOptionsWorkspaceService>();
var options = legacyOptionsService?.GetSyntaxFormattingOptions(services.GetLanguageServices(LanguageNames.CSharp))
?? CSharpSyntaxFormattingOptions.Default;
return new RazorCSharpSyntaxFormattingOptions((CSharpSyntaxFormattingOptions)options);
}

/// <summary>
/// Returns the text changes necessary to format the document after the user enters a
/// character. The position provided is the position of the caret in the document after
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.Serialization;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.Formatting;

Expand All @@ -11,17 +12,18 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.Razor.Features
/// <summary>
/// Wrapper for CSharpSyntaxFormattingOptions for Razor external access.
/// </summary>
[DataContract]
internal sealed record class RazorCSharpSyntaxFormattingOptions(
RazorSpacePlacement Spacing,
RazorBinaryOperatorSpacingOptions SpacingAroundBinaryOperator,
RazorNewLinePlacement NewLines,
RazorLabelPositionOptions LabelPositioning,
RazorIndentationPlacement Indentation,
bool WrappingKeepStatementsOnSingleLine,
bool WrappingPreserveSingleLine,
RazorNamespaceDeclarationPreference NamespaceDeclarations,
bool PreferTopLevelStatements,
int CollectionExpressionWrappingLength)
[property: DataMember] RazorSpacePlacement Spacing,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you need DataMember(Order = ...) here, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that too, but the real CSharpSybtaxFormattingOptions this wraps doesn't have it, and this works fine in manual testing 🤷‍♂️

Guessing someone configured something, or changes something in servicehub maybe

[property: DataMember] RazorBinaryOperatorSpacingOptions SpacingAroundBinaryOperator,
[property: DataMember] RazorNewLinePlacement NewLines,
[property: DataMember] RazorLabelPositionOptions LabelPositioning,
[property: DataMember] RazorIndentationPlacement Indentation,
[property: DataMember] bool WrappingKeepStatementsOnSingleLine,
[property: DataMember] bool WrappingPreserveSingleLine,
[property: DataMember] RazorNamespaceDeclarationPreference NamespaceDeclarations,
[property: DataMember] bool PreferTopLevelStatements,
[property: DataMember] int CollectionExpressionWrappingLength)
{
public static readonly RazorCSharpSyntaxFormattingOptions Default = new();

Expand Down
Loading