ReSharper 2020.3: Support for C# 9 and Source Generators, New Features in Inlay Hints, and Support for Avalonia UI
Hello everyone and welcome to ReSharper’s third and final release of the year!
With C# 9 recently released, ReSharper 2020.3 was destined to be about supporting new language features with our entire tool set. Of course, Source Generators had to be covered too. We also managed to implement long-awaited support for the Avalonia UI framework, and we added some new features to help with your daily routine. Let’s dig into these improvements.
Record types introduced in C# 9 are reference types with value semantics. They go perfectly with
init-only properties that can only be set during the initialization of an object. This means you can now achieve immutability, for the whole object or just for the property, and keep using object initializers.
ReSharper is keeping up with these changes, from code style settings to quick-fixes.
For positional records that have a compiler-generated
Deconstruct() method, ReSharper offers a deconstructing declaration when appropriate.
Local functions have received new features in C# 9.0: their parameters and type parameters, as well as the local functions themselves, are now allowed to have attributes. ReSharper now has quick-fixes for that.
With top-level programs, entry-point code can be placed right after the
using directives – that’s right, no namespace or class is required. There are, however, some rules: only one file per project can contain top-level code, and top-level sentences should indeed be placed on top, meaning they should precede any type or namespace.
ReSharper is here to help if you break any of these rules when moving your code around. Also, the Extract Method and Extract Local Variable refactorings are available in top-level code.
One more thing that’s no longer necessary is the type after the
new keyword – if it can be inferred from the context, of course. This is called target-typed
new expressions. ReSharper provides syntax style options for the new construct, and the Find Usages feature on the constructor.
What about pattern matching? Well, here we have relational and logical patterns, and all of them can now be used in matching expressions. Again, ReSharper can help you apply the new style.
ReSharper also covers smaller language updates, with static lambdas and lambda discard parameters, target-typed conditional expressions, native integer types, extension GetEnumerator methods in foreach, and function pointer types.
What can ReSharper do about probably the hottest feature in the new C# compiler? What it does best: let you do your thing and lend a helping hand without getting in your way. Generated files are taken into account in refactorings and code editor features such as completion, and navigation can take you to the generated code.
Inlay hints can take one more thing off your mind. But what if you don’t need them all the time? What if you would want only to summon them temporarily, as a magical helper? Well, this is now possible with the new Push-to-Hint visibility mode in Settings. In Push-to-Hint mode, the hints will be shown if you press and hold Ctrl (and hidden as soon as you release it) or press Ctrl twice (in which case they remain visible until you press Ctrl twice again).
You can specify different visibility modes for different hints types and different languages.
Speaking of hints types, we have a new one! Implicit type casts are now marked right in the code. Ctrl+Click on a hint will navigate you right to the implementation of the conversion.
Support is now available for the Avalonia XAML UI framework. Unleash the whole ReSharper arsenal: code inspections with appropriate quick-fixes for both C# code-behind and .axaml files, including Avalonia-specific inspections, code completion and other editor features, navigation, and refactorings.
Go to Text (or Find Text) now has one more inner tool to help you navigate in your project – fuzzy search, which takes into account possible typos and even missing words. The results are displayed below the results of the regular exact search, both in the popup and in the Find Results view.
In addition to helping find mistyped text, it can help when you’re not sure about the exact wording, or when you need to find where a formatted string is built.
We’re always updating the set of formatting options to help you see your code arranged exactly how you like it. In this release, we’ve added a group of settings for property patterns, which allow you to enable alignment in columns, place a simple pattern on a single line, and specify how to wrap long patterns. Also, blank lines can now be added around property or event accessors.
There have also been some additions in the .editorconfig department. First, ReSharper now supports the Roslyn properties
dotnet_separate_import_directive_groups. Second, the “Spaces around ‘=’” setting is now exported to .editorconfig. It’s detected automatically in existing files, and it can be set manually for new files. It is set to ‘true’ by default.
Dynamic Program Analysis
Imagine your code being analyzed for memory usage during the usual cycle of running and debugging. All you would have to do is work on your project, and occasionally get a report about closures and allocations exceeding the specified thresholds (or see a green light and pat yourself on the back).
Introducing Dynamic Program Analysis (DPA)! Silent, configurable, and a perfect companion to the Heap Allocations Viewer plugin. Check out the dedicated blog post to learn more about DPA in ReSharper.
Have you ever selected a piece of code with structural navigation, deleted it, and found yourself left with an extra comma? Things like that can be pretty annoying. ReSharper is now smarter and tries to not only select structurally, but to delete structurally as well. A tiny act of care!
Command Line Tools
First, a little time-saver: the CleanupCode console tool can now reformat the specified set of files or folders without pointing to the solution file. No need to wait for the whole solution to be scanned after you’ve just added a couple of files. The command line will look like this:
cleanupcode.exe [Path to folder] [Path to file] [Path to another file]
Please note that the tool only formats the code – cleanup isn’t available in this mode.
Second, plugins are back, but only on Windows for now. InspectCode and CleanupCode are now able to automatically download and enable plugins. You’ll need the plugin ID: go to JetBrains Marketplace, open the plugin page, go to the Versions tab, click on any version, and grab the plugin ID. After that, use the
-x=[ID] key like that:
cleanupcode.exe -x=[ID] [Path to solution file]
Please note that the plugin has to be compatible with the tool version. Also, plugins are not yet supported if you’re using the .NET Core global tools mechanism to install ReSharper’s CLT.
Private Source Link is now supported in the integrated decompiler. When navigating to the external sources that require a connection to a private source server, ReSharper will ask for your credentials – unless they have already been entered in Visual Studio’s settings, in which case they will be applied automatically (for GitHub and BitBucket).
We’ve also implemented some less visible but still important internal updates: improved the synchronization between IL Viewer and the source code, and updated the decompiler to understand new C# 9 features.
- In Blazor support, we’ve been working on supporting generic type parameters and their type inference from usages, and minimizing performance setbacks.
- We’ve added a new quick-fix that helps you transform a sequential pattern check into a complex pattern-matching check.
- Nullable annotations are supported on unconstrained generic types (including default constraint).
- A modest update for TypeScript support: ReSharper now supports nullish coalescing and optional chaining.
- Inside the Change Signature refactoring, we’ve redesigned the ‘Resolve with call tree’ tool.
Quite a few bugs have been fixed, of course. You can find the full list in our public bug tracker.
For even more details about this release, head over on to the What’s New in ReSharper page.
ReSharper C++ 2020.3: the perfect game dev companion for Unreal Engine
With the newest ReSharper C++ 2020.3 update, Unreal Engine developers can take advantage of the editor integration with UnrealHeaderTool, an improved project model, and new inspections based on control flow analysis in HLSL shader files. We’ve also taken another step toward full C++20 support by implementing the C++20 comparison rules and adding new inspections to help you adopt the C++20 ranges library.
Among other highlights:
- Improvements in import completion and a context action to invert a ternary expression.
- Navigation for matching preprocessor directives, Peek Implementation, and Peek Base Symbols.
- New modernizing inspections and Clang-Tidy 11.
Updates to Catch2 support and
Most updates in this release of dotPeek have to do with C# support and data presentation:
- More C# features handled, including static local functions, attributes on local functions, and init-only setters.
- A <Top-level Entry Point> node in Assembly Explorer to present the top level code.
- In IL Viewer, there’s new context highlighting for the custom attribute owner, and improved highlighting for function exits.
- A Locate in Metadata action for declarations and usages in the source code or IL code and for items in Assembly Explorer.
- Support for Private Source Link.
For more information, please visit the What’s New in dotPeek page.
- dotTrace now lets you profile .NET 5 applications.
- dotCover now lets you perform coverage analysis of applications targeting .NET 5.
- You can now specify which projects should be built when a continuous testing session is triggered, which helps speed up continuous testing sessions.
- The Unit Tests Coverage window in Visual Studio lets you filter coverage results by target framework.
- dotMemory now lets you profile .NET 5 applications.
- We’ve added inspections on the Timeline graph: High Garbage Collection pressure, Pinned objects in Gen0, and Fast Large Objects Heap growth rate.
- The Heap Fragmentation view now shows the Pinned Objects Heap – a separate heap segment introduced in .NET 5. dotMemory also shows memory allocated to the Pinned Object Heap in real time during profiling.
Please let us know about your experience with the 2020.3 release. Use the comments section below, social media, or our bug tracker. Thank you!
Your ReSharper team