Razor formatting removes indentation for array initializers
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)
Just like to add that the Razor editor (as of 17.8.6) does not indent/format correctly for many different scenarios. It really messes with my OCD.
It also becomes much less responsive the larger the Razor file. I have a 600 line page filled with components that brings it to it's knees.
Would love to see a deep dive refactor or rewrite of the Razor editor, especially since so many of us are moving to Razor, as its pretty "unstable" now. Not a deal breaker, but it is certainly annoying/frustrating.
Hate to just complain. If I can assist with screen shots or anything, just let me know.