dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.85k stars 670 forks source link

[BUG] Formatting C# code not respecting editorconfig settings #6953

Closed arkalyanms closed 1 month ago

arkalyanms commented 7 months ago

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

ntswamp commented 3 months ago

any update on this? It's been annoying the shit out of me.

sharwell commented 3 months ago

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.

Penguin-Spy commented 2 months ago

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.

mikadumont commented 1 month ago

EditorConfig should be working. If you're still experience this, feel free to open a new issue with details.