Search code examples
c#visual-studio-codevscode-extensionsomnisharp

VSCode Omnisharp ignores format settings in omnisharp.json


I've been working on a project in Unity for months now and have been using Omnisharp to format C# code. Just today, the formatter started formatting my code differently than before and I don't know why.

The only thing I've noticed that is different is the inserting of a new line before braces in class and method definitions, if/then statements, and loops. Before, I had it configured to format all of those things like this:

enter image description here

Now suddenly today they're all being formatted like this:

enter image description here

With a new line after the Start() and before the opening curly brace. The omnisharp.json file at the root of the project looks like this:

enter image description here

I haven't changed it since starting to work on this project. I would like to know why the formatter seems to suddenly ignore the NewLine... settings. Intellisense is still working and files are indeed being formatted, just not in a way that matches the settings I have configured.

I tried changing indentationSize to 4 in the omnisharp.json and restarted Omnisharp. That worked and made it indent 4 spaces. So it seems the formatter is getting something from my omnisharp.json, but it's just ignoring all the NewLine... settings when it wasn't before.

It's not a huge deal, it's just a little annoying to have my code being formatted differently than it has been all this time, and more annoying to not know why that's happening.


Solution

  • I've had the same issue, found a github issue with a workaround that worked for me https://github.com/OmniSharp/omnisharp-vscode/issues/5446

    I rolled back to the VS Code C# extension v1.25.0 and this fixed the issue.

    Reinstalling the C# extension to v1.25.0 from v1.25.2 fixed it for me.

    My understanding is that the newly added omnisharp setting "Enable Editor Config Support" is on by default which makes it ignore any omnisharp.jsons you may have.