Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News ReSharper 2023.2 IDE Includes Predictive Debugger

ReSharper 2023.2 IDE Includes Predictive Debugger

At the beginning of August, JetBrains introduced a predictive debugger in the 2023.2 version of ReSharper, its developer productivity extension for Microsoft Visual Studio. The predictive debugger anticipates the future of code execution without actually executing the code and provides visual cues to aid in understanding code behavior.

With regular debugging, when a breakpoint is triggered, developers can explore the program's state for that given point in time. To inspect the values of the following statements, developers need to step through the code and evaluate expressions manually. In contrast, the predictive debugger runs through the rest of the method and evaluates all lines of the code. ReSharper will then highlight expressions and show inline hints to indicate future values and states. Below is an example showing the predictive debugger in action:

In this example, the return "Not a number"; statement is "grayed out", as this code path won’t execute. The result > 0 expression is highlighted in green, indicating that it will evaluate to true, and the result < 0 is highlighted in red as it evaluates to false. The blue inline values show predicted values, while a yellow hint indicates where the prediction ends because of a return statement or an exception.

The predictive debugger integrates with Edit & Continue and will update the highlights and hints accordingly:

Users can also edit the variable values on the fly, and the predictive debugger will reflect the changes on the fly:

When the predictive debugger runs, it doesn’t evaluate functions that can have side effects to make sure the system state doesn’t change. In the above example, users must confirm the evaluation of the int.TryParse method:

To avoid the requirement to confirm the evaluation, developers can apply the PureAttribute, which indicates that a method doesn’t have side effects and doesn’t make any observable state changes. The predictive debugger considers the attribute and will evaluate pure methods without manual confirmation. The original release post shows an example of how the predictive debugger can tell the result of the GetCommitFromHead method once the PureAttribute is applied to all functions:

In the beta version, it is possible to apply annotations only to the current project’s source code. JetBrains plans to support external annotations to mark code from other libraries as pure. This way, developers can mark methods such as File.Exists or int.TryParse as pure functions. Another current limitation is that no support for async/await is provided, as the debugger doesn’t allow multithreaded evaluations.

The predictive debugger is currently in Beta and only available in ReSharper, with Rider support expected in the future. To try the predictive debugger, users must enable it from the ReSharper options page under Tools | Debugger | Editor Integration | Predictive Debugger.

The 2023.2 release also introduces significant new features for C# support, such as enhanced support for raw string literals, new inspections for local functions, and new inspections for disposable objects. It also comes with performance improvements and solutions for common Entity Framework issues. A notable addition is the AI Assistant, an AI-powered chat that can explain code fragments, identify potential issues, and generate code snippets and documentation.

The .NET community received the announcement of the predictive debugger positively. On X (formerly Twitter), the announcement tweet received more than 70 likes, and readers left positive comments on the Hacker News discussion as well as on the Reddit post.

The JetBrains team calls on developers to test the new feature and report bugs or to make suggestions on the JetBrains issue tracker.

About the Author

Rate this Article