Omnisharp-vscode: Same line curly braces for C#

Created on 25 Apr 2016  Â·  13Comments  Â·  Source: OmniSharp/omnisharp-vscode

_From @weshardee on April 23, 2016 2:44_

Is there or will there be a setting to toggle how curly braces are formatted in C# similar to https://github.com/Microsoft/vscode/issues/1533?

_Copied from original issue: Microsoft/vscode#5683_

Resolved-Fixed

Most helpful comment

Yes! Controlling all of the C# formatting options exposed within Visual Studio is now possible due to https://github.com/OmniSharp/omnisharp-roslyn/pull/649. You can add an omnisharp.json file that includes the following:

{
    "formatting": {
        "newLinesForBracesInMethods": false
    }
}

You can see the options available here: https://github.com/OmniSharp/omnisharp-roslyn/blob/dev/src/OmniSharp.Abstractions/Options/FormattingOptions.cs.

All 13 comments

_From @dbaeumer on April 23, 2016 19:24_

@jrieken not sure if this would be us or OmniSharp.

Any updates on this?

Yes! Controlling all of the C# formatting options exposed within Visual Studio is now possible due to https://github.com/OmniSharp/omnisharp-roslyn/pull/649. You can add an omnisharp.json file that includes the following:

{
    "formatting": {
        "newLinesForBracesInMethods": false
    }
}

You can see the options available here: https://github.com/OmniSharp/omnisharp-roslyn/blob/dev/src/OmniSharp.Abstractions/Options/FormattingOptions.cs.

If somebody ended on this issue from google as me:

I think syntax changed and snippet above does not work.
"formatting" should be changed to "FormattingOptions"

@hheexx correct. you can find more details in the blog post here http://www.strathweb.com/2017/01/c-code-formatting-settings-in-vs-code-and-omnisharp/

I'm still seeing same line curly braces in VSCode with Omnisharp. Tried setting that the FormattingOptions to both true/false and it still remains on the first line (tested with restart as well). Any ideas? @DustinCampbell

{
    "FormattingOptions": {
        "newLinesForBracesInMethods": false
    }
}

works for me.

@DustinCampbell I'm not sure where to add these lines to. And shouldn't be it in the setting we use to go to with Ctrl+,?

Edit: I added that to ~/.omnisharp/omnisharp.json, but the brace is still inserted at next line if I complete snippet of if statement. I want the spaces on the same line as if statement for the sake of code consistency. It's irritating.

I just found the exact same problem as @santosh above.

The snippets for "if", "for", etc don't follow the formatting settings or something.

The code...

if (true)
{

}

...is created. And then when I format the document using format. It moves the braces to same line as if statement.

I also tried placing same FormattingOptions in a omnisharp.json file i both HOME/.omnisharp/ and the project home. No difference.

For those who also want to change the snippets:

Open %USERPROFILE%\.vscode\extensions\ms-vscode.csharp-{VERSION}\snippets\csharp.json with VS Code and use "Find and Replace" (CTRL+H/F) with regex option enabled to replace (including the spaces):

",\n        "{"

with

 {"

and apply for all. Reload VS Code with command palette (or just restart it) for changes to take effect. Make sure to backup csharp.json after changing it because OmniSharp overwrites it on extension update.

@santosh @d0rf3n

@N3pp There's no omnisharp folder in %USERPROFILE%\.vscode\extensions\, should I create one? If so, then by which name? Because extensions of that folder have version number embedded. I don't know which version of omnisharp version I'm using.

My VS Code is up to date by the way.

@santosh Mine is named ms-vscode.csharp-1.15.0-beta3. It should be ms-vscode.csharp-1.14.0 for the current latest stable release.
I didn't want to type the full path because extension folders include version numbers as you said so it'll be different depending on when people are going to read the post. But OmniSharp's folder doesn't have "omnisharp" in its name so I'll edit the post to make it more clear.

Thanks a lot for this. I'll try it out later when I'm back home from
vacation.

@N3pp

On Thu, 22 Mar 2018, 04:59 N3pp, notifications@github.com wrote:

For those who also want to change the snippets:

Open

%USERPROFILE%.vscode\extensionsms-vscode.csharp-1.15.0-beta3\snippets\csharp.json
or

%USERPROFILE%.vscode\extensionsms-vscode.csharp-1.14.0\snippets\csharp.json
(for stable release)

then use "Find and Replace" (CTRL+H/F) with regex option enabled to replace
",\n ]"{"
with
{"
then apply for all then restart OmniSharp with command palette.

Make sure to backup csharp.json after changing it because OmniSharp
overwrites it on update.

@santosh https://github.com/santosh @d0rf3n https://github.com/d0rf3n

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/OmniSharp/omnisharp-vscode/issues/243#issuecomment-375172268,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFJCemQeyFX3pCYGeFmNdQN9ltLc3sdUks5tgyGMgaJpZM4IOsHl
.

Was this page helpful?
0 / 5 - 0 ratings