LoginSignup
5
0

More than 5 years have passed since last update.

[Unity]MonoDevelopからVSCodeに移行しました その2

Last updated at Posted at 2018-01-10

コードの自動フォーマッティングの設定を行う

環境

Macbook Pro sierra 10.12.6
VSCode 1.19.1

やりたかったこと

editor.formatOnTypeを有効にすると以下のようにフォーマットされてしまう。

理想

>   public static bool IsSampleCode() {
>   >   if (true) {
>   >   >   // 左側がタブ
>   >   } else {
>   >   >   
>   >   }
>   }

現実

・・・・public static bool IsSampleCode()
・・・・{
・・・・・・・・if (true)
・・・・・・・・{
・・・・・・・・・・・・// 左側がスペース
・・・・・・・・}
・・・・・・・・else
・・・・・・・・{
・・・・・・・・・・・・
・・・・・・・・}
・・・・}

設定ファイルの追加

~/.vscode/extensions/ms-vscode.csharp-1.13.1
の下にbin/omnisharp/config.jsonがあると書かれている記事がありますが、
自分のMacにはありませんでした。

なので、
~/.omnisharp以下にomnisharp.jsonを作成

omnisharp.json(設定ファイル)の中身

{
    "FormattingOptions": {
            "NewLine": "\n",
            "UseTabs": true,
            "TabSize": 4,
            "IndentationSize": 4,
            "SpacingAfterMethodDeclarationName": false,
            "SpaceWithinMethodDeclarationParenthesis": false,
            "SpaceBetweenEmptyMethodDeclarationParentheses": false,
            "SpaceAfterMethodCallName": false,
            "SpaceWithinMethodCallParentheses": false,
            "SpaceBetweenEmptyMethodCallParentheses": false,
            "SpaceAfterControlFlowStatementKeyword": true,
            "SpaceWithinExpressionParentheses": false,
            "SpaceWithinCastParentheses": false,
            "SpaceWithinOtherParentheses": false,
            "SpaceAfterCast": false,
            "SpacesIgnoreAroundVariableDeclaration": false,
            "SpaceBeforeOpenSquareBracket": false,
            "SpaceBetweenEmptySquareBrackets": false,
            "SpaceWithinSquareBrackets": false,
            "SpaceAfterColonInBaseTypeDeclaration": true,
            "SpaceAfterComma": true,
            "SpaceAfterDot": false,
            "SpaceAfterSemicolonsInForStatement": true,
            "SpaceBeforeColonInBaseTypeDeclaration": true,
            "SpaceBeforeComma": false,
            "SpaceBeforeDot": false,
            "SpaceBeforeSemicolonsInForStatement": false,
            "SpacingAroundBinaryOperator": "single",
            "IndentBraces": false,
            "IndentBlock": true,
            "IndentSwitchSection": true,
            "IndentSwitchCaseSection": true,
            "LabelPositioning": "oneLess",
            "WrappingPreserveSingleLine": true,
            "WrappingKeepStatementsOnSingleLine": true,
            "NewLinesForBracesInTypes": true,
            "NewLinesForBracesInMethods": true,
            "NewLinesForBracesInProperties": true,
            "NewLinesForBracesInAccessors": true,
            "NewLinesForBracesInAnonymousMethods": true,
            "NewLinesForBracesInControlBlocks": true,
            "NewLinesForBracesInAnonymousTypes": true,
            "NewLinesForBracesInObjectCollectionArrayInitializers": true
            "NewLinesForBracesInLambdaExpressionBody": true,
            "NewLineForElse": true,
            "NewLineForCatch": true,
            "NewLineForFinally": true,
            "NewLineForMembersInObjectInit": true,
            "NewLineForMembersInAnonymousTypes": true,
            "NewLineForClausesInQuery": true
    }
}

設定ファイルを再読込

  1. VSCode上でcmd+shift+pで検索窓を出す
  2. 「restart omnisharp」でエンター

以上

記事検索用

formatter
tabs
vscode

5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0