Skip to content

Conversation

@davidwengier
Copy link
Member

Fixes #12053

@davidwengier davidwengier requested a review from a team as a code owner July 29, 2025 07:29
var csharpChanges = RazorCSharpFormattingInteractionService.GetFormattedTextChanges(helper.HostWorkspaceServices, csharpRoot, csharpRoot.FullSpan, options.ToIndentationOptions(), options.CSharpSyntaxFormattingOptions, cancellationToken);
var csharpSyntaxFormattingOptions = options.CSharpSyntaxFormattingOptions.AssumeNotNull();

// Roslyn can be configured to insert a space after a method call, or a dot, but that can break Razor. eg:
Copy link
Contributor

Choose a reason for hiding this comment

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

// Roslyn can be configured to insert a space after a method call, or a dot, but that can break Razor. eg:

Devil's advocate, would it be possible to only augment the C# formatting in @ scenarios instead of @{ scenarios?

Copy link
Member Author

Choose a reason for hiding this comment

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

Possible? Sure, it's just code :)

Off the top of my head I can think of 3 approaches:

  1. Add something cool like #pragma formatter disable SpaceBeforeMethodCall to Roslyn
  2. Use the C# parser to go through the formatted expressions after the fact and remove significant whitespace
  3. Do a two-pass format, one with the user options, one for just implicit expressions with these modified options

All 3 sound like they're beyond this PR, and personally I think I'd wait until someone complains about the formatting not honouring their settings before we action it (assuming when they complain, we remember that this quirk exists)

@davidwengier davidwengier merged commit d372e46 into dotnet:main Aug 6, 2025
11 checks passed
@davidwengier davidwengier deleted the DontLetRoslynBreakUs branch August 6, 2025 21:55
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Aug 6, 2025
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Razor-File code formating breaks code

4 participants