ReSharper 2020.2 Help

Detect Code Issues in Design Time

ReSharper starts analyzing a code file as soon as you open it in the editor, all the way you edit it, until it is closed. All detected code issues are highlighted in the editor according to their severity levels. The map of the issues is also displayed on the marker bar in the right part of the editor window, where you can see instantly the status of the file and click the marks to navigate to specific code issues.

Design-time inspection features

To illustrate the design-time code inspection performed by ReSharper, consider the following code excerpt displayed in the editor:

ReSharper: Design-time code inspection

In this rather simple example, we can see the following features of ReSharper code inspection:

  1. Status indicator that helps you to see at once whether the current file has errors or warnings.

  2. A fix popup that appears for non-imported types. It is enough to press Alt+Enter or click this popup and ReSharper will add the missing directive for all types in the file. For more information, see Import Missing Namespaces.

  3. A low-priority code issue (in this case, a suggestion related to an unused public member) is greyed out.

  4. A medium-priority code issue (in this case, a warning about a symbol name that does not fit with the naming style) is highlighted with a blue curly underline.

  5. A marker corresponding to the suggestion issue (3) is displayed on the marker bar.

  6. A marker corresponding to the error issue (8) is displayed on the marker bar.

  7. An action indicator that appears to the left of the caret position if ReSharper has anything to suggest there.

  8. A high-priority code issues (in this case, errors related to an unresolved symbol and an incorrect return type) are highlighted with red text and red curly underline.

  9. A marker corresponding to the warning issue (4) is displayed on the marker bar.

  10. The action list, which opens by pressing Alt+Enter or clicking the action indicator (7), contains a list of quick-fixes for the issue at the caret.

  11. A short description of the issue at the caret appears in the status bar. You can also view descriptions of code issues by hovering the mouse over highlighted code or over the issue markers on the marker bar (5,6,9)

  12. If the solution-wide analysis is enabled, ReSharper allows you to see even more code issues. In this example, it detects the unused public member (3) and notifies about errors in other files of your solution. You can click the solution-wide analysis icon to explore the detected issues.

  13. To make missing function returns, missing breaks in switch statements, and disposed resources more noticeable, use Code analysis hints.

Toggle design-time inspection

By default, design-time code inspection is enabled in all supported languages. However, you can disable it everywhere or turn it off for specific files if needed. For more information on configuring code inspection, see Configure Code Inspection Settings.

  1. Select ReSharper | Options from the main menu or press Alt+R O, then choose Code Inspection | Settings on the left.

  2. Use the Enable code analysis checkbox to toggle the design-time code inspection.

  3. Optionally, you can enable or disable design-time inspection features on this page:

    Color identifiers This option lets you enable or disable ReSharper syntax highlighting scheme.
    If it is selected, language identifiers are highlighted with colors as defined in Visual Studio options: Tools | Options | Environment | Fonts and Colors.
    The list of syntax identifiers provided by ReSharper is available in the Display items list, each name starting with ReSharper prefix.
    Highlight color usages Enables highlighting of color definitions in code. For more information, see Color Assistance.
    Highlight special characters in string literals Enables highlighting of correct and incorrect escape sequences in non-verbatim strings. For example:
    Highlighting of escape sequence in strings
    For more information, see Regular Expressions Assistance.
    Highlight context exits This option, enabled by default, tells ReSharper to highlight all places where the control flow can exit the current context. For example, for a method, it will highlight the return type of the method, all return, throw keywords, and so on when you set the caret to one of these identifiers
    ReSharper highlights context exits
    For a loop, it will additionally highlight the loop keyword as well as all the break statements inside this loop.
    Note that if a method is not entirely visible in the editor, you can invoke the Navigate To Function Exits command on the method name to trigger another kind of highlighting, which will not disappear when your caret leaves the method name.
  4. If necessary, you can select the Enable solution-wide analysis checkbox to enable the Solution-Wide Analysis.

  5. Click Save in the Options dialog 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 list. For more information, see Manage and Share ReSharper Settings.

Inspection options menu

Besides suggested fixes, for each configurable code inspection as well as for custom inspections, ReSharper shows the Inspection [name of inspection] ThemedIcon Settings Screen Gray png sub-menu in the actions list, with the following items:

Inspection [name of inspection] sub-menu

Find similar issues

You can not only fix a highlighted issue with a quick-fix, but also find and investigate all similar issues (all issues detected with the same code inspection) in the whole solution or smaller scope.

Find similar issues

  1. Set the caret at a highlighted issue in the editor.

  2. Press Alt+Enter or click the action indicator to the left of the caret to open the action list.

  3. To find similar issues in the current file, choose Inspection [name of inspection] | Find similar issues in [filename] file.

  4. To find similar issues in the current project or solution, expand the submenu and choose the desired scope:

    Using action list to find similar issues

  5. If necessary, you can search for similar issues in any project or solution folder within your solution. To do so, choose Find similar issues in custom scope in the submenu.
    In the dialog that opens, type the name of the desired project or solution folder, and then click OK.

    Specifying search scope for the similar issues

  6. All found issues will be displayed in the Inspection Results window.

Integration with Visual Studio code inspection controls

Starting from version 2015, Visual Studio comes with its own code analysis engine (Roslyn) and provides its own light bulbs feature to perform quick actions including refactoring and fixing errors.

Visual Studio's quick actions often perform the same fixes as ReSharper's quick-fixes, context action, or refactorings. Therefore, for some errors you may have two similar suggestions from Visual Studio and from ReSharper. In the illustration below, you can see two bulbs both suggesting to remove redundant using directives:

Two light bulbs for fixing the same issue

To avoid this, ReSharper provides the Hide Visual Studio light bulb option on the Environment | Editor | Visual Studio Features page of ReSharper options. This option is enabled by default, so you will not see the duplicated bulbs unless you disable it.

If Visual Studio Light Bulb is suppressed, Visual Studio actions can be integrated into ReSharper's action list by selecting the Merge Visual Studio light bulb actions into ReSharper action indicator checkbox. If it is selected, ReSharper does the following for each Visual Studio's quick action:

  • If there is a similar ReSharper's quick-fix or context action, the Visual Studio's quick action is not displayed.

  • If there are no similar ReSharper's action, the Visual Studio's action becomes available in the ReSharper's action list. You can recognize Visual Studio's quick actions by the special icon ThemedIcon YellowBulbVS Screen Gray png.

If necessary, you can also disable Visual Studio's error highlighting in the editor, so that only code issues found by ReSharper are highlighted. To do so, select Hide Visual Studio squiggles on the Environment | Editor | Visual Studio Features page of ReSharper options.

Last modified: 04 September 2020