razor: Broken formatting on Razor (cshtml) files with LF EOL (vscode)

Describe the bug

Razor (cshtml) file formatting breaks in a very strange way when using LF end of lines. It doesn’t happen if file EOL is CRLF. It’s independent of BOM-encoded file (tested this).

To Reproduce

Repository: https://github.com/bryanjhv/aspnet-vscode-issues (including the steps above and some extra files in the GIF below)

  1. Create a new webapp project using dotnet new.
  2. Open any .cshtml file with Razor expressions (Index.cshtml, etc).
  3. Change its end of line to LF and save it.
  4. Enable format on save.
  5. Modify the file (add a space or something).
  6. Save the file.

recording

Exceptions (if any)

None.

Further technical details

  • ASP.NET Core version: 5.0.5

  • Include the output of dotnet --info

    .NET SDK (reflecting any global.json):
     Version:   5.0.202
     Commit:    db7cc87d51
    
    Runtime Environment:
     OS Name:     Windows
     OS Version:  10.0.19042
     OS Platform: Windows
     RID:         win10-x64
     Base Path:   C:\Program Files\dotnet\sdk\5.0.202\
    
    Host (useful for support):
      Version: 5.0.5
      Commit:  2f740adc14
    
    .NET SDKs installed:
      5.0.202 [C:\Program Files\dotnet\sdk]
    
    .NET runtimes installed:
      Microsoft.AspNetCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.NETCore.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.WindowsDesktop.App 5.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    
    To install additional .NET runtimes or SDKs:
      https://aka.ms/dotnet-download
    
  • The IDE (VS / VS Code/ VS4Mac) you’re running on, and its version

    • VSCode version: 1.55.2
    • C# Extension: 1.23.11

Additional notes

Migrated from https://github.com/OmniSharp/omnisharp-vscode/issues/4503 as requested.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 18 (9 by maintainers)

Most upvoted comments

Thanks for the traces @bryanjhv! Ya I validated that things didn’t break down for normal crlf cases which thankfully they don’t; however, was definitely able to reproduce after changing the file’s crlf -> lf.