Placing auto-inserted braces on a new line

If I type "if(x)", press enter, then type "{", a closing } brace is automatically added. But it's added on the same line, which means I have to press enter once more to enter the body of the statement. For example, after typing "if(x)<enter>{" I get the following:

if(x)
{}

Is there any way to force Resharper to place the closing brace on a new line like it does in Visual Assist X? eg.

if(x)
{
<- cursor is here
}

5 comments

Hello Adrian,

I'm afraid at the moment there's no way to force the closing brace to be
inserted on the next line. Could you please clarify why do you need such
behavior? When entering an if statement, you will have to press Enter anyway
in order to enter the code for the corresponding branch. Also, after typing
'if(x)' you can click ReSharper | Edit | Complete Statement (or press the
corresponding shortcut) and ReSharper will turn it into
if(x)
{
  |
}

Let me know if this helps. Thank you!

Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

If I type "if(x)", press enter, then type "{", a closing } brace is
automatically added. But it's added on the same line, which means I
have to press enter once more to enter the body of the statement. For
example, after typing "if(x)<enter>{" I get the following:

if(x)
{}
Is there any way to force Resharper to place the closing brace on a
new line like it does in Visual Assist X? eg.

if(x)
{
<- cursor is here
}
---
Original message URL:
http://devnet.jetbrains.net/message/5300477#5300477



0

It's more of an annoyance than anything else. Before I can start typing the body of the if statement, I have to press enter twice. After I press enter the first time, I get this:

if(x)
{|}

The vertical bar represents the caret. I have to press enter again to get what I wanted in the first place:

if(x)
{

|
}


The point is that if I type "if(x)" followed by an enter, then it means I must want to type the body of the if statement. There is never a case where I'd want to write the following code:


if(x)
{xyz();}


It's always the case that I want the code to look like this: (and I've set the associated options under Options > C# > Formatting Style)


if(x)
{

xyz();
}


Which is why it's silly to place the cursor immediately after the first brace when I hit enter because it just forces me to hit enter again to get the braces in a usable position. It's an annoyance, especially since Visual Assist X is smart enough to place the caret and the braces in the right places after I hit enter the first time.

0

Hello Adrian,

The behavior that you're observing is not the expected one. Could you please
attach a small screencast demonstrating it? You can take a screencast using
http://www.techsmith.com/jing/. Also, could you please export your code style
settings as an XML file (under ReSharper | Options | Languages | Common |
Code Style Sharing) and attach the file here? Thank you!

Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

It's more of an annoyance than anything else. Before I can start
typing the body of the if statement, I have to press enter twice.
After I press enter the first time, I get this:

if(x)
{|}
The vertical bar represents the caret. I have to press enter again to
get what I wanted in the first place:

if(x)
{
|
}
The point is that if I type "if(x)" followed by an enter, then it
means I must want to type the body of the if statement. There is never
a case where I'd want to write the following code:

if(x)
{xyz();}
It's always the case that I want the code to look like this: (and I've
set the associated options under Options > C# > Formatting Style)

if(x)
{
xyz();
}
Which is why it's silly to place the cursor immediately after the
first brace when I hit enter because it just forces me to hit enter
again to get the braces in a usable position. It's an annoyance,
especially since Visual Assist X is smart enough to place the caret
and the braces in the right places after I hit enter the first time.

---
Original message URL:
http://devnet.jetbrains.net/message/5300530#5300530



0

This seems to happen in both VS2010 and VS2008 using Resharper 5.1.3 so I'm not sure whether this is a bug, a configuration error, or intended behaviour.

Resharper 5.1.3:
http://www.youtube.com/watch?v=5-UL07n9c2w

Visual Assist X:
http://www.youtube.com/watch?v=addZEIrVp7I

As you can see in VAX, the moment I type the opening brace, the closing brace is added on a new line and the caret is placed in the correct position to start typing the body. After I type the opening brace in Resharper, it places the closing brace on the same line (meaning I have to hit enter again).

And this has highlighted another annoyance - VAX will correctly auto-format code when it inserts braces, while Resharper will not. In VAX, "if(x+1==2)" is correctly formatted and spaced to "if (x + 1 == 2)" but Resharper doesn't. Both VAX and Resharper correctly format "int x=0" to "int x = 0" upon typing the semicolon, however.

I've attached the exported XML file. I appreciate the time you're taking to help with this issue.



Attachment(s):
resharper.xml
0

+1

"Adrian Tsai"  wrote in message
news:6446561.72861303214321037.JavaMail.devnet@domU-12-31-39-18-36-57.compute-1.internal...

This seems to happen in both VS2010 and VS2008 using Resharper 5.1.3 so I'm
not sure whether this is a bug, a configuration error, or intended
behaviour.

Resharper 5.1.3:
http://www.youtube.com/watch?v=5-UL07n9c2w

Visual Assist X:
http://www.youtube.com/watch?v=addZEIrVp7I

As you can see in VAX, the moment I type the opening brace, the closing
brace is added on a new line and the caret is placed in the correct position
to start typing the body. After I type the opening brace in Resharper, it
places the closing brace on the same line (meaning I have to hit enter
again).

And this has highlighted another annoyance - VAX will correctly auto-format
code when it inserts braces, while Resharper will not. In VAX, "if(x+1==2)"
is correctly formatted and spaced to "if (x + 1 == 2)" but Resharper
doesn't. Both VAX and Resharper correctly format "int x=0" to "int x = 0"
upon typing the semicolon, however.

I've attached the exported XML file. I appreciate the time you're taking to
help with this issue.

---
Original message URL: http://devnet.jetbrains.net/message/5300951#5300951

0

Please sign in to leave a comment.