razor icon indicating copy to clipboard operation
razor copied to clipboard

FUSE - Formatter behaves differently when calls end up calling Write (or similar)

Open ryzngard opened this issue 1 year ago • 2 comments

Failing test name: FormattingDocument(testFileName: "FormatDocument.cshtml")

         <p>
     @*
     test
     *@
     @while (true)
     {
     }
</p>
<div>
     @if (true)
     {
         <div>
             <p></p>
         </div>
     }
</div>
<div>
     @(Html.DropDownList("list")
-        .ToString()
-        )
+    .ToString()
+    )
</div>

Problem

The context for c# in fuse has a method call surrounding the code rather than a variable assignment, causing the csharp compiler to behave differently in indentation rules.

Potential Fix

It's possible to assign DateTime.Now.ToString() as below to a variable that is uniquely named by the compiler, and then use that variable in the call. This would cause the formatting behavior to behave the same as today

Without Fuse

#line 17 "/path/to/Document.mvc"
__o = DateTime
.Now
.ToString();

#line default

With Fuse

           Write(
#nullable restore
#line 17 "/path/to/Document.mvc"
     DateTime
.Now
.ToString()

#line default
#line hidden
#nullable disable
           );

ryzngard avatar May 23 '24 01:05 ryzngard

@ryzngard how impactful is this for integration tests? Trying to prioritize given we're low on dev power right now.

jaredpar avatar May 23 '24 20:05 jaredpar

This accounts for 4/19 of the integration test failures from the last run.

ryzngard avatar May 23 '24 20:05 ryzngard