Skip to content

Broken formatting on Razor (cshtml) files with LF EOL (vscode) #4349

@bryanjhv

Description

@bryanjhv

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 dotnet/vscode-csharp#4503 as requested.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions