RSS

ReSharper 5 – Coding Assistance & Templates

31 Aug

Coding Assistance in ReSharper is great,  meanwhile templates are one big disappointment.
They should be done much better, but I’ll talk about them latter. First I’ll focus
on what ReSharper brings.

In code editor you notice some nice icons that appear next to the caret location.
This are context actions, which are allowing you to quickly edit, refactor, navigate,
fix or generate code. Very handy, indeed. Here are icons that you should pay attention
to:

alt - for code editing
alt - for refactoring
alt - for navigation
alt - for quick fixes
alt - for code generating

Context actions are accessible by clicking the icon or by pressing Alt+Return. Below
is an example how context actions looks like.

Context Action

It’s also hard to miss hints above context actions. They usually appear in association
with missing using directives, like shown on a picture below.

Action Hint

When a reference to assembly is missing, this hint doesn’t appear. However, ReSharper
is able to add a correct reference to project references.

Once you start typing you’ll notice that IntelliSense from Visual Studio has been
replaced with a new one. Don’t panic, this is ReSharper’s default option and can
be later changed in Options dialog. New IntelliSense is much better from the one
in Visual Studio and what I especially like is code completion. It provides three
different modes:

  • Symbol Completion (Ctrl+Space) – completes
    names of classes, methods, variables, keywords, and any other symbols that are available
    within the current visibility scope (including extension methods that were
    previously imported).

    Symbol Completion

  • Smart Completion (Ctrl+Shift+Space)
    - filters the list of types, methods, and variables to match the expected type of
    an expression. It works anywhere as long as ReSharper can determine the expected
    type of the expression, for example, right-hand sides of assignments, variable initializers,
    or return statements. If several return types are possible, ReSharper detects the
    most recently used symbol of an applicable type and automatically selects it in
    the lookup list. Smart Completion can also suggest creating anonymous delegates,
    lambda expressions, and regular methods, as well as local variables for out parameters.
    In addition to that, in object initializers, Smart Completion suggests fields/properties
    that were not yet assigned a value.

    Smart Completion

  • Import Symbol Completion (Shift+Alt+Space) –
    displays all types that match a given prefix regardless of what namespace they belong
    to (as opposed to Symbol Completion, which only completes names of currently visible
    types). Import Symbol Completion automatically inserts appropriate namespace import
    directives to the current file if a selected type has not been imported previously.
    It also works after dot with extension methods and puts necessary using directives.

    Import Symbol Completion

In general, this IntelliSense is quite a monster, but it takes a little bit to get
used to it.

Wondering what’s more? There’re some really nice sugars like

  • Complete Statement (Ctrl+Shift+Enter)
    – is a feature that inserts necessary syntax elements (braces, semicolons etc.)
    and gets you in position to start the next statement.

    Complete Statement

  • Parameter Information – shows up the tooltip regarding the current parameter.
    I find this very useless. Maybe a picture tells thousand words why. But that’s just
    my opinion.


    Parameter Information

  • Quick Documentation… – shows up a tooltip with
    a quick documentation. Very handy.

    Quick Documentation

  • Generate Code (Alt+Ins) - this functionality provides you with options to
    generate code from editor and solution tree. With it, your able to generate classes,
    interfaces, constructors, delegates, override members,… Oh god, I love this. No
    more “Add new dialog”.

    Code Generating #1
    Code Generating #2 

  • Insert Live Template… – allows you to insert a code template. Tough a list
    of predefined templates is very short (around 30 templates all together), it’s possible
    to create your own templates with ease.


    Insert a Template

  • Surround With Template… – gives you an ability to surround your code with
    region, compiler directives, code block,… At times, this could be useful, but
    that’s up to you.
    Surround With
  • Extend Selection (Ctrl+W) – allows
    you to successively select expanding blocks of code so that you can easily select
    any expression in the code by placing the caret somewhere inside it and pressing
    Ctrl+W a few times
  • Shrink Selection (Ctrl+Shift+W) – opposite of “Extend Selection”
  • Duplicate Text (Ctrl+D) – duplicates selected text if any, otherwise it duplicates current line.
  • Comment with Line Comment(Ctrl+/) – comments selected text with // in front of each line. This functionality doesn’t work correct with XML comments and is also provided by Visual Studio.
  • Comment with Block Comment (Ctrl+Shift+/) – comments the selected text with /* and */ block.
  • Rearrange Code – allows you to rearrange members in your code up, down. It’s also possible to move code in or out of block. Generally this is a useful feature, but it doesn’t support moving regions.
  • Paste – Clipboard history.

Templates


Templates

Templates in ReSharper are one big disappointment in comparison with CodeRush. Although
it provides around 50 live templates (this is a total count – for all languages)
and around 30 surround templates (this is total count – for all languages) I find
it pretty poor. Many of those are pretty useless. The only good point about templates
is they’re easy to add and  edit. However once you start adding new templates
you quickly figure out that your options are limited, which is another minus regarding
the templates.

Other posts in the series

Part 1 – Installation & First-time Configuration
Part 2 – Coding Assistance & Templates
Part 3 – Refactoring
Part 4 – Navigation
Part 5 – Code Inspection
Part 6 – Unit Tests
Part 7 – Performance & Memory Consumption
Part 8 – Ease of Use
Part 9 – Extensibility
Part 10 – Other Cool Features
Part 11 – Final Thoughts

Advertisement
 
8 Comments

Posted by on August 31, 2010 in Tools

 

Tags: ,

8 Responses to ReSharper 5 – Coding Assistance & Templates

  1. Bojan V.

    September 6, 2010 at 07:41

    I find templates in R# quite usefull…there aint so many as in Coderush. Neverthless, i more into writting my own templates. when i need them.
    Coderush has very powerfull templates engine, but if you take time (minute per templates) and set up the favorite templates with R# (thats quite easy with live templates), you’ll get everything you need for better writting code. Its works for me. I swapped to R# from CodeRush and must say, for now i dont miss any funcionality.

     
  2. Danijel Malik

    September 6, 2010 at 12:48

    Well that’s up to an idividual. In my opinion R# lacks some predefined templates. And abilities to add my own templates are a little bit limited.

     
  3. aşk büyüsü

    October 6, 2010 at 14:43

    thanks for admin wonderfull information…

     
  4. Jura Gorohovsky

    October 11, 2010 at 16:20

    Hi Danijel,

    Thanks for your reviews! Please keep on with your review series!
    Just a couple of notes:
    1. Context actions and quick-fixes are not actually the same thing. Quick-fixes (red and yellow bulbs) are aimed at removing errors and issues discovered by ReSharper code analysis. Context actions are just editing/navigation/generation helpers that are not in any way bound to code analysis results.
    2. Visual Studio’s Parameter Information is pretty much static while ReSharper’s Parameter Info changes as you type. With the amount of signatures in your image, it’s probably a little too ambiguous case but if you have an observable amount of signatures, it can really help find out which of them you’re following and which parameter to put next.
    3. Regarding live templates, we’re not really striving to provide a ton of them out of the box but rather we rely on the user to create templates that are relevant to him/her. Probably an online repository of shared live/surround templates would be a good option, what do you think?
    BTW, what are three main things that you feel you’re missing from ReSharper templates compared to CodeRush templates?

     
    • Bojan V.

      October 11, 2010 at 17:26

      @Jura: do you allready have shared live/online repository of R# templates? If not, i’m very interested of creating such a service. I’m playing around web technologies and it sounds a really cool project to create as a pet project or community work.

       
      • Jura Gorohovsky

        October 12, 2010 at 11:39

        @Bojan
        Thanks for offering your help!
        A template repository is at this point something that we’re considering but we haven’t yet taken any practical steps in this direction.
        If we do that, first of all we’ve got to make sure that ReSharper does support this kind of sharing internally. As soon as this requirement is satisfied, we’ll hopefully be able to get the community involved.
        I’m not ready for any commitments in this area yet but as soon as we’re ready, we’ll make an announcement on the .NET tools blog (http://blogs.jetbrains.com/dotnet) and on twitter (http://www.twitter.com/resharper), so if you follow one of those resources, you’ll know when you’re able to step in.

         
  5. Bojan V.

    October 12, 2010 at 12:27

    @Jura: sure, no prob. If you will enable the possibility to sync live templates inside of R#, that would be awesome. I follow both of resources, so i’ll surely step into the game, when you’ll have everything ready. Keep up the good work.

     
  6. Mariella Voisinet

    December 14, 2010 at 04:44

    There is evidently a bundle to identify about this. I consider you made certain nice points in features also.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.