Note:

This site is no longer used and is in read-only mode. Instead please go to our new Moodle Developer Resource site.

Setting up VSCode

From MoodleDocs
Revision as of 19:54, 6 August 2019 by Marcus Green (talk | contribs)

VSCode stub https://en.wikipedia.org/wiki/Visual_Studio_Code

Location of function/class braces

According to the Moodle coding guidelines

https://docs.moodle.org/dev/Coding_style#Functions_and_methods_2

"the brace should always be written on same line as the function name."

By default VSCode uses the PSR coding convention that braces appear on the next line when the internal formatter is used. (Cmd -K-F on OSX). This can be changed via a file called

omnisharp.json

Which can be placed either in the root of the project or as a configuration in the users home dir, e.g. ~/.omnisharp/omnisharp.json

The following example will put braces on the same line as the function/class declaration

{

   "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
   }

}