2

When I try to initialize an object using the Object Initializer, ReSharper always inserts a lot of whitespace.

public class Bar
{
    public void Adam()
    {
        var foo = new Foo
                      {
                          First = "yes",
                          Second                              = 
                      };
    }
}

When I replace the ; character after the intializer, my code will then be formatted as below:

public class Bar
{
    public void Adam()
    {
        var foo = new Foo
                      {
                          First = "yes",
                          Second = "no"
                      };
    }
}

Follow these steps to reproduce the problem (Thank you Piers Myers):

  • Place your cursor at the indented position after the opening brace for example (on an empty line you can place your cursor either at the very beginning of the line or at the indentation level Resharper/VS thinks you should be using)
  • Press CTRL+Space, CTRL+ALT+Space or SHIFT+ALT+Space. It will insert spaces before your cursor to pad it out but it will also add the same amount of spaces after your cursor which is incorrect.

Does anyone know what is causing the initially generated whitespace? Perhaps which settings I might have configured wrong?

Myrtle
  • 5,761
  • 33
  • 47
  • When you say causing "this", which bit do you mean - the lots of whitespace to start with, or the reformatting when you replace the `;` ? – AakashM Jun 14 '12 at 08:12
  • @AakashM I mean the lots of whitespace to start with. Possibly causing my carret to move outside the visual boundaries. – Myrtle Jun 14 '12 at 08:24
  • I think it would help if you describe exactly what keystrokes you do and when the whitespace appears. Also check the [bugtracker](http://youtrack.jetbrains.com/issues/RSRP), if you haven't already. – AakashM Jun 14 '12 at 08:33
  • @AakashM I did not thought of identifying this as a bug. I will update the question with the keystrokes and investigate the bugtracker. – Myrtle Jun 14 '12 at 10:51
  • I can reproduce your problem using Resharper 5.1 and VS2008. If you place your cursor at the indented position after the opening brace for example (on an empty line you can place your cursor either at the very beginning of the line or at the indentation level Resharper/VS thinks you should be using) and press CTRL+Space, CTRL+ALT+Space or SHIFT+ALT+Space, it will insert spaces before your cursor to pad it out but it will also add the same amount of spaces after your cursor which is incorrect. – Piers Myers Jun 14 '12 at 14:58
  • @PiersMyers Thanks for writing this out. I will file a bug report at Jetbrains. – Myrtle Jun 15 '12 at 06:10
  • @Aphelion I have tried the same thing in VS2010 and Resharper 6.1 and it doesn't seem to add the extra spaces so the issue has probably been fixed. – Piers Myers Jun 17 '12 at 12:26
  • @PiersMyers I using Resharper 6.1.1000.82 on visual studio 2008. Perhaps it is indeed a bug in the 2008 edition. – Myrtle Jun 18 '12 at 07:07

1 Answers1

0

This problem has been confirmed on these installations:

  • Resharper 5.1 VS2008 (By Piers Myers)
  • Resharper 6.1 VS2008 (By Me)

However the probleem seems to be gone on these installations:

  • Resharper 6.1 VS2010 (By Piers Myers)
  • Resharper 7.0EAP VS012 (By Me)

Therefore it appears to be a bug of ReSharper in combination with the VS2008 IDE.

Myrtle
  • 5,761
  • 33
  • 47