Wrong indentation in .razor files if there is a RenderFragment
This issue has been moved from a ticket on Developer Community.
For example, create this Asp.Net Blazor page:
@page "/"
@code
{
void T()
{
S("first"
+ "second"
+ "third");
}
string[] S(string s) =>
s.Split(',')
. Select(s => s.Trim())
. ToArray();
RenderFragment R => @<div></div>;
}
When the file is formatted (Ctrl+K,Ctrl+D), some lines are shifted to the left. If you format it again, they are shifted to the right. If you format it again, they are shifted to the left... Every time I commit to Git, there are too many modified lines.
Original Comments
Feedback Bot on 8/20/2023, 06:59 PM:
(private comment, text removed)
Original Solutions
(no solutions)
lol, it's true.
I can confirm that using variables and objects inside custom components in blazor files without parentheses also breaks indentation.
@* OK within parentheses *@
<MudAlert>
@(message)
</MudAlert>
@* Breaks formatting if @ without parentheses is the last element in component *@
<MudAlert>
@message
</MudAlert> @* Everything after this line is indented wrong *@
<MudAlert>
@message
@* If @ is not the last element indentation returns to normal except this line. This one is indented like a close tag *@
</MudAlert>
@* All of rules above are valid for one line elements too *@
<MudAlert>@obj.message</MudAlert>
<MudAlert>
@(message)
</MudAlert>
VS: 17.8.3 .NET: 7.0
@eMuonTau most of those issues you mentioned don't repro for me in 17.8.3, but perhaps I'm trying something different. Is all of that in a RenderFragment? This issue is about formatting problems specifically with RenderFragments so if you're getting other formatting issues, perhaps it would be good if you could log a new issue, with a fuller description of what is happening. I copied and pasted the code you wrote above into a project that references MudBlazor and except for the last MudAlert component, everything was fine.
This is fixed with the new formatting engine.