Tag Archives: ReSharper 6

ReSharper Settings in 6.1

This post is about ReSharper 6.1. For features in 6.0, please see previous posts introducing ReSharper 6:

 

EAP Warning: This post is based on ReSharper 6.1 Early Access Program and some things such as screenshots and minor details might vary from the time this has been written to the time of release.

 

This is a first in a series of posts about some of the new options available in terms of settings with ReSharper 6.1.

 

One of ReSharper’s pain points has always been settings, specially when it comes to managing them across projects and/or teams. With ReSharper 6.0 we started to make changes to build in support for a new way to manage settings, but unfortunately due to time constraints, we could not get it done in time for the 6.0 release. It has however made it into the 6.1.

Unified Settings Storage

An important change is that all settings have been unified into a single storage mechanism. This means that when you load or save settings, they apply to everything, from code style to templates, patterns and naming conventions. This should make it easier than before where different things were stored in different places.

 

Settings for every scenario

Everyone has their own style and methodology of working. Some like to name their properties in a certain way, others don’t like to be explicit about their privates. Some use underscores, others don’t. Some like the var suggestions. Others despise it. We are all different.

When it comes to working together, we have to make compromises and settle in a series of settings and ways in which to work. One day, hopefully, we won’t have this limitation and it will be transparent to us, but until then we need to find a way to not only cope with it but define it.

This scenario is very apparent when working on a team, but even as a solo developer, we can still require different settings based on different factors. We can be working on private projects that follow our own standards or be part of an open source team that follows the standards for the OSS project.

 

We hope with ReSharper’s new settings we can try and accommodate different scenarios. Let’s cover a few of the simpler ones.

 

Single developer and same settings for all solutions

If you are a solo developer or like to have the same settings across every single solution, then you won’t notice much difference in how you save your settings. You access the settings using the regular ReSharper | Options dialog and once done you press the Save button

image

 

These are also known as ReSharper Global Settings and are stored in

%AppData%\JetBrains\ReSharper\vAny\GlobalSettingsStorage.DotSettings

making them easily accessible for backup and restore as well as persistence during upgrades.

 

Different private settings on different solutions

Sometimes we’d like to have different settings based on different solutions, even if we are not necessarily sharing these settings with a team. We’ve made this scenario quite simple too. Once again we open up the ReSharper | Options dialog and make the required changes. This time however, instead of clicking on the Save button, we click on Save To and select  %SolutionName% Solution  – Private where %SolutionName% varies based on the active solution

image

 

This will create a file called %SolutionName%.SLN.DotSettings.user in the solution folder (in our case ConsoleApplication2.SLN.DotSettings.user) which holds the settings for this particular project. It is important to note that this file should not be checked in to source control as each user would have their own specific settings and thus one would override the other. We recommend that this file be added to the list of files to ignore by the VCS (i.e. add to .gitignore).

 

Shared team settings

The next step is to have a series of settings shared across the team. As you can guess from the previous screenshot, this is merely just choosing the next option down when saving settings:

 

image

 

which will create a a %SolutionName%.SLN.DotSettings file in the solution folder. This file should be checked in to source control.

 

These cover some of the simple scenarios when it comes to settings. However, sometimes it is not that simple. Often we want to have the best of both worlds. For instance, we might like to have team settings and tweak them a little bit to our own use. That’s where ReSharper’s smart settings come in.

Combining Settings: Layers

Settings in ReSharper are like onions, they have layers, and these layers, combined with what we call internally “smart savings”, provide more flexibility when it comes to tweaking settings.

Say for instance we are using some shared settings from a team settings file checked in with the project, yet there are certain settings we’d like to change privately that only affects us. How would we do this?

Quite simple. We modify the settings we want tweaked and then save it as Solution Private. ReSharper realizes that there are different values for a setting and the layering kicks in which one layer override another one. The actual order of the layering is:

 

image

Private Settings currently override Solution Shared, which in turn override Global settings. As such, by tweaking the settings to our individual needs (only those required), we can override specific team settings.

[Note: Some have mentioned that this wouldn’t enforce team settings. True, it does not, and we believe in discipline versus constraint.]

Managing Options

You might have noticed that in the ReSharper menu, as well as the Options dialog there is a new entry / button labeled “Manage Options” and “Manage…” respectively. These provide access to managing the different settings layers easily as well as importing/exporting and resetting.

image

 

When clicking on them, we’re displayed the following dialog:

image

 

The dialog box lists all the different layers currently available. Out of the box, ReSharper ships with the three we’ve already discussed: Global, Private and Shared with Team. Each of these are appropriately placed in the correct Group, which also happens to be three. From this dialog box we can edit each of these as well as import and export settings.

 

To edit specific settings, we merely select the one we’re interested in and click on the Edit… button on the top-left corner. This opens up the regular Options dialog box for us, with a minor difference. It now displays the name of the layer we are editing:

 

image

 

This difference is also apparent in that the Save To Button is no longer present, as when clicking Save we will automatically save the layer we are editing. When we edit the settings, only those of that specific layer are updated. Everything else stays intact.

Summary

The new ReSharper settings is hopefully designed in a way which allows to not only ease the pain of sharing settings, but provide for a variety of options and maximum flexibility. In the next parts we’ll cover how to add additional layers (including storing settings on Dropbox for instance), re-order, as well as importing and exporting of old and new settings.

New Features in ReSharper 6 Unit Test Runner

Previous posts introducing ReSharper 6:

 

ReSharper 6 includes a series of new features and improvements in the test runner, as outlined below.

NUnit TestCase

We now fully support NUnit’s TestCase, TestCaseSource, Values, sand other attributes. Given the following tests:

 

image

 

ReSharper outputs the results as individual tests, appropriately grouped.

 

image

 

This allows us to now run and view tests individually.

 

image

 

As expected, dotCover  and dotTrace also provide support for this.

 

Support for Coded UI Tests with MSTest

 

Coded UI tests (when appropriate) are also supported now with the ReSharper test runner

image

Default Keyboard Bindings and Test Re-Runs

 

Out of the box ReSharper now ships with pre-defined shortcut keys for running, debugging, re-running tests, among other things. This eases the pain of having to map keys on new installations (as of ReSharper 6, you no longer loose your key bindings during upgrades!). By default, the key-bindings for the schemes are:

 

 

Operation Visual Studio IntelliJ IDEA
Run Unit Tests. Context Sensitive Ctrl+U, R Ctrl+T, R
Debug Unit Tests. Context Sensitive Ctrl+U, D Ctrl+T, D
Run ALL Unit Tests Ctrl+U, L Ctrl+T, L
Run Current Session Ctrl+U, Y Ctrl+T, Y
Rerun last test. Context Insensitiveimage Ctrl+U, U Ctrl+T, T

 

This last shortcut is a new feature added in 6 which allows us to re-run the last test we just ran. And we can run it from anywhere! This makes TDD for instance very easy as we can write some code, be in the actual code and run the test, without having to switch back to the test or open up the unit text explorer.

 

Running Tests from File Structure and Find Results Windows

 

You can now run Tests directly from the File Structure Window

 

SNAGHTML14c0e0a

 

as well as the Find Results Window

 

SNAGHTML14d0b1d

 

again, removing some of the friction when it comes to testing.

Categories

Certain Unit Testing frameworks provide test categories. For example, in NUnit there is the [Category] attribute. ReSharper now allows us to ignore specific categories and not run them during a test run. This is accomplished by indicating the category under ReSharper | Options | Unit Testing

image

 

When running unit tests, these appear as ignored.

image

This is useful for instance when we want to avoid running certain tests during development sessions.

 

Categories can also be used to run a specific group of tests by selecting these from the context menus:

 

image

Other improvements

Some other minor improvement or previous features we have blogged about include:

 

  • QUnit Support
  • Unit testing Sessions are now persisted between Visual Studio restarts
  • Ability to run tests in parallel from different assemblies, decreasing testing time (can be turned off in ReSharper | Options | Unit Testing)
  • General performance improvements
  • Update Progress indicator on Windows task bar

           image

 

As always, we welcome your feedback

File Header Macros in ReSharper 6

Sometime ago I wrote about Automating File Header Information, showing how to insert license information and other data in project files. One of the shortcomings ReSharper had however was the inability to support macros. Something as simple as inserting the current year or filename required the support of StyleCopy for ReSharper. ReSharper 6 now support macros allowing file headers to contain varying information:

SNAGHTML13afe47c

For instance, in the previous license header, the Copyright years are fixed to 2010 – 2011. It also has no information relevant to the actual project. We could of course hardcode the name of the project in there but since this setting is not solution-specific, it would be of little use. Other data such a filenames however would be impossible to do.

With ReSharper 6 we simply remove the hardcoded values and replace them with macros. We can either type them in or click on the corresponding macro, which will insert it at current cursor position:

image

With this change in place, next time we run a code-cleanup and have the Update File Header option activated, we will get up to date and project/file specific header information inserted. Next feature request: Custom Macros!

Machine.Specifications for ReSharper 6 now available

Many, myself included, have been eagerly awaiting the release of the ReSharper Runner of Machine.Specification (MSpec) for ReSharper 6. I’m glad to announce that this is now available, which is the result of a team-effort between Victor Kropp, Chris Nicola, myself and of course Alexander Gross, long-time contributor and main maintainer of the MSpec project.

NuGet packages have already been updated to support ReSharper 6. The source code can also be obtained via SymbolSource.org if using NuGet or directly from Alexander’s GitHub account.

SNAGHTML5fd19d5

Installing the Runner in ReSharper 6

If you’re new to MSpec or have simply forgotten how to install the runner under ReSharper, here are some simple steps to use Mspec in your project and integrate it with ReSharper:

1. Run the command install-package Machine.Specifications (or Machine.Specifications-Signed if you want the signed version). If this is an existing project, issue the command update-package instead of install-package.

2. Inside the packages folder corresponding to Machine.Specifications, a tools folder is created with a series of assemblies and some batch files. There are a series of batch files named InstallResharperRunner.X.X. – VS20XX.bat where X’s correspond to the version of ReSharper and of Visual Studio. By executing the corresponding one, it will copy the assemblies to the ReSharper plug-in folder.

You can of course do the second step manually, by copying the Machine.Specifications.ReSharperRunner.X.Y files to the ReSharper Plugins folder, located either under the ReSharper bin folder in %Program Files%\JetBrains\ReSharperX\bin (for all users) or under %APPDATA%\JetBrains\ReSharperX\bin (user-specific settings).

With that you should be up and running.

Enjoy.

ReSharper 6 is Released!

We are extremely happy to announce the release of the new ReSharper: please download ReSharper 6 right now.

With this new release, we have gone way and beyond merely providing new features. We have added support for not one but three new languages: JavaScript, CSS and HTML, plus ASP.NET MVC 3 Razor view engine, making ReSharper 6 and Visual Studio one of the best environments today for developing web applications. In addition we also have implemented code analysis for Visual Basic .NET.

The features however aren’t limited to just new language support. Earlier in the year, we announced our new decompiler, which is built in to the core of ReSharper 6, providing integrated decompiling inside Visual Studio. Built on the philosophy of external sources, ReSharper 6 facilitates navigation of source code, whether it belongs to our solution, the .NET framework or any third party library. We also announced the availability of a new free standalone decompiler tool, which is currently in Early Access Program.

ReSharper 6 also provides a wealth of rich features for all language lovers. From new in-place refactorings, to enhancements in navigation and unit testing, new code transformations, code inspections for C#, improved XAML support, ReSharper 6 provides something for everyone.

If you prefer watching over reading about the new features, here’s a fresh screencast for you.

Also, we have previously blogged about some of the new features of ReSharper 6, and we’ll be keep doing that after release.

We have also opened our Early Access Program for dotCover 1.1.1 and dotTrace Performance 4.5.1 which are compatible with ReSharper 6.

We truly hope you enjoy this new release and know that we have already started working on the next version. As always, we’d love to hear your feedback.

ReSharper 6 enhances the JavaScript experience

We already mentioned some of the benefits that ReSharper brings to the table when it comes to JavaScript development previously. In this post we are going to have a more in-depth look at some of the features.

Pimping jQuery

In addition to support for JavaScript, ReSharper 6 also provides certain functionality specific to jQuery.

Code Completion for Selectors

When working with jQuery selectors we often need to lookup certain DOM elements or CSS classes in order to operate with them. This can result in a back-and-forth between the code we are working on and looking up of a specific element. ReSharper 6 facilitates these cumbersome operations by providing code completion for selectors:

image

This completion is invoked by typing # between the quotes, where as if we were to type ., we’d get:

image

This completion is available anywhere we a selector is required.  Of course if we merely want to select a specific type of element, we also have completion:

image

Extending jQuery extensions

One of the benefits of jQuery is the ease by which we can extend it to add our own functions and methods. ReSharper enhances this experience by providing completion also for custom extensions. For instance, if we were to write a new extension:

image

we now have myFoo available as a method of jQuery:

image

Much in the same way, if we want to extend an object:

image

we have:

image

Importing File References

Out of the box, Visual Studio requires a special comment to be added to script files to provide support for IntelliSense:

image

With ReSharper this is not required. If however, it is included, ReSharper will then limit the scope of Intellisense to the reference added. This reference can be provided by directly typing it in, in which case ReSharper offer completion:

image

as well as providing quick-fixes when errors are detected in paths:

image

Creating from Usage

Similar to C# and VB.NET, we can now also create JavaScript code based on usage. For instance, let’s say we write some code that calls a specific function named getInterval that does not yet exist. ReSharper prompts us to create a local function:

image

generating the code for us, providing us the same ability we have in C# to iterate through parameter names etc. The same applies to variables:

image

as it does to creating parameters and properties; once again, making the whole development experience a bit smoother.

Last but not least, ReSharper also provides the ability to create jQuery extension methods from usage:

image

Refactoring

Certain refactoring operations are now available in JavaScript. Firstly, in combination with Create from Usage, we can now easily add an extra parameter to a function call and have ReSharper offer to create it for us:

image

Introduce Variable is another refactoring option available:

image

And last but not least, Renaming:

image

ReSharper is smart enough to handle the scope of the renaming outside of the current local scope, prompting you always with the option to fine-tune certain renaming’s.

Code Clean-up and Rearranging.

In a previous blog post we mentioned briefly the code formatting options for JavaScript. These have now been extended and better organized. We can fine tune Lines Breaks, Braces Layout as well as Space via ReSharper | Options | JavaScript | Formatting Style. Below are the options for the newly added Spaces:

image

Running code-cleanup on JavaScript files is of course now also possible:

image

Also, out of the box, we provide certain filters, both in clean-up and analysis, such as those with min.* extensions. These can be changed in the options dialog, albeit it’s not highly recommended.

image

Rearranging Code

You can now rearrange code which includes moving parameters around, moving members up/down as well as arguments and object literals and arrays. All this is done using the same key combination as used in C# and VB.NET (Ctrl+Alt+Shift + Cursor Keys).

Code Inspections

JavaScript is a dynamic language. It has great advantages but can prove to be not the easiest language to work with, specially for novices. We’ve tried to ease some of that pain by providing code inspections, where possible. Among the many code inspections that currently are available are:

Syntax errors

image

Unused symbols

image

Dead code

image

Duplicate switch statements

image

Misuse of “this”

image

Accessing undefined global symbols

image

And this is just a few of the over 25 inspections that ReSharper supports along with their corresponding quick fixes. We believe that this will help remove some of the issues encountered at runtime, specially by newcomers.

Miscellaneous

Some of the other features provided for JavaScript are:

  • Configurable Naming Conventions: Much like C# and VB.NET you can define your own naming conventions.

image

  • Comments: Ability to comment and uncomment blocks of code as well as support for XML Documents.
  • Context Actions Settings: You can fine-tune which of context actions you want enabled.

image

  • Live Templates:  Support for Live Templates
  • Navigation and Find Usages: Navigation support as well as Find Usages for JavaScript members, some of which was already covered in a previous post.
  • Coding Assistance: Also covered in previous post.

All in all, we hope that some of these features allow JavaScript to become a language to that easier to learn, use and enjoyable.

ReSharper 6 is currently in EAP. Download it today and start playing with it. We’d love to hear your feedback.

ReSharper 6 Enhances Razor Support

Previous posts introducing ReSharper 6:

 

Razor is the new View Engine introduced by Microsoft in ASP.NET MVC 3. If you have worked with ASPX View Engine, the default one up to version 2 of MVC, you’ll certainly appreciate the simplicity and ease of use of Razor. It makes the flow of HTML vs Code much easier to the eyes and to work with. In ReSharper 6, we are enhancing Razor support in Visual Studio by adding a series of features that will make it even better to work with.

 

 

Importing Namespaces

ReSharper 6 now automatically imports the specific namespace for your model:

 

Hitting Alt+Enter (QuickFix) will add the using statement

image

If you prefer to have a fully qualified name, that is:

image

you can change the setting under the Namespace Imports for C# under ReSharper Options (we are looking at the possibility of making this setting independent from general C# settings).

 

Creating from Usage

If a specific Model does not exist, ReSharper now allows you to create it from usage:

image

placing the Model automatically in the Models folder:

image

 

Helping with Sections

Razor has support for Sections. ReSharper enhances this support by providing Code Completion for Sections. The following shows a section defined in the _layout.cshtml file

image

We now get Code Completion for this section in any child page by typing @section

image

This provides us not only with Intellisense, but prevents us from making. If we were to type Footeer instead of Footer, ReSharper would highlight this error

image

Refactoring

Razor files are made up of code and HTML. As such, you also have Refactoring options that are applicable to both languages. For instance, the picture below depicts a refactoring of an HTML tag:

image

whereas the following is a Refactoring of some C# code

image

 

In fact, for ReSharper it doesn’t matter where your C# code starts and where your HTML ends. Just like Razor, ReSharper is capable of providing the correct contextual menus. The following is displayed when prompting the Refactor This menu (Shift+Ctrl+R) on the @text variable

image

 

ReSharper also knows how to handle situations where certain Razor constructs are required based on the outcome of a Refactoring option. Take the following code:

image

if we are to apply the Invert if refactoring, we would obtain:

image

where ReSharper conveniently places the @: which allows mixing of code and plain text.

 

Refactoring Helpers

Razor provides support for two types of Helpers, the classic Extension Methods that were available in the ASPX View Engine and Declarative Helpers, which are new to Razor. Declarative helpers are placed in the same file usually and avoid having to define an extension method or pre-post conversions. Given the following code:

image

 

we can invoke the Refactor This menu (by selecting the input tag line) and select Extract Helper:

 

image

ReSharper prompts us with the following dialog box:

 

image

 

resulting in the following refactoring

 

image

 

Currently Helpers are placed inline in the same Razor file, although we are looking at providing common helpers in App_Code folder as well as Extension Methods.

 

Navigation and Selection

Razor also now supports all the goodness of Navigation and other features of ReSharper such as Extend Selection (Ctrl+W). We can now navigate to and from Razor Views, go to Actions, Controllers:

 

image

as well as User Controls:

image

 

ReSharper Intellisense

We now get the full benefits of ReSharper Intellisense in Razor

image

with Razor-specific entries which allow for easy completion for constructs such as defining Models, Using or Flow statements. Similar to ASPX View Engine, we also get Intellisense for Actions, Controllers and User Controls:

image

and just like ASPX, we can also do Create From Usage:

image

 

On the Controller Side, ReSharper 6 now supports the built-in Scaffolding dialog for creating Views:

 

image

 

which allows us to have the QuickFix of Alt+Enter and take advantage of Visual Studio’s Scaffolding support.

 

Analysis

Last but not least, ReSharper wouldn’t be ReSharper without its in-depth analysis of source code. And Razor support wouldn’t be complete without it either. In ReSharper 6 we provide full analysis of Razor files, providing you with insight on errors, hints, warnings along with their associated QuickFixes:

 

image

along with full right-margin analysis of the file:

image

 

 

Summary

As you can see, Razor support in ReSharper 6 is pretty extensive, although it’s not entirely complete yet. We are still in Early Access Program and would love to hear your feedback, whether they are bug reports or suggestions on how to even make it better. Please download the EAP and play with it and report any issues you find on YouTrack

[IMPORTANT: Please note that some code snippets shown are neither endorsed or recommended. They are merely for demonstration purposes. Code in Views should usually be restricted to View Logic and Rendering]

Mix…Here we come!

We are going to MIX! image

As one of the premier Microsoft conferences focused on Web Technology, MIX is all about Web, and we are going to be there to show what we have in stock for Web Developers.

With the upcoming release of ReSharper 6, which adds support for JavaScript, CSS and HTML, as well as Razor View Engine, and of course our slew of Web Development IDE’s including WebStorm, PyCharm, PHPStorm and RubyMine, you can be pretty certain that there is something that suites you!

Stop by our booth. We’d love to meet you in person!

And as always, our Spending time with you program is open, so if you’d like to meet up at your offices, ping me

ReSharper 6 Introduces Support for JavaScript Unit Testing with QUnit

In ReShaper 6 we have taken the first step to make it easier for developers to work with JavaScript. By providing support for analysis, refactoring and code-navigation, we try and remove some of the difficulties developers might encounter when working with this language. Now we’re taking the next step!

Running QUnit from ReSharper

When it comes to Unit Testing, even some of the more experienced JavaScript developers tend to not pay too much attention to testing their code. Reasons for this include too much friction, lack of understanding on how to test, what framework to use, etc. Although we can’t solve all of the problems, we are going to try and remove a few of them by providing support for running JavaScript Unit Tests in an easier way with ReSharper. And we are starting this by providing support for QUnit, the unit testing framework used by jQuery. You will be able to run QUnit JavaScript tests using the same interfaces you know and love in ReSharper. And the best part of it all, is that it’s really easy! Let’s see how.

1. Define the code under test

First step is to have some code that we want to test. This code can be located in the same file where are tests are (not recommended) or in different files. In our case, we want to test some simple calculator operations:

image

We have placed this code in a file called CodeUnderTest.js but it can be named absolutely anything.

2. Write some tests

Writing Unit Tests in QUnit is pretty straightforward. Whereas with most test frameworks, you’d normally write a class that contains test methods, with QUnit, you call a function test which takes two parameters, a description of the test and the actual code to test, which is passed in as a function:

image

We place this code in a file called CalculatorTests.js (again, can be named anything). Our project structure now looks like this:

image

Since our tests are located in a file different to that of our tests, we do need to tell ReSharper which code we are referring to by using a specific reference notation at the top of the test file:

image

As soon as we add the tests, ReSharper will detect that these are QUnit tests and provide us with the ability to run them by placing the Test Runner menu in the left gutter:

image

providing us with the ability to run the tests:

image

We can now run individual tests and get the output displayed in the ReSharper test runner:

image

Notice how the tests are grouped under “Calculator tests”. This is done using the module function which allows grouping of tests:

image

When the tests are run, ReSharper launches the default system browser which runs the tests and reports the information back to ReSharper. Normally, to run QUnit tests, you would need to create an HTML file that runs the them. This is handled internally by ReSharper, so it’s one less step to perform.

image

If you prefer to use a specific browser to run the tests, you can do so by changing the browser under the ReSharper Options | Tools | Qunit

image

There is still more to come…

Currently, ReSharper is bundling the latest available version of QUnit (at the time of building). We will be adding support in upcoming releases which will allow you to use your own version of QUnit. Also, we will be looking at providing access to the HTML file that ReSharper generates, allowing better support for Continuous Integration environments, as well as the possibility of running the tests from the browser directly.

When can you play with it?

Right now! The public EAP build includes this functionality. Download it from here the ReSharper 6 Early Access page.

And as always, feedback welcome. Feel free to provide comments here or using our issue tracking system where you’ll not only be able to monitor the status of a feature but also get people to vote for it.