Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor C# is Formatting Constructs like JavaScript #11266

Open
vsfeedback opened this issue Dec 3, 2024 · 2 comments
Open

Blazor C# is Formatting Constructs like JavaScript #11266

vsfeedback opened this issue Dec 3, 2024 · 2 comments
Labels
author: migration bot 🤖 The issue was created by a issue mover bot. The author may not be the actual author feature-formatting
Milestone

Comments

@vsfeedback
Copy link

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


[severity:It bothers me. A fix would be nice]
When coding in C# in Blazor, when entering a construct like "if", the left brace ({) should move below the if, like it does in all other C# projects. It seems to format like JavaScript, which is not desirable. Perhaps it could be a setting.


Original Comments

Feedback Bot on 25/11/2024, 00:34 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Runtong Liu (Centific Technologies Inc) [MSFT] on 25/11/2024, 06:07 PM:

Thank you for taking the time to log this issue!

I tried repro this issue:
For C# code in .razor of blazor app, left brace can’t make a new line after “if” when save the code, but after I press ctrl+k,ctrl+d, the left brace go to the new line.
For the code in .cs file, the left brace can go to the new line after you save the code or press ctrl+k,ctrl+d.

Is your issue same as mine? if not, can you please provide us a repro video using https://www.screentogif.com/or a similar tool?

We look forward to hearing from you!

Tony Lugg on 26/11/2024, 01:06 AM:

It is not about saving the code of formatting the entire document. When working in a .cs file, typing an “if” statement like:

if (a > b) {

As soon as I hit Enter, I will end up with:

if (a > b)
{

}

But when working in a .razor file in Blazor, this does not happen, the brace is left on the same line as the if.

In Tools->Options under Text Editor->Razor->Advanced I have set the setting Code/functions block open brace on next line several times hoping this will do it, but it never keeps the change after restarting, and doesn’t seem to do what I’m looking for anyway.

Runtong Liu (Centific Technologies Inc) [MSFT] on 26/11/2024, 01:57 PM:

Thanks for your sharing the detail steps, I can reproduce this issue through your shared steps and this issue has been escalated for further investigation, if there is any process, I will inform you immediately.

@dotnet-policy-service dotnet-policy-service bot added untriaged author: migration bot 🤖 The issue was created by a issue mover bot. The author may not be the actual author labels Dec 3, 2024
@davidwengier
Copy link
Contributor

davidwengier commented Dec 3, 2024

I couldn't personally get this feature to work in a C# file, but it could very well be my own Roslyn settings:

Image

It defeinitely doesn't work in a Razor file though. We do have OnAutoInsert handling for pressing Enter when both braces are present, but it seems that doesn't take effect with only one brace, so perhaps we can tweak that and make it work.

@TonyLugg
Copy link

TonyLugg commented Jan 3, 2025

This is really bothersome, so if it can be improved that would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author: migration bot 🤖 The issue was created by a issue mover bot. The author may not be the actual author feature-formatting
Projects
None yet
Development

No branches or pull requests

4 participants