Posts Tagged ‘ReSharper 7.1’

AngularJS support for ReSharper

Thursday, February 28th, 2013

In case you haven’t already been introduced, AngularJS is a popular JavaScript framework for creating dynamic web applications. It provides many of the services required to build such applications, not the least of which is a declarative approach to updating the UI. It favours the use of data binding and templates over direct DOM manipulation, and it makes it possible to create complex sites with a minimum of code. For more information, check out the examples on their home page, or take a look at the video tutorials by our very own John Lindquist.

We’ve just released a plugin that adds ReSharper support for some of AngularJS’ features (here’s a direct download link). It’s an initial version, so doesn’t cover everything, but what it provides should give you a helping hand in creating your sites. Currently, the plugin provides code-completion for Angular’s custom HTML attributes, and a bundle of Live Templates to make building common constructs easier.

Code completion will include all of AngularJS’ “ng-” attributes when editing HTML files, and include a description tooltip:

Code completion showing Angular attributes

It also supports the HTML5 “data-” prefixed versions of the same attributes.

Code completion with data prefixed attributes

And of course, since ReSharper has smart matching, you can type initials to quickly get to the start of the attribute you want. For example, you can type “dngbh” to get to the “data-ng-bind-html” attribute:

Code completion with smart matching

The plugin also ships with 26 Live Templates, based on the IntelliJ and WebStorm templates by Pawel Kozlowski and John Lindquist, respectively. They are split into functionality for directives, modules, scope, routing, html and global helpers. For example, you can use the “ngindex” template to create a simple HTML page to start your development,  or “ngb” to create a binding expression. These work in HTML or HTML-like files (Razor, ASPX, .html)

Expanding the binding template in a HTML file

The JavaScript templates can create code for directives, for loops, modules, routing and scope. These are available in JavaScript files, and within script tags in HTML-like files:

Expanding a scope function template

Please check out the templates explorer to get a full list, or to edit, add or remove templates.

This is just an initial release. We’d love to expand the feature set, supporting custom HTML element directives, navigation to model properties, binding expressions, and more. If there are any features you’d like to see, or if you find any bugs, please add a feature request to the Issues page. And of course, it’s Open Source - if you’d like to see a new feature, how about taking a crack at it? We’ll help.

Now, go and download it, and make lovely dynamic JavaScript applications.

CatelR# - a niche plugin for the Catel framework

Monday, January 28th, 2013

Most ReSharper plugins provide general-purpose services – spell checking, style enforcement, unit testing, code generation or context actions for XAML, string manipulation or code quality. The focus is wide, either concentrating on multiple file types or multiple analyses.

The CatelR# ReSharper plugin takes a different approach, and has a very narrow focus. It provides context actions and analyses specifically for users of the Catel framework.

Catel is a framework with a focus on MVVM based applications. It provides multiple services to the application developer, including an IoC container, validation, message mediation and argument validation. It also provides MVVM services, such as view model support, commands and behaviours. Check out the extensive documentation for more details of the framework itself.

The plugin’s aim is to streamline development with the framework, trying to make it as easy as possible to get the most out it. For example, when creating a ViewModel, Model or data object class, CatelR# offers a context action on the class declaration to make it derive from Catel’s ViewModelBase, ModelBase or DataObjectBase classes, automatically inserting the correct using statements.

Context action to derive from Catel base objects

And these options only show up once you’ve added assembly or NuGet references to Catel.Core and Catel.MVVM.

Similarly, it offers context actions to convert a normal auto-property into a Catel property, similar to XAML’s DependencyProperty, which can be used for data binding. Optionally, you can also have it create a method to be used when the value changes.

Context action to convert auto-property to Catel property

Resulting in generated code that looks like this:

Example of generated Catel property

The generated NameProperty field also has a context action to include or exclude it from serialisation, which alters the parameters to the RegisterProperty method, and another that will convert it back into an auto-property.

And this is made even easier using the Generate Code menu, which allows converting multiple properties at once.

Generate multiple Catel properties at once

A similar code generation workflow is provided that makes it very easy to map between a model and a view model. The view model creates a property that holds the model instance. As long as this property is marked with the ModelAttribute, CatelR# now knows the type of the model, and can generate matching properties in the view model, saving a lot of work. See this blog post for more details.

The other main feature offered by the plugin is to add argument checking, using the framework’s own methods. This adds context actions to method parameters. For strings, you get to check for null/empty or null/empty/whitespace.

Add argument check for parameter

For objects you can assert that it is a specific type or implements a specific interface, and for integers, you get a choice for minimum, maximum or within range. When you select one of these options, CatelR# uses ReSharper’s LiveTemplate hotspots to allow for editing the values, which ReSharper automatically copies to the xml documentation that CatelR# also creates.

Argument check with hotspot editing

This plugin provides some very useful features for the users of the Catel framework. The focus is refreshingly narrow and very much aimed at reducing friction for Catel users – quickly implementing the patterns and code necessary to use the framework, allowing the user to concentrate on adding the business value. This is a fantastic approach for a ReSharper plugin, and one that could be used to great effect by other library developers.

Catel and CatelR# are both open source projects, hosted on CodePlex. The Catel framework can be installed via NuGet, and the ReSharper plugin is available on the CodePlex download page.

ReSharper plugins for unit testing - MSpec, xUnit.net and Silverlight

Monday, January 21st, 2013

ReSharper provides comprehensive support for running and debugging unit tests. Out of the box, it works with NUnit and Microsoft’s Visual Studio Unit Testing Framework (henceforth mstest for brevity) for .Net languages, and supports QUnit and Jasmine for JavaScript.

The same APIs that ReSharper uses to implement this support are fully available to third parties, and there are currently plugins to expand this support to include Machine.Specifications (MSpec), xUnit.net and support for Silverlight projects. More can be added at any time, through the use of the SDK.

The MSpec project is a “Context/Specification” testing framework, which is a form of BDD tool, focussed more on driving correct behaviour than on testing functionality – building the right thing, rather than building the thing right. It’s a significant change of style to anyone used to the NUnit/mstest style of attributed methods, but it’s not too difficult to follow – test methods are replaced with fields that take lambdas that arrange, act and assert. It’s worth checking out the example projects in the source repository – BankingSpecs is a good place to start.

Machine.Specifications ships as a NuGet package, which also includes the ReSharper runner. Simply run the InstallReSharperRunner batch file in your packages\Machine.Specifications\tools folder (it includes support for ReSharper 6 and 7). Once installed, ReSharper now recognises MSpec tests in your source code, adding the unit test icons to the gutter in the editor:

mspec test recognised in the editor

One of MSpec’s nice features it that the names of the test and the information from the SubjectAttribute are used to generate a natural language description, which, when used with the different grouping options in the test runner can give very readable test results:

mspec results with natural language descriptions grouped by category

The xUnit.net framework is a more traditional unit testing framework, similar to NUnit and mstest, but arguably more idiomatic .Net. For example, it still uses attributes to mark methods as tests, but uses constructors and IDisposable instead of SetUp and TearDown attributes. Support is added by the xunitcontrib plugin, giving ReSharper the ability to locate and run xUnit.net tests. Like NUnit and mstest, it can handle parameterised row tests, dynamically adding rows into the results as the tests are run.

xUnit.net parameterised tests, using random data

It also works with the “Show Unit Test Usages” option in the filter drop down of the Find Results window. When viewing the results of a find usage search, any usage in a test method or test class is marked with a test icon, rather than an icon representing a method, class or property. Unchecking the “Show Unit Test Usages” option in the “Filter Usages” drop down will hide the test usages in the results, allowing you to focus on the usages in the production codebase.

Filtering xUnit.net test usages out of Find Usages results

Unit test providers don’t need to be source based. Most of them are, and display the test icon in the editor gutter, but they also examine the metadata of the compiled assembly, and can potentially find more tests here. Using this technique, it’s possible to run tests created in a source file that ReSharper doesn’t support. For example, we can create an xUnit.net test in F#, and while it’s not detected in the editor, it is still found and run when the assembly is compiled.

xUnit.net test in F#

Since the test hasn’t come from source code, you can’t double click the test in the test results to navigate to it. But a failing test will display a clickable stack trace that will navigate to the failure.

F# test results showing clickable call stack

This technique can be used to run F# tests using other F# test frameworks, as long as they are based on a unit test framework that ReSharper supports (and this technique can also be used to write a plugin that supports a framework that isn’t based on one of these frameworks).

Silverlight support is provided by AgUnit, which enables running and debugging your unit tests in Silverlight projects, and of course handles the Silverlight test framework’s AsynchronousAttribute.

AgUnit debugging an asynchronous Silverlight test

Perhaps surprisingly, a couple of our own products are also plugins for ReSharper’s unit test runner – dotTrace and dotCover. Although the products register themselves with ReSharper somewhat differently to normal plugins, these products use the same open APIs that the third party plugins use, albeit for a slightly different purpose. Instead of examining source code and metadata to find and run tests, they provide the environment in which tests are run; dotTrace collects profiling information, and dotCover collects coverage information. Both products extend the UI to provide means of running the tests, but dotCover also adds an output pane to the test runner to display the coverage information (and highlights covered and uncovered code in the editor), and of course, this works with third party test providers.

Unit test runner showing dotCover custom code coverage results pane

And, just to bring the extensibility full circle, dotCover includes ReSharper’s unit test runner, which is used if ReSharper isn’t installed. Again, NUnit and mstest support is provided out of the box, and there are separate dotCover plugins for xUnit.net and MSpec support (the dotCover MSpec runner is also distributed in the NuGet package, just use the InstallDotCoverRunner batch file in the tools folder).

ReSharper provides comprehensive unit testing support, in an environment that is very flexible. There is a lot of great support, provided in the box, and just a download away. And it’s all open and extensible – if you don’t see something you want, grab the SDK and get coding!

Introducing ForTea - a T4 templating plugin for ReSharper

Friday, January 11th, 2013

T4 files have sometimes suffered from a lack of love. It’s brilliant that Visual Studio provides an ASP.NET-like template language in the box with Visual Studio, but there is not much support – for example, there is no syntax colouring in Visual Studio, and ReSharper knows nothing about the contents of the file. We have an item on our issue tracker to include support, but I’m very pleased to announce that one of our users has beaten us to it and created a very impressive plugin to do just that – the first plugin we have that provides support for a new file type.

The ForTea plugin by Julien Lebosquain (who also created the GammaXaml plugin) was released as version 1.0 just before Christmas. You can find it on GitHub – which means it’s Open Source, if you’re interested in contributing – and from the readme on the home page, here is a direct link to an msi download.

So what does it give you? Well, obviously it provides syntax highlighting for .tt and .ttinclude files, but that’s to be expected.

Where this plugin really shines is that it integrates with ReSharper’s PSI (Program Structure Interface). In other words, once the plugin is installed, ReSharper gets access to the abstract syntax tree of the file, and uses this to provide familiar code completion, analyses and refactorings.

Intellisense displayed in T4 template

As you can see from the screenshot, it supports code completion for T4 directives, and even in this little snippet from a brand new file, is greying out namespaces that aren’t used. And as expected, Alt+Enter on the unused import statements invokes the standard ReSharper context action to remove unused directives.

Remove unused directives context action in T4 file

The plugin also recognises C# code blocks, and provides the expected analysis and code completion – notice the light bulb context action icon, the greyed out unused variable name, and the code completion drop-down.

Intellisense and analyses in T4 file

It can understand multiple code blocks – this example provides code completion in one code block for a method defined in a separate code block at the end of the file, and also marks the duration variable defined in the first code block as in use. It even suggests that the public method can be made private, and provides a hint that the FormatTimeSpan method could be static.

Multiple code block support in T4 file

Of course, renaming works, too:

Renaming variable across T4 code block

As does Find Usages, in files:

Find usages in single T4 file

And across the solution, even providing syntax highlighted previews:

Find usages results including T4 file

One of the nicest features is importing references. ReSharper handles this for C# files – if a type isn’t found, it can suggest to import a namespace or add an assembly reference to the project. But T4 files don’t use the project’s references. Instead, they use namespaces and assemblies declared at the top of the file. Once the ForTea plugin is installed, ReSharper will suggest to add namespaces and references for missing types, but will correctly add them to the file.

Importing references and namespaces into T4 file

As impressive as it is for a 1.0 release, there are a couple of limitations. It should hopefully be obvious that there will be conflicts with other Visual Studio extensions that provide T4 support, so any similar extensions will need to be uninstalled. There are also a few things not yet supported. For example, it’s C# only, and there’s no support for outlining (this is a feature of the Visual Studio editor, and not handled by ReSharper). There is no code formatter yet, so ReSharper won’t help with indenting and code cleanup. See Julien’s notes for more details.

This is a fantastic effort from a member of the ReSharper community, and has produced a very impressive plugin. Please, download it (direct link), use it, and give Julien some feedback. And, of course, it’s open source, hosted on GitHub, so if you’d like to see new features, or find any issues, report them, or grab a copy of the source and submit some pull requests!

ReSharper 7.1 Plugins

Friday, November 23rd, 2012

ReSharper 7.1 has only just been released, and once again, it’s time to congratulate our plugin authors on how quickly they have support for the latest version ready. A lot of these plugins are Open Source, and produced in the authors’ spare time, so we’d like to give them a big thank you for their continued support. Here are some of the plugins:

  • We have testing frameworks: AgUnit can run and debug Silverlight tests, the xunitcontrib runner provides xUnit.net support and the latest MSpec NuGet package includes a ReSharper 7.1 runner.
  • There are code validation plug-ins: StyleCop will analyse your C# source code, and display warnings and corrections if you violate the style guide. JSLint for ReSharper supplies similar functionality for your JavaScript files.
  • There are a couple of plugins providing spell checker support. YouCantSpell is available now, ReSpeller is currently being updated and should be available very soon, and Agent Smith implements context actions to help format XML documentation as well as spell checking.
  • ActiveMesa’s R2P plugin brings a veritable smorgasbord of miscellaneous context actions, refactorings, generators and and inspections to ReSharper 7.1, as does Agent Johnson.
  • Catel.ReSharper takes a very interesting approach to implementing a plugin – instead of offering a broad set of additional features, it targets users of a specific platform - that is Catel MVVM project, providing context actions and refactorings specifically designed to integrate with the Catel.MVVM feature set.
  • The GammaXaml plugin has been updated to work with the new XAML support in 7.1, and provides additional XAML support such as dependency property validation and generation, and support for Caliburn.Micro’s conventions.
  • Joar Øyen’s ReSharperExtensions is a set of macros to be used in live templates, where they can automatically insert the current domain user or ensure a string typed by the user is a valid identifier by converting spaces to underscores, optionally capitalising the first letter of each word.
  • Continuing the Agent naming theme, Agent Mulder brings ReSharper analysis and navigation features to Dependency Injection frameworks such as Autofac and Castle Windsor. It’s not quite ready for 7.1 yet, but it’s being worked on and should be available soon.
  • And of course, there are plugins that JetBrains contributes. The recently released NuGet support, and the example plugin that shows MVC action verbs in navigation lists both support ReSharper 7.1.

Again, most of these plugins are Open Source. All of the authors welcome feedback, good as well as bad! Report issues, suggest features, fork and contribute! If you want to get involved, download the SDK for MSBuild targets, tools and sample code, and visit the development guide for more information. And if you create a new plugin, let us know, and we’ll help spread the word.

ReSharper 7.1 is Available

Tuesday, November 13th, 2012

ReSharper 7.1 is released
You knew ReSharper 7.1 had been underway for some time, and now, the day has come: ReSharper 7.1 is officially released and available for download. You’re welcome to grab the new ReSharper update.

Some of the reasons why you would want to do this include:

  • Performance and bug fixes: since releasing version 7.0, we have fixed over 300 performance problems and bugs! Special notice goes to performance fixes for SharePoint and ASP.NET MVC projects, as well as those for resource files.
  • Improved code formatter: considering that code formatting is a very sensitive area of functionality, we have implemented some of the most demanded code formatter improvements so far. For example, ReSharper 7.1 is able to format XML doc comments and chained method calls. We’ve recently blogged in detail about code formatter improvements.
  • Reviewing code and sharing ReSharper code inspection results with team mates is now easier, thanks to improved export functionality, as well as a way to copy code inspection items and convert them to work items. To learn more about this, see Easy sharing of ReSharper inspection results in the 7.1 EAP launch blog post.
  • Support for Windows Phone 8: if you’re already using Windows Phone 8 SDK to develop applications, ReSharper 7.1 is here to help you. How exactly? Read a recent blog post about Windows Phone 8 support
  • Support for VB.NET has been refined with Extract Class refactoring, new quick-fixes and improved IntelliSense.
  • XAML support is now considerably smoother in terms of code completion, typing assistance, naming style control, and code generation. The guy who’s in charge of XAML support has recently blogged about this.
  • INotifyPropertyChanged support pack now covers more usage scenarios relevant to Windows Forms, WPF and Silverlight application developers.
  • Other improvements include fixes in multiple refactorings; improved support for Entity Framework 5, ASP.NET, ASP.NET MVC, and JavaScript.

ReSharper 7.1 is a free upgrade for everyone who owns a ReSharper 7 license or a ReSharper 6 license purchased since June 1, 2012.

If you’re using ReSharper with plug-ins, they’re being tested for 7.1 compatibility. Most of them should be available for download in the coming days.

Please download ReSharper 7.1 and let us know how it works for you!

Windows Phone 8 Support in ReSharper 7.1

Wednesday, October 31st, 2012

As many of you know, after months of waiting Microsoft has finally released Windows Phone 8 SDK to the general public. This means that you can now start writing WP8 apps and it should probably come as no surprise that ReSharper is here to help once again!

Here is an overview of some of the aspects of WP8 development that ReSharper 7.1 supports out of the box:

  • Code completion is provided in both the C# and VB languages as well as XAML.

  • Code inspections, quick-fixes and context actions let you quickly fix errors, improve and organize your code:

  • A vast array of XAML-related improvements is provided in 7.1. These include improved support for XAML code completion as well as typing assistance, binding assistance, support for custom bindings and resource dictionaries and lots of other improvements. Check out this blog post for details.

  • Navigation and search mechanisms continue to support lightning-fast introspection of existing code:

  • Create from usage mechanisms let you use elements first, and declare them later:

  • ReSharper’s large set of refactorings support different languages as well as cross-language usage scenarios:

  • Color highlighting and the Select Color window make working with colors in XAML a breeze:

  • Naturally, ReSharper also supports HTML that is used in the “Windows Phone HTML5 App” type of project:

We’ve ensured that all of the aforementioned mechanisms (as well as many others) are supported under the various C#- and VB.NET-based Windows Phone project types, making development of WP8 applications that much easier and more intuitive. Enjoy!

Right now, you can download a fresh ReSharper 7.1 nightly build. The final release should be available shortly as well.