Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newline formatting options #313

Closed
CuddleBunny opened this issue May 12, 2016 · 18 comments
Closed

Newline formatting options #313

CuddleBunny opened this issue May 12, 2016 · 18 comments

Comments

@CuddleBunny
Copy link

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.

@MGillson
Copy link

I agree. I have found the forced formatting annoying. Is there any plans for configuring how the formatting works?

@unalone
Copy link

unalone commented Aug 8, 2016

Agree+1

We need rights to format code as what we need, not the fixed role!

@koppert
Copy link

koppert commented Sep 21, 2016

+1

@Thaina
Copy link
Contributor

Thaina commented 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

@bbugh
Copy link

bbugh commented Jan 7, 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.

@filipw
Copy link
Contributor

filipw commented Jan 7, 2017

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.

that's correct, this is planned to change though, the config file will be watched. it's tracked here OmniSharp/omnisharp-roslyn#366 (comment)

The formatting options don't seem to be documented anywhere, but you can see them all in the code:

I wrote a wiki page about dealing with omnisharp config here https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration%20Options but indeed, the individual options are just picked up from Roslyn directly.

@unalone
Copy link

unalone commented Jan 9, 2017 via email

@Thaina
Copy link
Contributor

Thaina commented Jan 9, 2017

@unalone Have you restart omnisharp?

@unalone
Copy link

unalone commented Jan 9, 2017 via email

@Thaina
Copy link
Contributor

Thaina commented Jan 9, 2017

@unalone First, I think you should not put that line in settings.json
Second, you may need to restart omnisharp too in addition to restart vscode
Third, if above don't work I wish you would try with a new fresh blank project

@unalone
Copy link

unalone commented Jan 9, 2017 via email

@unalone
Copy link

unalone commented Jan 9, 2017 via email

@filipw
Copy link
Contributor

filipw commented Jan 9, 2017

one more thing, regarding documentation - you can also use omnisharp.json from schemastore.org here http://json.schemastore.org/omnisharp

@DustinCampbell I think this issue can be closed as it seems everything needed here has been explained/addressed.

Omnisharp.json auto-reload is tracked in the omnisharp repo OmniSharp/omnisharp-roslyn#366 (comment)

@unalone
Copy link

unalone commented Jan 9, 2017 via email

@filipw
Copy link
Contributor

filipw commented Jan 9, 2017

it will - this is tracked in separate issue already OmniSharp/omnisharp-roslyn#717

@DustinCampbell
Copy link
Member

Sounds good @filipw. Closing this issue.

@Thaina
Copy link
Contributor

Thaina commented Jan 27, 2017

@filipw Have you include schemastore/omnisharp into jsonvalidator contribution point of vscode extension yet?

@DustinCampbell
Copy link
Member

Nope. That's my fault. I've commented on the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants