简体   繁体   中英

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:

在此处输入图像描述

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

在此处输入图像描述

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:

在此处输入图像描述

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.

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.json s you may have.

"Enable Editor Config Support" mentioned by @obezy fixed the problem for me. I had updated VS Code, and when I did, omnisharp started ignoring my formatting choices.

Settings -> Extensions -> C# Configuration -> Uncheck "Omnisharp: Enable Editor Config Support"

Make sure to restart omnisharp after making the change.

Go to settings.json and remove "omnisharp.path": "latest" if you have it, this fixed the issue for me make sure to restart omnisharp after by pressing ctrl+shift+p and type restart omnisharp

Disabling Omnisharp: Enable Editor Config Support fixed it for me, thanks @obezy and @puzzl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM