This Question is Not Answered

1 "correct" answer available (4 pts) 2 "helpful" answers available (2 pts)
6 Replies Last post: May 20, 2013 5:56 PM by Amith George  
Amith George Newbie 5 posts since
Apr 25, 2013
Currently Being Moderated

May 14, 2013 4:12 AM

Code formatting - help needed

This is how Visual Studio 2012 currently formats my code. This is formatting is applied if paste new code in, or if I explicitly choose to format the document using VS shortcut Ctrl K,D.

 

    private static void MyFunc()
    {
        var ints = new List<int>();
        var diffInts = ints.Select(x => new
        {
            Prop1 = x,
            Prop2 = x * x
        })
                           .ToList();

 

        diffInts.ForEach(x =>
        {
            if (x.Prop2 > x.Prop1)
            {
                Console.WriteLine("Whatever!");
            }
        });
    }

 

However I have configured R# (7.1.latest) to format the code as below

 

    private static void MyFunc()
    {
        var ints = new List<int>();
        var diffInts = ints.Select(x => new
                                        {
                                            Prop1 = x,
                                            Prop2 = x*x
                                        })
                           .ToList();

 

        diffInts.ForEach(x =>
                         {
                             if (x.Prop2 > x.Prop1)
                             {
                                 Console.WriteLine("Whatever!");
                             }
                         });
    }

 

R# kicks in its formatting only if I terminate a statement (ie using `;`) or if I terminate a block (ie using `}`). Otherwise I need to explicitly format the document using the R# shortcut Ctrl+Atl F.

 

This is quite tedious as I frequently move code around, the code looses all formatting (ie resets to VS style formatting).

 

What can I do to get rid of this annoyance? I presume I will need to share some R# settings values as well as some VS settings values. Please let me know which ones (and if possible, in which sub section I can find those settings)

Alex Berezoutsky JetBrains 580 posts since
Feb 18, 2011
Currently Being Moderated
May 14, 2013 5:40 PM in response to: Amith George
Re: Code formatting - help needed

Hi,

 

I'm sorry but I didn't understand the question well - would you like to keep the ReSharper formatting (code sample #2) in all scenarios? If so, could you please describe in detail, when and after what actions the formatting is set to the VS one (like, what do you mean by 'move code around')?

 

Thanks in advance!

Alex Berezoutsky JetBrains 580 posts since
Feb 18, 2011
Currently Being Moderated
May 20, 2013 5:25 PM in response to: Amith George
Re: Code formatting - help needed

Hello Amith,

 

It took some time to check it out, and I beleive there's no option in ReSharper for now. However, you may map 'CodeCleanupSilent' command to any keymap you'd like and select 'Refomat Code' for a silent code cleanup profile. At least it will allow you reformat code more easily after pasting.

 

Hope it helps.

Thanks!

Alex Berezoutsky JetBrains 580 posts since
Feb 18, 2011
Currently Being Moderated
May 20, 2013 5:44 PM in response to: Amith George
Re: Code formatting - help needed

Amith,

 

If you'd like to have both "Paste" and "Silent Code Cleanup' commands to be mapped to a single key, you may use VS macros for that.

Still, you're welcome to log this request in your YouTrack here: http://youtrack.jetbrains.com/issues/RSRP

 

Thank you!

More Like This

  • Retrieving data ...