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

Automatically move { opening braces down to a new line when pressing enter #6834

Closed
apotenza92 opened this issue Jan 27, 2024 · 11 comments · Fixed by dotnet/roslyn#76876
Closed

Comments

@apotenza92
Copy link

apotenza92 commented Jan 27, 2024

Hi all,
I've come across other older issues raised to have opening braces such as { automatically move down to the new line once enter is pressed and the cursor is inside the brace.
As far as I'm aware these were made before the more modern C# extension was created and are issues with the older Omnisharp LSP.

Describe the solution you would like

A setting for the VSCode C# Extension that allows for automatic moving of opening braces { to a newline.
This is the way it works in other C# editors like Visual Studio and Rider.

Applicable Scenarios

In what scenarios would the feature apply?

Currently:

class Car {*cursor here press enter*}

Results in the following after pressing enter:

class Car {
    *cursor here*
}

Proposed { setting enabled would result in the following after pressing enter:

class Car
{
    *cursor here*
}

Describe alternatives you've considered

The extension C# Curly Formatter achieves this but it should be a simple included option in the C# extension. This extension also has some issues conflicting with other extension such as Vim.

@astralmaster
Copy link

I cant believe this is still an issue in 2024.

@scriptBoris
Copy link

I can't believe that such a problem exists at all.

@B1ack3ye
Copy link

B1ack3ye commented Sep 4, 2024

I can't believe that such a problem exists for 7 years without a fix.

@Minihacker3k
Copy link

Anyone got a solution by any chance it triggers me alot...

@achobanov
Copy link

@ryzngard can we please mark this as a feature request as well?

@ryzngard
Copy link
Contributor

Thanks for the ping @achobanov , idk why this wasn't marked as untriaged :/ . Updated the labels

@Consumedgrub2
Copy link

Bruh why. This is annoying that this exists. I was wondering why my brackets weren't going on a new line. I'm pretty sure brackets on new lines is supposed to be a csharp code formatting standard.

@phil-allen-msft
Copy link
Contributor

There seems to be some similarities between this issue and dotnet/razor#11266, though the other issue is specifically VS and this is for VS Code.

@david-siegert
Copy link

I’m genuinely astonished that this is an issue. How is this even possible? This is a fundamental aspect of the C# standard, and yet even Microsoft, who established this standard, has introduced a bug like this. It’s baffling. With problems like this, I can’t understand how anyone could rely on VS Code for C# development.

@apotenza92
Copy link
Author

apotenza92 commented Jan 22, 2025

We're almost at the 1 year anniversary of this now. Any idea from people in the know if this could become a thing? @achobanov @ryzngard. Appreciate your efforts in responding in the first place.

JoeRobich added a commit to dotnet/roslyn that referenced this issue Jan 23, 2025
Enables format on type when the trigger character is a newline. Removes
text changes that contain the cursor as we do not want to remove the
indentation.



https://github.com/user-attachments/assets/962f8229-f41b-4632-a8e9-b7660575e448



Resolves dotnet/vscode-csharp#6834
@JoeRobich
Copy link
Member

A change to format on type has been made to the Roslyn LSP. It will flow into the C# extension later this week and be part of a future pre-release. Do note that format on type will need to be enabled.

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

Successfully merging a pull request may close this issue.