Context actions are code transformations helpers available right in the editor. In contrast to quick-fixes, context actions do not aim to resolve a problem or improve your code, instead, they allow you to quickly introduce minor changes like changing access modifiers, generating a code that checks for null, convert 'foreach' to 'for', etc.
ReSharper provides hundreds of context actions in all supported languages. You can find all of them in the ReSharper options. For example, here is the full list of context actions in C#: ReSharper | Options | Code Editing | C# | Context Actions.
In this topic:
Applying context actions
As soon as a context action becomes available for the current caret position, ReSharper displays the corresponding action indicator to the left of the caret. Sometimes, however, ReSharper provides several contextually available features for the current caret position. In this case, the action indicator corresponding to the action with the highest priority is shown, and all other actions only appear when you expand the action list by clicking on the action indicator or pressing Alt+Enter Context actions have the lowest priority, therefore, they often appear in the bottom of the action list:
In most cases, a context action is applied immediately. However, some actions require user interaction to chose how exactly they transform your code. In these cases, a Hot Spot Session is deployed in the editor, where you can select one of the suggested values or provide your own values in the active input positions.
After creating the
statement, a hot spot session helps you complete editable parameters of the generated statement:
To complete the hot spot session:
- If ReSharper suggests some values for the current parameter, use Up and Down arrow keys to navigate through the list of suggested values, or just type in a desired value.
- Press Tab or Enter to accept the value and move to the input position of the next parameter. If this is the last parameter, the hot spot session completes and the caret moves to the end position defined for the session.
- Press Shift+Tab to move the input focus to the input position of the previous parameter.
- Press Esc to exit the hot spot session. In this case, all session parameters will be initialized with default values.
Configuring Context Actions
By default, most of the context actions are enabled, but you can easily disable those that you consider unhelpful.
To enable or disable specific context actions
- In the main menu, choose .
Use the search box in the
dialog to find specific context action.
Alternatively, open the or pages and look for the context actions that you want to disable.
- Clear the check box next to a context action to disable it.
- Click Save to apply the modifications and let ReSharper choose where to save them, or save the modifications to a specific settings layer using the Save To drop-down list. For more information, see Managing and Sharing ReSharper Settings.
Applying context actions in wider scope
Some context actions can automatically find and change similar code items in a larger scope - in the current file, in the current project or in the whole solution. These context actions work the same as Fix in Scope. For example, you can move all types from the current file to new matching files:
The full list of context actions that can be applied in wider scopes includes:
- Move to '.cs'
- Remove region/endregion directives Remove region/endregion directives
- Use 'var'
- Specify type explicitly
This feature is supported in the following languages/technologies:
The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.