Skip to content

Razor formatting removes indentation for array initializers #9826

Open
@vsfeedback

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


[severity:It bothers me. A fix would be nice]
If I have the following code in a .cshtml file and format it with Ctrl-K, Ctrl-D, the indentation of the second block is altered, but incorrectly.

@model SampleViewModel
@{
    string minimum = "", maximum = "";
    
    // This piece correctly remains unchanged with Ctrl-K, Ctrl-D
    var dateOptions = new[,]
    {
        {$"Set to minimum ({minimum})", minimum},
        {$"Set to maximum ({maximum})", maximum}
    };
}
<table>
    @{
        // This piece incorrectly changes with Ctrl-K, Ctrl-D
        var dateOptions2 = new[,]
        {
            {$"Set to minimum ({minimum})", minimum},
            {$"Set to maximum ({maximum})", maximum},
        };
    }
</table>
  

The result:

@model SampleViewModel
@{
    string minimum = "", maximum = "";

    // This piece correctly remains unchanged with Ctrl-K, Ctrl-D
    var dateOptions = new[,]
    {
        {$"Set to minimum ({minimum})", minimum},
        {$"Set to maximum ({maximum})", maximum}
    };
}
<table>
    @{
        // This piece incorrectly changes with Ctrl-K, Ctrl-D
        var dateOptions2 = new[,]
        {
    {$"Set to minimum ({minimum})", minimum},
    {$"Set to maximum ({maximum})", maximum},
    };
    }
</table>
  

Similar issues have been raised, and marked as fixed but this issue is occurring in Visual Studio Enterprise v17.8.3 so I assume it’s either a regression or the specific case above has not been fixed.


Original Comments

Feedback Bot on 12/11/2023, 05:48 PM:

(private comment, text removed)

Feedback Bot on 12/12/2023, 00:54 AM:

(private comment, text removed)


Original Solutions

(no solutions)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions