Razor Editor (VS2022) Comment & Uncomment working incorrectly
Describe the bug:
The new Razor Editor introduced in Visual Studio 2022 has issues commenting out code on HTML or Razor code. "Ctrl+K" or "Ctrl+U" short cuts for comments are working incorrectly.
Switching to "legacy Razor editor for ASP.NET Core" via options helped. I'm just wondering if the behavior of the new Razor Editor is correct or if this a bug?
Comments should contain @* *@. However, we get //
Version used: VS2022 17.1.2
To reproduce: Steps to reproduce the behavior:
- open a complex razor page containing HTML, Razor and JavaScript Code
- try to comment/uncomment code by using the short cuts: "Ctrl+K" or "Ctrl+U"
- watch the video
Expected behavior: HTML or Razor code comments should contain @* *@. However, we get //
https://user-images.githubusercontent.com/12381397/160365666-2765dba6-a177-4a96-bf42-b629abe26fa1.mp4
@arashberlin thank you for the bug report! I've dug into your issue and found a minimal repro:
Comment between the | pipes
@{
<strong>
|<span>
</span>|
</strong>
}
Expected:
@{
<strong>
@*<span>
</span>*@
</strong>
}
Actual:
@{
<strong>
//<span>
//</span>
</strong>
}
@arashberlin as a workaround you can remove the overarching @{...} from your code to get things back into a working state.
I have found another example:
@{
void f()
{
<p class="x"></p>
}
}
//<div>
// text
//</div>
Why is there the C# comment if the HTML is not inside a code block ? Do you know any workaround ?
The issue is still not fixed in VS 2022 17.2.2.
I run Razor editor in legacy mode with no problems untill this bug is fixed.
I am also experiencing this issue with VS 2022 17.12.3, which is frustrating. I don't know which update I took where this began, but the Code Comments started using slashes for all comments regardless of file type. It used to be smart enough to know what type of comment to use based on whether it was C#, Razor, HTML, or CSS.
Thank you for looking into it for us!
Today, I upgraded to VS 2022 17.12.5 and it fixed the Razor comment issue. The code comments are now completed in a Razor file with the @* *@ block! Awesome.
I have version 17.14.27 and still have this problem but could notice something strange. After a code block this bug occurs otherwise not.
Problem after a code block. Comment with double slash:
And when I am commenting out the code block, the subsequent comment is formatted correctly: