32

When I auto format with Resharper CTRL + ALT + SHIFT + F for lines longer than max line length (in my case say it's 80 characters), I get the following:

    return
        View(new ViewModel
        {
            Identifier = identifier,
            Files = service.AllFiles()
        });

But what I really want is it not to wrap after the "return" keyword (i.e. not have the return keyword on a line all on its own), like so:

    return View(new ViewModel
    {
        Identifier = identifier,
        Files = service.AllFiles()
    });

Does anyone know how to "configure" Resharper to make this happen? :)

Here's another example, here's what I'm seeing now:

    return
        repository.Session.CreateCriteria(typeof(SomeType))
                  .Add(Expression.Eq("Identifier", identifier))
                  .UniqueResult<SomeType>();

When I really want to see:

    return repository.Session.CreateCriteria(typeof(SomeType))
                     .Add(Expression.Eq("Identifier", identifier))
                     .UniqueResult<SomeType>();

UPDATE:

Here is "chop always":

    return View(new OrganisationFileLoadViewModel
    {
        Identifier = identifier,
        AllExistingOrganisationFiles = nmdsOrganisationFileLoadService.AllNMDSOrganisationFiles()
    });

Here is "chop if long":

    return
        View(new OrganisationFileLoadViewModel
        {
            Identifier = identifier,
            AllExistingOrganisationFiles = nmdsOrganisationFileLoadService.AllNMDSOrganisationFiles()
        });
4
  • Have you reported this bug to JetBrains? Commented Oct 29, 2014 at 9:18
  • I'm happy to if it's definitely a bug and not just a setting that I have incorrect...? Commented Oct 30, 2014 at 5:33
  • 1
    It's definitely a bug. Commented Oct 30, 2014 at 21:21
  • 3
    There are similiar issues already reported, although none of them were fixed - See youtrack.jetbrains.com/issue/RSRP-274953
    – Dresel
    Commented Jan 12, 2015 at 9:05

2 Answers 2

43

Resharper -> Options -> (Code Editing) C# -> Formatting Style -> Line Breaks and Wrapping

There are a lot of settings for line wrapping. The default for Wrap long lines is normally 120 characters. This may be triggering your break since you are set to 80 or Resharper 8.0 may have a newer option for return. The path above is for 7.0, but I believe it is the same or at least similar to 8.0.

The nice is that they show you examples for the changes you make so you don't have to test it right away.

4
  • 1
    I'm looking for an option to stop R# from putting the "return" keyword on a line on its own (as shown in my example above). I can't find that option in the section you're referring to. Commented Dec 11, 2013 at 4:03
  • 1
    This will just make the problem less likely to appear. It doesn't fix it. I have ReSharper set to break after 120 characters, but very long lines still break in awkward places.
    – siride
    Commented Dec 11, 2013 at 4:04
  • Also, I'm wrapping at 150 characters (fits on my 1920x1200 screen with big font nicely), but of course I still get wrapping occasionally and I find myself manually introducing intermediate variables just to avoid the wrapping "gunk" in R#, which is just terrible and I hate myself for doing it... Commented Dec 11, 2013 at 4:24
  • 1
    Yea, I wasn't necessarily saying it could be done. Just pointing to where the options were for line wraps. You may want to request an option for a future release with JetBrains.
    – TyCobb
    Commented Dec 11, 2013 at 16:17
2

There is no special option to turn "wrapping after return" OFF.

1) I was not able to reproduce a similar code formatting as shown in the first code snippet. However, I recommend you trying to change this setting to "Simple Wrap": ReSharper | Options | Code Editing | C# | Formatting Style | Line Breaks and Wrapping | Line Wrapping | Wrap invocation arguments.

2) In my case, the following changing helps me: ReSharper | Options | Code Editing | C# | Formatting Style | Line Breaks and Wrapping | Line Wrapping | Wrap chained method calls | Select "Chop always".

5
  • I've changed them all to "Simple Wrap", which didn't fix the break after the return... Commented Dec 13, 2013 at 3:09
  • Then I also changed them all back to "chop if long" that doesn't help either (return is still on a line by itself). Commented Dec 13, 2013 at 3:10
  • Then when I go to "chop always" I get the correct behavior (i.e. it doesn't put the return on a line on its own)! #WINNING, but then all my code looks terrible as it's always chopping, which makes what should be a small chained method call or object / collection initializer (i.e. should fit on one line) take up 3-4 lines unnecessarily... Commented Dec 13, 2013 at 3:14
  • What I really want is a) "chop if long" + c) "but don't put 'return' on a line on its own"... It seems like a defect to me, as it does the correct thing on "chop always" but the wrong thing on "chop if long"... Commented Dec 13, 2013 at 3:15
  • 2
    Added UPDATE above which shows the difference in behaviour between "chop always" and "chop if long"... Commented Dec 13, 2013 at 3:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.