How-To's

End of Year Round up of ReSharper 10 Extensions

With the end of the year just around the corner, ReSharper 10 released less than two months ago, and having just released our second maintenance release, it’s a perfect time to take a look at some of the extensions we’ve got available for ReSharper 10.

ReSharper provides a very rich extensibility platform. It is a very modular application, composing functionality and features via a component container. Extensions can extend existing functionality, such as adding items to the Alt+Enter menu, or new inspections and Quick Fixes, or add new functionality, such as support for new languages, or synchronising settings via DropBox.

We currently have about 60 extensions available in the Extension Manager for ReSharper 10. If you haven’t yet had a look to see what’s available, grab yourself a coffee and we’ll take a wander through some of what’s out there. If you see anything you like, head over to the Extension Manager under the ReSharper menu, and search for the extension you want.

ZenSharp

The ZenSharp extension is like ReSharper’s Live Templates on steroids. While Live Templates will expand a static shortcut (like tm) into a code snippet (such as a test method), ZenSharp uses “dynamic” shortcuts to customise the generated snippet.

For example, pc will expand to public class $Name { }, where $Name is a standard Live Template “hotspot” to edit the class name. But pcPerson will expand to public class Person { }.

Similarly, pmSayHello  will expand to public void SayHello() { }. And pmsSayHello will expand to public string SayHello() { }.

The shortcuts are defined to be intuitive mnemonics that can be combined and built up to make it easy and fast to create classes, methods, properties, fields and so on. Standard types can be specified as part of the mnemonic shortcut, and once you’ve mastered it, there’s no faster way to create types and type members.

ZenSharp creating code really quickly

Enhanced Tooltips

The Enhanced Tooltip extension gives ReSharper’s tooltips a facelift. While this doesn’t exactly sound like it’s a big deal, it has a surprising impact – tooltips and parameter info popups in C# are rendered with syntax highlighting, which makes quickly reading parameter lists and method names a whole lot easier.

Furthermore, the tooltips that appear for ReSharper’s inspection warnings and suggestions are also syntax highlighted, with any member names in the message being rendered correctly, and an icon showing what kind of message is being displayed. ReSharper never looked so good!

Enhanced tooltips

ReSpeller

Office has it, so why shouldn’t ReSharper? Spelling, that is, and the ReSpeller extension provides just that. It’s available in Free and Pro versions and will look for typos in different languages, such as C#, VB and XML, and even differentiates between identifiers, string literals and comments. For example, you can configure typos in identifiers to be shown as a “hint”, and change typos in comments (such as XML documentation) to be “warning”. And it understands “CamelCasing”, treating “SayHelo” as two words, and finding the typo in “hello”.

It also supports the Alt+Enter menu, offering a Quick Fix to replace the typo, or options to add the word to the user dictionary.

The Pro edition adds extra features, like enabling support for extra languages (such as JavaScript, HTML and Razor), multiple language support and even spell checking directly in the Rename refactoring dialog box!

ReSpeller showing typos

StyleCop

While the StyleCop project itself has stalled, there are still many people using it to maintain a very consistent style when writing code within a team. The StyleCop extension provides as-you-type inspections to highlight when your code doesn’t match the expected style. It also configures ReSharper so that the code ReSharper produces or formats is in the correct style.

We find ourselves in the unfortunate position of having two different StyleCop extensions available in the Extension Manager (it’s a long story, sadly, and we’re working to resolve it). We strongly recommend you use the StyleCop by JetBrains version (search for “StyleCop by JetBrains” in the Extension Manager), as it fixes many issues, including exceptions and memory leaks, and implements improved performance throttling. It also doesn’t need the StyleCop Visual Studio plugin installed.

One thing to note is that StyleCop itself does not support C# 6. The StyleCop engine that the extension uses has a custom C# parser, rather than using ReSharper’s already parsed abstract syntax trees (one cause for performance issues), and due to the project stalling, the parser hasn’t been updated for C# 6. If you’re using Visual Studio 2015 and C# 6, we recommend you use the StyleCopAnalyzers project, which has full support for C# 6, including new rules. When the StyleCop by JetBrains extension sees that StyleCopAnalyzers is installed, it disables its own as-you-type analysis, but still provides code cleanup features and configures ReSharper to match the StyleCop settings.

StyleCop showing warnings

Extra inspections

Some extensions are designed to add new inspections, and we’ll take a look at two – Cyclomatic Complexity and Heap Allocations Viewer.

The Cyclomatic Complexity extension calculates the cyclomatic complexity of a block of code. This is a measurement of how complex your code is, and you should ideally be aiming for a very low figure – the higher the value, the more complex the code, and the harder it is to maintain and understand. The value is always shown in a tooltip, and if it’s over a certain configurable threshold, the method name (or similar) is highlighted as a warning. The extension works with C#, VB, JavaScript, TypeScript and C++.

ReSharper showing high cyclomatic complextity

The Heap Allocation Viewer extension highlights all allocations made by your code. This is an interesting extension, because it doesn’t indicate that anything is actually wrong, but it’s intended to make you aware that an allocation happens here. This is very useful when writing performance critical code, when you really need to keep track of all allocations. While it’s obvious that the new statement will allocate memory, this extension will also highlight less obvious allocations, such as boxing, string allocation, allocations when iterating with a foreach loop, and so on.

Heap allocations viewer showing boxing

Working with open source libraries

While some extensions are designed to provide new functionality across the product (such as improving the editing experience, or more inspections for your code), others are designed for a specific library or framework.

A good example of this is support for AngularJS, parsing your JavaScript code to pull out Angular directives, and add them to your HTML code completion. It will also provide improved code completion for the services and providers injected into controllers and directives.

AngularJS intellisense for injected parameters

Similarly, Unity support provides features for users of Unity 3D. It will mark methods and fields used by Unity as being in use when Solution Wide Analysis is enabled, generate message handlers via the Generate Code command and automatically mark a C# project as C# 5, so ReSharper won’t suggest incompatible C# 6 features when the project is opened in Visual Studio 2015.

Working with commercial libraries

A very nice use of ReSharper extensions is supporting commercial frameworks and products. The team at Trackerbird have done just that, and released an extension that will make it very easy for you to integrate their analysis SDK into your own project. Once installed, this extension adds an item to the ReSharper menu, offering options to set up the SDK in your project, add simple or detailed event tracking code to your project, help you implement checking for updates and so on. It also includes a context action on Application.Run that will add the code necessary to initialise and start activity tracking in your app.

Implement Trackerbird as a context action menu item

Please check out the Trackerbird blog for more details.

Annotations

ReSharper extensions are not just about custom code adding new items to the Alt+Enter menu, but can also include “external annotations”. These are files that contain annotations for pre-compiled assemblies that in turn provide hints to ReSharper’s inspections, resulting in better analysis for features such as null analysis, string formatting highlighting and telling ReSharper that type members are used externally from the code. Here are some annotations packages:

  • Community External Annotations – this is a nice open source project that maintains annotations for a number of third party libraries, as well as adding extra support for various BCL libraries. You can see the list of supported assemblies in the project readme. Contributions welcome!
  • NLog Annotations – adds null analysis and string formatting highlighting annotations for the NLog framework.
  • Caliburn.Light Annotations – adds annotations for the Caliburn.Light MVVM framework

Live Templates

Alongside external annotations, ReSharper extensions can also include settings files, which are automatically merged into ReSharper’s settings (technically, they override ReSharper’s defaults, and can get overwritten by your own settings). One of the more interesting uses for this is to package up a settings file that contains Live Templates.

There are several such packages available in the Extension Manager, such as:

  • SpecsFor templates for the SpecsFor BDD framework
  • Joar Øyen’s Live Template Macros – adding templates for BDD and a macro that converts a Live Template “hotspot” into a “snake_case_identifier”, such as given_a_new_customer .

Presentation Assistant

This extension is very useful when you find yourself giving a presentation. It will display the name of the last command run, and the keyboard shortcuts used to run it, allowing everyone to follow along with the steps you make as you make them. It shows both ReSharper and Visual Studio commands, and can be enabled from the ReSharper → Tools → Presentation Assistant.

Presentation Assistant showing keyboard shortcuts

It’s also useful for pair programming, to stop the “how did you do that?!” questions as you show off your mad keyboard skillz.

Working with settings files

Two useful extensions for working with settings files are ReSharper Solution Settings Autodiscovery and JetBox.

ReSharper already allows you to share settings files per-solution, by creating a .sln.DotSettings file that lives next to your solution file. But this needs setting up for each solution – what if your team has a number of solutions that you want to work with?

The ReSharper Solution Settings Autodiscovery extension will look for a settings file in each of the parent folders when opening a solution. So if your solution is in C:\projects\team\solution\mySolution.sln, this plugin will look for any file that ends in *.AutoLoad.DotSettings in any of the parent folders – C:\projects\team\solution, C:\projects\team, C:\projects and so on, up to the root of the drive. This is ideal when working on a source control check out that has multiple solutions, and allows you to easily share settings between all of them, and still have the file checked into source control.

The JetBox extension will sync your global settings via DropBox. Simply log in to DropBox via the options page, and the global settings file will be synced whenever there are any changes. And because ReSharper automatically refreshes the settings in any running instances whenever the file changes, you don’t even need to close and reopen Visual Studio for the changes to take effect.

And Finally…

It doesn’t have to be all work and no play. We’ve got a couple of fun extensions too. Check out ReMoji, to add support for JBEvain’s EmojiVS extension to ReSharper’s code completion (make sure you read the instructions for installing first!)

Code completion showing emoji

And of course, who can forget Clippy?

inplace_refactoring.gif

We hope you’ve found this look at some of the extensions available for ReSharper 10 useful. It’s by no means all of the extensions that are out there, so please, have a scroll through the Extension Manager, and see if there’s anything else there that interests you.

image description