I'm attempting to take advantage of the integration with Visual Studio Code, but can't figure out how to set the C# formatting options. The config.json right next to the OmniSharp exe on my Mac (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/jrieken.vscode-omnisharp/bin/packages/OmniSharp/config.json) doesn't match the standard OmniSharp config.json format, so setting the brace + newline behavior properties isn't working, e.g. methodBraceStyle. It does work to set the tabSize, etc., however.
Just got this to work using the latest omnisharp (dev branch) and the omnisharp.json (pasted below) in the same folder as my project's .sln.
It should work with all releases since v1.9-beta18, I just compiled from source because I don't use a supported system.
{
"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,
}
}
The available properties are listed in FormattingOptions.cs in the omnisharp-roslyn repository.
From Configuration Options on the omnisharp-roslyn wiki:
At startup, OmniSharp obtains the configuration options using the following (hierarchical) order:
- its own hardcoded defaults
- Environment variables
- Command line arguments
- An
omnisharp.jsonfile located in%USERPROFILE%/.omnisharp/- An
omnisharp.jsonfile located in the working directory which OmniSharp has been pointed atEach of the configuration sources, can overwrite any of the settings set by the previous source.
To summarize the above configuration locations according to a blog article by one of the developers:
config.json in the OmniSharp extension's directory. It is not recommend to modify this file.omnisharp.json in %USERPROFILE%\.omnisharp\ (or ~/.omnisharp/) for user-specific settings.omnisharp.json in a project directory for project-specific settings.Testing with v1.21.11 of the ms-vscode.csharp extension on Visual Code v1.42.0, it seems OmniSharp only applies omnisharp.json found in the root of a workspace folder, not descendant directories.
The C# extension for Visual Studio Code also supports EditorConfig, which you can enable via one of the following methods:
File → Preferences → Settings → Extensions → C# configuration → OmniSharp: Enable Editor Config Support
settings.json...
{
"omnisharp.enableEditorConfigSupport": true,
}
omnisharp.json
{
"FormattingOptions": {
"enableEditorConfigSupport": true
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With