visual-studio-code - 在 Visual Studio Code 上设置 OmniSharp 的 C# 格式选项?

标签 visual-studio-code code-formatting omnisharp

我正在尝试利用与 Visual Studio Code 的集成,但无法弄清楚如何设置 C# 格式选项。 Mac 上 OmniSharp exe 旁边的 config.json (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/jrieken.vscode-omnisharp/bin/packages/OmniSharp/config.json) 与 the standard OmniSharp config.json format 不匹配,因此设置大括号 + 换行符行为属性不起作用,例如methodBraceStyle。不过,设置 tabSize 等确实有效。

最佳答案

刚刚使用最新的omnisharp(开发分支)和与我的项目的.sln 位于同一文件夹中的omnisharp.json(粘贴在下面)使其正常工作。 它应该适用于所有 releases从 v1.9-beta18 开始,我只是从源代码编译,因为我不使用受支持的系统。

{
    "FormattingOptions": {
        "newLine": "\n",
        "useTabs": false,
        "tabSize": 4,
        "indentationSize": 4,

        "NewLinesForBracesInTypes": false,
        "NewLinesForBracesInMethods": false,
        "NewLinesForBracesInProperties": false,
        "NewLinesForBracesInAccessors": false,
        "NewLinesForBracesInAnonymousMethods": false,
        "NewLinesForBracesInControlBlocks": false,
        "NewLinesForBracesInAnonymousTypes": false,
        "NewLinesForBracesInObjectCollectionArrayInitializers": false,
        "NewLinesForBracesInLambdaExpressionBody": false,

        "NewLineForElse": false,
        "NewLineForCatch": false,
        "NewLineForFinally": false,
        "NewLineForMembersInObjectInit": false,
        "NewLineForMembersInAnonymousTypes": false,
        "NewLineForClausesInQuery": false,
    }
}

可用属性列在 FormattingOptions.cs 中在 omnisharp-roslyn repository .

关于visual-studio-code - 在 Visual Studio Code 上设置 OmniSharp 的 C# 格式选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34407922/

相关文章:

javascript - VSCode 显示数组中的元素索引

Eclipse 格式化程序在空注释行中添加空格

editor - 在 Notepad++ 中重新格式化代码

c# - 为什么 Visual Studio 2010 C# Express 不能正确格式化嵌套代码?

c# - 智能感知不再有效

c# - 如何配置 omnisharp syntastic 语法检查器更宽松?

visual-studio-code - 使用远程 ssh 扩展时,VSCode 无法安装扩展远程 ssh 服务器

regex - 如何在积极回顾后排除事件?

c# - OmniSharp 自动完成类名,而不仅仅是方法/属性?

C++程序在vs代码中出错时使用haskell编译器