question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Newline formatting options

See original GitHub issue

Looking for a way to configure auto-format for newlines. I’m a fan of this structure:

void foo() {
    if (something) {
        bar();
    } else {
        baz();
    }
}

However the current auto-format will place all my curly braces on a new line. I’ve noticed that both TypeScript and JavaScript have the options placeOpenBraceOnNewLineForControlBlocks and placeOpenBraceOnNewLineForFunctions.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:17
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
Thainacommented, Dec 23, 2016

In the meantimes we could create omnisharp.json which contains many property about omnisharp, and then restart omnisharp

This is what I use

{
	"FormattingOptions": {
		"NewLinesForBracesInLambdaExpressionBody": false,
		"NewLinesForBracesInAnonymousMethods": false,
		"NewLinesForBracesInAnonymousTypes": false,
		"NewLinesForBracesInControlBlocks": true, // You need to change this
		"SpaceAfterControlFlowStatementKeyword": false,
		"SpaceAfterComma": false
	}
}

However I would also support that omnisharp should also add vscode config contribution point

3reactions
bbughcommented, Jan 19, 2017

If you’re like me (and I know I am) you want the brackets on the same line for everything, not just control blocks. Here’s the full listing for all of the common squirrely bracket cases.

  1. Put this in the base of your project as omnisharp.json
  2. open the command palette and run Omnisharp: Restart Omnisharp.
{
	"FormattingOptions": {
		"NewLinesForBracesInLambdaExpressionBody": false,
		"NewLinesForBracesInAnonymousMethods": false,
		"NewLinesForBracesInAnonymousTypes": false,
		"NewLinesForBracesInControlBlocks": false,
		"NewLinesForBracesInTypes": false,
		"NewLinesForBracesInMethods": false,
                "NewLinesForBracesInProperties": false,
                "NewLinesForBracesInAccessors": false,
		"NewLineForElse": false,
		"NewLineForCatch": false,
		"NewLineForFinally": false
	}
}

Omnisharp doesn’t presently reload the omnisharp.json files automatically, so if you make changes while you’re in the editor, you’ll have to restart Omnisharp again.

It’s possible that I missed a couple of NewLine settings for edge cases. The formatting options don’t seem to be documented anywhere, but you can see them all in the code: http://source.roslyn.codeplex.com/#Microsoft.CodeAnalysis.CSharp.Workspaces/Formatting/CSharpFormattingOptions.cs,dac739b7b8a53984

HURRAY! This was the only thing left that was still bugging me about vscode. Thanks @Thaina for the PROTIP.

Read more comments on GitHub >

github_iconTop Results From Across the Web

newline Formatting Guidelines
You can, of course create bold, italic, and code highlighted inline marks. These can be created by selecting a word and using the...
Read more >
Newline - Wikipedia
Newline is a control character or sequence of control characters in character encoding specifications such as ASCII, EBCDIC, Unicode, etc. This character ......
Read more >
C# formatting options - .NET - Microsoft Learn
Learn about the code style options for formatting C# code files. ... The new-line options concern the use of new lines to format...
Read more >
Line Formats (Comparing and Merging Files) - GNU.org
The formats contain newline characters where newlines are desired on output. ... To specify a line format, use one of the following options....
Read more >
Adding a Newline Character To a String In Java - Xperti
A newline character, also known as the end of line (EOL), line break or line separator is a control character used to represent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found