vscode-csharp
vscode-csharp copied to clipboard
Automatically move { opening braces down to a new line when pressing enter
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.
I cant believe this is still an issue in 2024.
I can't believe that such a problem exists at all.
I can't believe that such a problem exists for 7 years without a fix.
Anyone got a solution by any chance it triggers me alot...
@ryzngard can we please mark this as a feature request as well?
Thanks for the ping @achobanov , idk why this wasn't marked as untriaged :/ . Updated the labels
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.
There seems to be some similarities between this issue and https://github.com/dotnet/razor/issues/11266, though the other issue is specifically VS and this is for VS Code.
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.
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.
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.
yeah, how to disable this? It didn't do anything and now it started working and I don't see an option to disable it
yeah, how to disable this? It didn't do anything and now it started working and I don't see an option to disable it
@LimeShep you can override those settings in your settings.json (ctrl+shift+p -> Open user settings (JSON)):
"[csharp]": {
"editor.formatOnType": false
}
To help everyone get to the right place because this whole process is almost abusive, you want to use...
- FILE => PREFERENCES => SETTINGS.
- In the search box, type "@lang:csharp" for just the C# language preferences.
- Find "Editor › Language: Brackets"
- There's a link there for "Edit in settings.json"
- Click to open that file
- Look for " "[csharp]": { ... } " or create one.
- Add " "editor.formatOnType": false " to that list.
For more recent (version 2.93.22); set "dotnet.autoInsert.enableAutoInsert": false in the settings.json.
This is also found as Enable Auto Insert under the C# Extension. Why this causes the bracket to go on a separate line baffles me; its definition says "Enable automatic insertion of documentation comments" which is in no relation to curly brackets
For more recent (version 2.93.22); set
"dotnet.autoInsert.enableAutoInsert": falsein the settings.json. This is also found asEnable Auto Insertunder the C# Extension. Why this causes the bracket to go on a separate line baffles me; its definition says "Enable automatic insertion of documentation comments" which is in no relation to curly brackets
this kind of works. but if you have your cursor on the same line as the closing bracket and press enter, the opening bracket shifts down to a new line again :(
edit I think I solved it. I did the following:
- Navigate to
Preferences -> Settings -> Extensions -> C# - Turn off
Enable Auto Insert. This disables placing opening bracket on a new line when pressing enter. But issue still remains where opening bracket goes onto new line again when pressing enter on the closing bracket. - Restart editor.
- Navigate to
Preferences -> Settings -> Extensions -> C# - Turn off
CSharp Format: Enable - Turn off
Omnisharp: Use Editor Formatting Settings - Turn off
Razor Format: Enable - Restart editor.
- Everything should be resolved now. You can re-enable steps 5-7 if needed, and the issue should stay gone. Otherwise, just leave them off. I'm not sure which one actually solved the issue.