Just-in-time refactoring made even easier with IntelliCode auto suggested code for C#

Peter Groenewegen

Have you ever wondered if there was a tool to help you with routine code tasks like writing common constructors or inserting similar code to a few different spots? Maybe you even know some code actions or refactorings that can help you. But at the time you could have used the code action, you typed the change instead, because you remembered the code action too late or forgot about it.”

Since the release of Visual Studio 2022, IntelliCode has code actions and refactorings for common tasks in the IntelliSense list. In Visual Studio 17.3, these code actions and refactorings are now offered as auto suggestion code upon typing. You can accept auto suggested code by pressing [Tab].

How it works

In the video, you’ll see how IntelliCode detects three common patterns: 

  • Creating a constructor 
  • Adding parameters to that constructor 
  • Repetitive code changes that only involve adding new code 

IntelliCode suggests the code change as an auto suggested code insertion. If the suggestion is correct, you can use [TAB] to insert the code change. if the suggestion is not the code you intended to write, you can either continue typing, or press [ESC]. Under the hood, intent detection is made possible by the PROSE engine. The code suggestion offered is generated either by PROSE, or by the .NET compiler platform (“Roslyn”).  

Try it now

These new IntelliCode suggestions will be enabled in the latest version of Visual Studio 2022. Visual Studio will support more refactorings in future versions. Let us know in the comments or on social media which scenarios would help you! 

10 comments

Leave a comment