Archive for the ‘ReSharper Tips&Tricks’ Category

Machine.Specifications for ReSharper 6 now available

Wednesday, July 20th, 2011

Many, including myself 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.

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’s 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.

Preventing Items from being analyzed in ReSharper

Sunday, June 26th, 2011

With the imminent release of ReSharper 6, and support for JavaScript as well as CSS, we’ve had a few people ask us how to prevent ReSharper 6 from detecting issues in certain files that are not supported, for instance .less. Although many operations are available for these types of files, including “Move To Folder” (and consequent reference updates), analysis is not currently available.

Eliminating Items from Analysis

ReSharper allows us to completely exclude specific files and folders from Analysis. Currently, it does not support file masks, so we cannot tell it to ignore all *.less files. What we can do however is place all files of a certain type into a folder and add that folder to be excluded. To do this, we first move the specific files by using the “Move To Folder” refactoring and create a new folder called less for instance (which can be created using the same dialogue box).

In order to now exclude this folder, we need to go to ReSharper | Options | Code Inspection |Settings

SNAGHTML2c0fc9

and click on the Edit Items to Skip button.  This now provides us the ability to add specific files and/or folders to list of items to skip.

SNAGHTML2d02ce

We then click on Add Folder and select the newly created folder (less).  Once we do that, all analysis on the skipped items will stop. Obviously this is available for any kind of file so you can add anything there.

Note: You can also add/remove files and folders quickly by pressing the shortcut key Ctrl+Shift+Alt+8.

In the case of CSS/.less, if you still see squiggles under certain elements, that is Visual Studio error highlighting, not ReSharper. You can turn that off using Tools | Options | Text Editor | CSS | Miscellaneous.

Generated Code

Below the previous menu option, there is another entry Generated Code:

image

How is this different from the above? The entries on this page, which do allow masks (as well as regions), do get analyzed, yet no hints, warnings, suggestions or quick fixes are offered since it does not make much sense. However, and this is important, files still do get analysed to provide error information and completion. This is what makes Generated Code different from Items to Skip.

Note: In ReSharper 6 and below, Generated File Masks and Generated Code Regions are GLOBAL and not Solution based. However, they can only be edited when a solution is open. This will be solved in a future release along with other improvements in the area of settings across solutions/projects.

ReSharper Tips and Tricks Video from NDC

Wednesday, June 22nd, 2011

We at JetBrains have recently visited the awesome NDC conference. In addition to booth activities and regular sessions (which you can download from the official NDC web site), Hadi Hariri has presented a semi-impromptu session called ReSharper Tips and Tricks that we know that some of you wanted to attend (and hopefully attended.) The session was recorded and kindly provided to us by the organizers, and is now available on JetBrains TV.

Since the complete session is worth an hour of video, and we only expect selected geeks to handle it in its entirety, we decided to also make several parts of it available as standalone videos, and we have five of them, namely:

Please watch and learn things about ReSharper that you probably haven’t known before!

Use Alt+Enter in Microsoft Word for spell checking quick-fixes

Tuesday, April 19th, 2011

Sometimes we receive feedback on the most popular ReSharper keyboard shortcut, Alt+Enter, not being available outside of Visual Studio. This is a bit confusing for ReSharper users working in Microsoft Word where spell-checking comes with a curly underline for grammar and spelling errors in document — similar to how ReSharper highlights errors and warnings in Visual Studio. Proofing suggestions in Word are by default applied with a right mouse click or an unfamiliar shortcut, which kind of slows down document editing for ReSharper (or IntelliJ IDEA) users.

Here are some easy steps to make the renowned Alt+Enter shortcut to apply “quick-fixes” as well as navigate between errors in Microsoft Word documents. The following guide is based on Microsoft Word 2010; however, the steps are very similar in previous versions (for example, Word 2007 or 2003).

  1. Open the Word Options dialog box by choosing File | Options (Word 2007: Office button | Word Options.)
  2. Click Customize Ribbon (Word 2007: Customize.)
  3. Click Customize in the Keyboard shortcuts area (in Word 2003, the button can be reached by selecting Tools | Customize | Commands.)
    File | Options | Customize Ribbon dialog, Customize button
  4. In All Commands category, find a command called NextMisspelling. It is mapped to Alt+F7 by default.
  5. In the Press new shortcut key field, press Alt+Enter (it will be displayed as Alt+Return in the dialog):
    The Next Misspelling command, which needs to be remapped
  6. Click Assign, and you’re done!

Now gently close all dialogs and enjoy Alt+Enter displaying the spelling correction menu in Microsoft Word! Note that you can even press it anywhere in a Word document (not necessarily directly on a curly underline) to navigate to the next spelling or grammar error, and open the correction menu upon it:

ReSharper 6 Enhances Razor Support

Monday, April 18th, 2011

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]

Pluralsight’s Weekly Webcast: ReSharper Tips and Tricks

Wednesday, April 6th, 2011

James Kovacs just keeps on rocking! Following the launch of the online ReSharper training course by Pluralsight last month, James follows up with a webcast called “ReSharper Tips and Tricks”.

Make sure to join the webcast tomorrow, on April 7, 11:00 AM EDT, to learn new ReSharper gems and challenge James with your questions. He says the webcast will be useful for both ReSharper rookies and experienced users.

Access to the live webcast is open and free for everyone!

ReSharper 6 Introduces Support for JavaScript Unit Testing with QUnit

Friday, March 25th, 2011

Previous posts introducing ReSharper 6:

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:

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:

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

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:

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:

providing us with the ability to run the tests:

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

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

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.

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

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.

ReSharper 6 Enhances Suggestions with Explanations

Tuesday, March 22nd, 2011

Previous posts introducing ReSharper 6:

One of the new features we have added to ReSharper 6 is the ability to find out why ReSharper makes certain suggestions. Often, ReSharper can provide a suggestion such as the one shown below:

image

For some people this might be clear, whether or not they would agree with the suggestion. For others it might make little sense, specially developers that are often new to the language or framework. In ReSharper 6, we have added a feature* which provides more information as to why these suggestions, hints or warnings are made:

image

When invoking the QuickFix, by pressing Alt+Enter, ReSharper now provides a new entry which is “Why is ReSharper suggesting this?”. By clicking on this entry, you will be redirected to a Wiki on the JetBrains site where you will be provided with more detailed information in regard to the suggestion. For instance, when being displayed with the following:

image

By selecting the “Why is ReSharper suggesting this?” action, the Wiki site will show the following information:

image

Currently we have over 40 entries in the Wiki and are continuing to add more entries. We will also be updating and reviewing them with more examples were required. As always, please let us know if you have any feedback.

* There is a plug-in which is available for previous editions of ReSharper called WhySharper, which this idea was partially based on. We realized however, that to make sure the information is kept up to date, it would be better to have this functionality built into the product.

48 Hours of Free Access to ReSharper Training Course from Pluralsight

Tuesday, March 15th, 2011

Yesterday, we’ve announced the brand new Pluralsight training course that can make you and your fellow developers experts in ReSharper.

Here’s even more exciting news: starting today, March 15, 16:00 GMT, Pluralsight provides 48 hours of free access to the full ReSharper course — you don’t even have to register!

Don’t let this opportunity pass! Take this course now to become an expert ReSharper user!

Priceless: Online ReSharper Training from Pluralsight

Monday, March 14th, 2011

Our good friends at Pluralsight have today made available their brand new online ReSharper training course.

How cool is that?!

Specifically, the course is the offspring of Pluralsight expert and JetBrains Academy Board member James Kovacs (@jameskovacs on twitter).

Hats off to this courageous evangelist!

This course covers everything you need to know to become a proficient ReSharper user: navigation, code analysis and coding assistance, refactorings, code cleanup, code generation and templates, unit testing, internationalization, and technology-specific ways to use ReSharper efficiently, including its capabilities in ASP.NET/ASP.NET MVC, XML, WPF, Silverlight, MSBuild & NAnt. James even talks JavaScript and CSS support, which will only be available in the upcoming ReSharper 6.

This course is a great value for everyone, and here’s why:

  • If you have just recently started using ReSharper, or if you haven’t yet taken the time to dive into the multitude of its features, you simply owe it to yourself to take this excellent course.
  • If you’re staying away from ReSharper because you think it’s no better than plain Visual Studio, this course will challenge you to think out of the box - and perhaps be converted.
  • Even if you’re a long-time ReSharper user, we bet you’ll see some exciting things about the tool that you never knew existed.

Anyway, taking this online ReSharper training course may very well be one of the best possible ways to invest your time. Even more so considering that Pluralsight provides a free 200-minute trial, and their monthly single-user subscription stands at as low as $29. And if this wasn’t enough, the guys at Pluralsight are preparing a special offer for everyone interested in ReSharper, so watch closely for more announcements very soon!