vscode-csharp
vscode-csharp copied to clipboard
[BUG] Formatting C# code not respecting editorconfig settings
From vscode-dotnettools created by gmamekudz: microsoft/vscode-dotnettools#886
Describe the Issue
There is no more way to formatting c# code with braces on same line. This is since last vs code update.
Steps To Reproduce
Set up omnisharp.json to
{
"FormattingOptions": {
"NewLinesForBracesInLambdaExpressionBody": false,
"NewLinesForBracesInAnonymousMethods": false,
"NewLinesForBracesInAnonymousTypes": false,
"NewLinesForBracesInControlBlocks": false,
"NewLinesForBracesInTypes": false,
"NewLinesForBracesInMethods": false,
"NewLinesForBracesInProperties": false,
"NewLinesForBracesInObjectCollectionArrayInitializers": false,
"NewLinesForBracesInAccessors": false,
"NewLineForElse": false,
"NewLineForCatch": false,
"NewLineForFinally": false
}
}
and/or .editorconfig to
[*.cs]
csharp_new_line_before_open_brace = none
csharp_new_line_before_else = false
csharp_new_line_before_catch = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_object_initializers = false
csharp_new_line_before_members_in_anonymous_types = false
csharp_new_line_between_query_expression_clauses = false
Format c# code.
Expected Behavior
for example:
public static bool BoxIsValidAndActive(RuntimeInfo _ri, long _boxesId) {
SqlCommand cmd = new SqlCommand();
SqlDataReader rdr;
Instead this will be the result:
public static bool BoxIsValidAndActive(RuntimeInfo _ri, long _boxesId)
{
SqlCommand cmd = new SqlCommand();
SqlDataReader rdr;
Environment Information
Version: 1.85.2 (system setup) Commit: 8b3775030ed1a69b13e4f4c628c612102e30a681 Datum: 2024-01-18T06:40:10.514Z Electron: 25.9.7 ElectronBuildId: 26354273 Chromium: 114.0.5735.289 Node.js: 18.15.0 V8: 11.4.183.29-electron.0 Betriebssystem: Windows_NT x64 10.0.22631
any update on this? It's been annoying the shit out of me.
I am not able to reproduce this. My .editorconfig contains the following:
root = true
[*.cs]
csharp_new_line_before_open_brace = none
When I run the Format Document command, opening braces are moved from being on their own line to being at the end of the preceding line.
I am able to reproduce this with "C# Dev Kit" (ms-dotnettools.csdevkit) and "C#" (ms-dotnettools.csharp) both enabled, but the issue does not occur with just "C#" enabled. With the C# Dev Kit extension enabled, the options in the .editorconfig file are ignored.
EditorConfig should be working. If you're still experience this, feel free to open a new issue with details.
I'm experiencing the same issue. Having an .editorconfig file in the root of a Dotnet project works as expected (it formats the curly braces on the same line), but if I have no project setup, it doesn't work.
I mean, having a folder with just an .editorconfig file and a .cs script doesn't seem to work when formatting.
@Vasdranna The C# extension requires a project file to be present to startup. Project files are necessary because they tell the extension which .NET framework you are targeting, what NuGet packages you are referencing, etc...
We do have an issue tracking a better loose file experience. See https://github.com/dotnet/vscode-csharp/issues/5729
I have the same issue.
My .editorconfig is being ignored when formatting on save but it works when doing dotnet format.
I have a dotnet project setup with dotnet new web.
@PierBover Please open a new issue and provide the requested logs.