C# FixFormatがない
久々に作りかけのUnity Projectを開き、拡張機能を覗くとあれまビックリ、C# FixFormatが消えていた。
調べてみるとdotnet-formatというCLIツールが良いらしいのだが、仕事でガッツリ書くわけでもないため楽をした。
omnisharp.json
プロジェクトルートにomnisharp.jsonというファイルを作り、FormattingOptionsで設定をカスタマイズできる。
設定項目一覧。
例:if文などの末尾にある中括弧を同じラインに置きたい。
omnisharp.json
{
"FormattingOptions": {
"NewLinesForBracesInLambdaExpressionBody": false,
"NewLinesForBracesInAnonymousMethods": false,
"NewLinesForBracesInAnonymousTypes": false,
"NewLinesForBracesInControlBlocks": false,
"NewLinesForBracesInTypes": false,
"NewLinesForBracesInMethods": false,
"NewLinesForBracesInProperties": false,
"NewLinesForBracesInObjectCollectionArrayInitializers": false,
"NewLinesForBracesInAccessors": false,
"NewLineForElse": false,
"NewLineForCatch": false,
"NewLineForFinally": false
}
}
prettierを使っている
JSなどを書いてるとdefaultFormatterをprettierに設定していることもあるだろう。
その場合はこうする。
settings.json
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[csharp]": {
"editor.defaultFormatter": "ms-dotnettools.csharp"
}
}
↧