Reputation: 1849
I find I am consistently fighting with ReSharper's Complete Statement (Ctrl+Shift+Enter) behavior and I wonder if there is a way to customize it.
What happens is that I will be editing some code, for example:
var a = 0;
var b = 1;
And then I want to add this to it:
var a = 0;
using (var frob = new Thingy())
{
a = frob.Foo();
}
var b = 1;
If I don't use the "using" live template, and just type it in, I hit Complete Statement after typing thingy, and Resharper will copmlete it to this:
var a = 0;
using (var frob = new Thingy())
var b = 1;
So, I wonder, is there a way to tell it to always create new braces rather than trying to insert the next line into whatever statement you are adding?
This is using ReSharper 8.1. I've been using it since version 4 and this feels like a new problem, so perhaps they have altered the default behavior.
UPDATE: Given Thomas Weller's answer, and @Resharper's response on Twitter, I did some more investigating.
There seems to be a discrepancy here. If you look at the docs for Complete Statement it clearly states:
With Complete Statement, instead of this tricky procedure, you only have to press Ctrl+Shift+Enter, and ReSharper will automatically insert a closing parenthesis, as well as both braces, and put the caret right where you can proceed with writing the method body In similar ways, Complete Statement is known to work with the following language constructs:
[...] Statements: if, while, do, switch, using, lock, continue, break, and return statements; case and default clauses; conversion of single-line statements to block statements.
In testing this out some, I noticed that the behavior for an if
statement is as expected (it adds the braces and places the carat on a new line inside). So does switch
and checked
.
On the other hand, while
, using
, and fixed
behave as in my example above, where it co-opts the next line of code to be used instead of a new block.
This seems rather inconsistent. Either the docs should be updated, or the behavior should be the same for all statement types.
So, it seems this is more appropriate as a bug report than an SO question. Here is the link to the bug if anyone is interested in upvoting it. :)
Upvotes: 2
Views: 427
Reputation: 11717
You're not using R#'s 'Complete Statement' feature as intended, so the tool cannot exactly figure out what you want to achieve.
Complete the using
statement with the Live template as soon as the template becomes available in IntelliSense, then it will give you the brackets. The Live template will then lead you through typing in the various parts of the statement by highlighting/setting the cursor at the appropriate parts one after the other (don't worry, you won't need to touch the mouse).
Alternatively, Live templates are always accessible and editable via the Live templates explorer (Live templates are similar to 'normal' code templates). But I would not recommend that for predefined ones, unless you have a strong reason to do so.
Upvotes: 3