1

I am reading everywhere that Omnisharp now supports configuration from the .editorconfig. However, everything that I've tried does not seem to work. Here is the most slim test that I can come up with, but what is wrong here?

omnisharp.json

{
    "RoslynExtensionsOptions": {
        "enableAnalyzersSupport": true
    },
    "FormattingOptions": {
        "enableEditorConfigSupport": true
    }
}

.editorconfig

root = true

[*]
insert_final_newline = true
indent_size = 2
indent_style = tab
tab_width = 2
trim_trailing_whitespace = true
charset = utf-8

[*.cs]
csharp_new_line_before_else = true

Program.cs

using System;

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isPostCrisis = true;

            if (isPostCrisis) {
                Console.WriteLine("Hello World!");
            } else {
                Console.WriteLine("Welcome to the Multiverse!");
            }
        }
    }
}

I can see that "enableAnalyzersSupport": true rule is working, but I don't see any feed back for csharp_new_line_before_else = true.

enter image description here

I am using:

  • VS Code v1.42.1
  • C# extension for VS Code v1.21.12
    • Omnisharp server v1.34.13 (included through parent extension)

Here is a repo of the test project: https://github.com/roydukkey/moist/tree/stackoverflow/60607975

roydukkey
  • 3,149
  • 2
  • 27
  • 43
  • There is a new line before *else*. – Hans Passant Mar 09 '20 at 21:57
  • @HansPassant I've updated the example and still don't see an error or warning. – roydukkey Mar 10 '20 at 13:32
  • 1
    It is not meant to generate an error, it helps you [format your code](https://stackoverflow.com/questions/29973357/how-do-you-format-code-in-visual-studio-code-vscode). – Hans Passant Mar 10 '20 at 13:40
  • In .NET 5 you can set the `EnableCodeStyleInBuild` option to true in the csproj file. In my editor, this also causes the style errors to be highlighted whereas otherwise they are not. Have you tried it with this setting? https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#enforcecodestyleinbuild – cdimitroulas Oct 07 '21 at 08:45

0 Answers0