Kudos on the new Code Formatter. It's a great step forward. It's fast, and it works pretty well. I'm getting close to being able to abandon a certain other coding tool that still manages to edge out this new code formatting engine (but whose other features fall far behind CodeRush for Roslyn). Their product slows everything down even when I have everything turned off except for the Code Formatter, so I am really keen to stop using their tool altogether.
Here's a link to my original Code Formatter request for comparison: Code Formatter in CodeRush
The simple formatting requests in that have been implemented, but the formatter has trouble with embedded anonymous methods, and combinations with chaining:
For instance, what I want is:
C#MyServiceRequest request = new MyServiceRequest()
{
InvoiceId = myInvoiceId,
MyStuffArray = calculatedStuff
.Select(myItem => new MyStuff()
{
StuffId = myItem.StuffId,
ProductLookupId = myItem.ProductLookupId,
})
.ToArray(),
};
The closest I can get after playing with the formatting settings is:
C#MyServiceRequest request = new MyServiceRequest()
{
InvoiceId = myInvoiceId,
MyStuffArray = calculatedStuff
.Select(myItem =>
new MyStuff()
{
StuffId = myItem.StuffId,
ProductLookupId = myItem.ProductLookupId,
})
.ToArray(),
};
There are a couple big issues with this:
First, I can only get the formatter to leave "new MyStuff" on the same line as the lambda expression if I choose No Wrap. I suppose this is okay and I can just wrap stuff on my own, assuming that the code formatter wouldn't unwrap code I've specifically wrapped (except that it does, to follow after I am done with this issue.)
Second, note that the .ToArray should be chaining with .Select, and should be indented at the same level as .Select.
With wrapping turned off, what I want:
C#Func<int> func = new Func<int>(() =>
{
int a = 4 + 5;
return a;
});
What I get:
C#Func<int> func = new Func<int>(() => {
int a = 4 + 5;
return a;
});
I've very explicitly set that braces are always on a new line in every place I can possibly set it, so I should never be able to see it happen.
I've attached my settings for CodeRush and the formatting settings for that certain other extension.
Another thing I've noticed is that the "tolerance" stuff is great for respecting the Tolerance level. However, if the tolerance level is not met then it appears to fall back on the default C# formatting engine, which messes with the indentation again. I think that the tolerance level should be a measure of "don't touch my wrapping" but still apply any other applicable formatting (such as indentations). As an example, set up Object Initializer with tolerance of 2 with indent level of 1,1,2, and create an initializer with two parameters, but still follow the multi-line rules. You'll see that the indentation of the braces falls back to 0 indentation.
Obviously Code Formatting is very important to me, so I'm open to being your beta test guinea pig for code formatting types of features.
Hi Jason,
Thanks for the code snippets and CodeRush settings.
I have created new tickets for two requests - Code Formatter - Open brace on new line and Code Formatter - .ToArray should be chaining with .Select, and should be indented at the same level as .Select. We will process them as a separate issue report.
As for other requests - I have added a corresponding item to our backlog and we will consider this improvement for future updates.