CSS Support in ReSharper 6February 15th, 2011 by Jura Gorohovsky
ReSharper 6 EAP has been available for about 1.5 months, and it’s time to move on zooming into new features that this new version brings.
Syntax/Color Highlighting and Palette
ReSharper applies its own highlighting to CSS syntax including properties and functions:
Property values representing colors is another item that ReSharper highlights and provides additional assistance for. Every color value is underlined with a respective color, and there’s a quick-fix available to help change the color:
As soon as you select the quick-fix, ReSharper shows the Select Color window that contains controls to fine-tune the color based on any property:
Whenever ReSharper fails to validate a CSS symbol, it leaves a mark on the marker bar and, when you hover the mouse over the error, tells you what it expects to see:
File Structure and Go to File Member
File Structure and Go to File Member have both successfully arrived to CSS files:
These navigation features fully support lowerCamelCase search, enabling you to instantly land at selectors with tricky names, like this:
The same technique can be applied to properties.
You can easily find where a certain CSS property or selector is used both within the current file and in a larger scope. For example, when you have multiple CSS files in your solution, applying Find Usages over a selector in one of these files finds all occurrences of the selector in all remaining files:
ReSharper provides its own IntelliSense in CSS files and in other file types where CSS can be used. It helps you complete HTML tag names, including those introduced with HTML 5:
It lists available HTML attributes in a similar way after the opening bracket:
In fact, ReSharper code completion helps in multiple scenarios when you specify selectors. For example, it provides a list of available pseudo-classes after colon:
Sure enough, ReSharper code completion suggests available properties…
…and property values:
On top of that, ReSharper suggests available classes when you’re invoking code completion inside the value of the
…and available id’s within the
id attribute in HTML or ASP.NET markup files:
To sum up most significant benefits of ReSharper code completion in CSS over Visual Studio native IntelliSense:
- ReSharper provides completion for all kinds of selectors, including elements, .classes, #id’s, [attribute]s, and :pseudo-elements in CSS files.
- Both ReSharper and Visual Studio provide completion for properties and values in CSS files. However, ReSharper code completion supports lowercase CamelHumps, letting you complete
background-colorby only entering
- Both ReSharper and Visual Studio complete usages of CSS classes in markup files but ReSharper goes further by completing usages of id’s.
Naturally, the majority of ReSharper refactorings are not applicable in CSS, but some of them could work there just fine. The first refactoring to be provided in CSS is the Rename refactoring.
With ReSharper 6, you can rename a class selector — both from its declaration in a CSS file and from its usage in markup files.
Of course, whichever way you choose, all usages of the class selector in markup and all CSS files are updated accordingly. In addition, as you would expect, ReSharper will let you rename any occurrences of the old selector name in comments:
A couple more CSS-specific refactorings are in the works, as well as other nice CSS support features here and there.
Download ReSharper 6 EAP builds and explore the goodies!