[英]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.我已经在 Unity 中从事一个项目几个月了,并且一直在使用 Omnisharp 来格式化 C# 代码。 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.我注意到的唯一不同之处是在 class 和方法定义、
if
/ then
语句和循环中的大括号前插入了一个新行。 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.在
Start()
之后和左花括号之前有一个新行。 The omnisharp.json
file at the root of the project looks like this:项目根目录下的
omnisharp.json
文件如下所示:
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.我想知道为什么格式化程序似乎突然忽略了
NewLine...
设置。 Intellisense is still working and files are indeed being formatted, just not in a way that matches the settings I have configured. Intellisense 仍在工作,文件确实正在格式化,只是与我配置的设置不匹配。
I tried changing indentationSize to 4 in the omnisharp.json
and restarted Omnisharp.我尝试在
omnisharp.json
indentationSize 更改为 4,然后重新启动 Omnisharp。 That worked and made it indent 4 spaces.这行得通并使它缩进了 4 个空格。 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.因此,格式化程序似乎从我的
omnisharp.json
获得了一些东西,但它只是忽略了所有NewLine...
以前没有的设置。
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我遇到了同样的问题,发现了一个 github 问题和一个对我有用的解决方法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.我回滚到 VS Code C# 扩展
v1.25.0
,这解决了这个问题。
Reinstalling the C# extension to v1.25.0
from v1.25.2
fixed it for me.将 C# 扩展从
v1.25.2
重新安装到v1.25.0
为我修复了它。
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.我的理解是,新添加的 omnisharp 设置“启用编辑器配置支持”在默认情况下处于启用状态,这使得它会忽略您可能拥有的任何
omnisharp.json
。
"Enable Editor Config Support" mentioned by @obezy fixed the problem for me. @obezy 提到的“启用编辑器配置支持”为我解决了这个问题。 I had updated VS Code, and when I did, omnisharp started ignoring my formatting choices.
我更新了 VS Code,当我更新时,omnisharp 开始忽略我的格式选择。
Settings -> Extensions -> C# Configuration -> Uncheck "Omnisharp: Enable Editor Config Support"设置 -> 扩展 -> C# 配置 -> 取消选中“Omnisharp:启用编辑器配置支持”
Make sure to restart omnisharp after making the change.确保在进行更改后重新启动 omnisharp。
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
Go 到 settings.json 并删除
"omnisharp.path": "latest"
如果你有它,这解决了我的问题确保通过按ctrl+shift+p
并键入restart omnisharp
Disabling Omnisharp: Enable Editor Config Support
fixed it for me, thanks @obezy and @puzzl禁用
Omnisharp: Enable Editor Config Support
为我修复了它,感谢@obezy 和@puzzl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.