4

Is there any way to disable ReSharper Web Form/MVC (.aspx) Code Formatting on Brace ( } ) Completion?

It is really frustrating and most of the time is not what I want. For instance if I have:

<% if (CurrentUser.IsRole(Helper.UserRole.Agent)) { %>
   <%= Html.LinkTo("sign out", SessionRoutes.Logout, null, new { @class = "sign" }) %>
<% } else { %>
   ...
<% } %>

as soon as I type the last <% } it formats like this:

<% if (CurrentUser.IsRole(Helper.UserRole.Agent))
  { %>
 <%= Html.LinkTo("sign out", SessionRoutes.Logout, null, new { @class = "sign" })%>
  <% }
  else
  {%>

  <%
  }%>

I have looked through ReSharper options, but cannot find any setting suitable. It's driving me nuts! To get around it I either have to paste the bracket, sometimes be lucky enough that ctrl+z works or type <{ then insert the % then space :S

I'm sure anybody who has worked with ReSharper and web forms lately will know what I'm talking about.

Thanks

GONeale
  • 26,302
  • 21
  • 106
  • 149

3 Answers3

3

First, you should change options for braces layout to match your style. Go to ReSharper | Options > Languages > C# > Formatting style > Braces Layout > Braces Layout and change option "Other" to "At end of line (K&R style)".

Next, please note that there is indeed a bug that sometimes causes ReSharper to insert linebreaks after <% or before %>. This bug is fixed in the internal builds and should be in the next EAP (later that 2011-jun-7) as well as in the future 6.0 betas/release.

If you wish you can completely disable auto-format in ReSharper options (but this would affect not only ASP.NET, but regular C# files as well). Go to ReSharper | Options > Editor and switch off Auto-format on semicolon and Auto-format on closing brace.

Hope this helps :)

Dmitry Osinovskiy
  • 9,999
  • 1
  • 47
  • 38
  • Thanks Dmitry, I will take a look at the Braces Layout option, but look forward to next EAP. – GONeale Jun 08 '11 at 05:32
  • 1
    Dmitry, my latest woe in 6.0 RTM is all the tag completion in Razor files, can this be turned off separately? There really should be granualar control for all this. I love ReSharper, but I really don't like all the html coding assistance, now with the CSS class assist it often picks class names and auto completes before I finish typing, then I have two written :( – GONeale Jul 08 '11 at 01:00
  • Also Dmitry sorry to bother you, but quite a few people are having problems with intellisense / and/or performance with 6.0, I hope you've seen this thread.. because I too concur, fast typing speed causes a big issue and a lot of malformed html with intellisense http://devnet.jetbrains.net/thread/305694;jsessionid=F2D33679D73D37997A9C27BA7824687C?tstart=0 and http://devnet.jetbrains.net/message/5308690#5308690 – GONeale Jul 08 '11 at 01:09
  • Graham, I'm the same Dmitry who is in that thread, and yes, right now I'm busy with correcting issues mentioned in that thread. Option to switch off HTML intellisense also will be added. If you have questions/suggestions, please answer my posts on the devnet.jetbrains.net, stackoverflow is not the right forum for these things :) – Dmitry Osinovskiy Jul 11 '11 at 13:55
1

Are you sure it's Resharper that's doing the formatting? Visual Studio itself also has an "Automatically format completed block on }" option.

Tools | Options > Text Editor > C# > Formatting

Hans Kesting
  • 38,117
  • 9
  • 79
  • 111
1

Feels like this is a known issue reflected in these two bug reports: http://youtrack.jetbrains.net/issue/RSRP-193396 and http://youtrack.jetbrains.net/issue/RSRP-178877 Please vote for them. Can't guarantee any fix schedule right now but I hope we're able to fix sooner rather than later.

Jura Gorohovsky
  • 9,886
  • 40
  • 46