ReSharper in Detail: Quick-Fixes vs Context Actions
Of all ReSharper’s features, two are most noticeable: context actions and quick fixes. Along with marker bar, these are exactly what a user sees every time he works with a real-world solution.
It’s pretty obvious what these features do – both offer drop-down lists filled with various available actions for modifying your code. However, specific differences between context actions and quick-fixes are not readily evident. Bearing that in mind, we will compare the two features below.
Availability of quick-fixes and context actions for a code position is designated by two differently colored bulb icons to the left of current line:
- red for quick-fixes, and
- yellow for context actions.
Whenever both quick-fixes and context actions are available at a specific caret position, a red bulb is displayed.
When any of two bulbs is displayed, pressing Alt+Enter launches a drop-down list with all available quick-fixes and/or context actions. If only quick-fixes are available, the list looks like this:
If only context actions are provided:
If both quick-fixes and context actions are available:
Quick-fixes are specifically designed to fix any code with highlighed errors, warnings, suggestions, or unused elements. In other words, wherever you see a code item marked with a red, green or blue curly underline, or a symbol highlighted in grey, you can bet there’s a quick-fix provided. Applying a quick-fix at a specific line can cause code modification in any other corner of your solution. For example, the “Create Method” quick-fix applied upon a call to a nonexistent method causes ReSharper to create the corresponding method after the current method ends or in another class:
Another example would be triggering a quick-fix over a method call to modify the type of an argument in the corresponding method declaration, which can possibly reside in another file:
On the contrary, context actions serve to provide ways to change your code instantly. They’re not associated with any discovered errors but displayed merely because they might be useful to you. After all, if you’re looking to surround a string with a
string.Format() call or merge two nested
if statements, it’s much easier to do with context actions than by hand.
Since quick-fixes are tied to the results of code analysis, they’re only applied to C# code. As for context actions, three separate sets of them are available for C#, VB.NET and XML.
For both C# and VB.NET, you can explicitly choose which context actions to enable. That can be done using language-specific Context Actions tabs in ReSharper Options. No comprehensive list of quick-fixes is available to a user and you can’t disable quick-fixes associated with compilation errors one by one – however, you can abandon code analysis altogether (to do that, clear Enable code analysis in ReSharper | Options | Code Inspection | Settings). You can also fine-tune the list of displayed warnings and suggestions that have quick-fixes associated with them (ReSharper | Options | Code Inspection | Inspection Severity).
For examples of using context actions and quick-fixes in practice, see the following links:
- ReSharper Horizons: Jedi Way – Implementing Members
- ReSharper Horizons: Transforming Conditionals
- Joe White’s Blog: ReSharper, day 17: Change All with Alt+Enter (and, Introducing the red light bulb)
Subscribe to Blog updates
Thanks, we've got you!
Another Look into the Future with Rider’s Predictive Debugger
In the 2023.2 release cycle, we’ve introduced the Predictive Debugger in ReSharper, which gives you predictions about code paths and variables beyond the current execution pointer. We’ve written extensively about its advantages compared to alternative debugging strategies like thorough thinking, log…
Visualize Entity Framework Relationships and Additional Query Analysis in ReSharper 2023.3
A lot of teams are using Entity Framework or EF Core to work with their database. As an Object-Relational Mapper (ORM), it bridges objects in code to a relational database model, so that as a developer you don’t have to worry too much about the actual database. We all know: that’s not entirely tr…
Automatically Analyze ASP.NET Core Performance With Dynamic Program Analysis
Slow web pages may make your users or customers abandon your web application, even before they’ve had a proper look at it. You’ve likely also been frustrated working with a web application that is slow to load. The good news is that the latest versions of ReSharper and JetBrains Rider’s Dynamic P…
OSS Power-Ups: MassTransit – Webinar Recording
The recording of our webinar, OSS Power-Ups: MassTransit, with Chris Patterson, is available. This was the thirteenth episode of our OSS Power-Ups series, where we put a spotlight on open-source .NET projects. Subscribe to our community newsletter to receive notifications about future webinars.…