May 11th, 2022

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

Peter Groenewegen
Senior Software Engineer

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! 

Author

Peter Groenewegen
Senior Software Engineer

Peter is a Software Engineer on the Visual Studio IDE team, where he's been integrating ML and AI in developer tools. He currently working on AI tools for developers.

11 comments

Discussion is closed. Login to edit/delete existing comments.

  • A L

    Hello,

    is the other way around also possible? Most of the time you want to inject an existing Service into an Constructor, when the Constructor is already there.

  • James Rolfe

    Any plans to port this convenient feature to VB.NET? If you don’t have enough VB code to train IntelliCode, you can use C#->VB converters.

  • Krzysztof Kalukin

    Is it going to be available in Visual Studio for Mac 2022?

  • Guillermo Mazzari

    Does Intellcode offer any advantage over copilot? If so, which ones? Thanks!

    • Aaron YimMicrosoft employee · Edited

      Hey! Aaron from the IntelliCode team here – the key differentiator between the two autocomplete experiences is that Copilot leverages CODEX & cloud inferencing to provide multi-line autocomplete. IntelliCode relies on GPT-C model inferenced entirely locally, can complete up to one line of code at once.

  • Boggs, Daniel

    17.3 or 17.2?

  • Lân Bùi Tấn

    Thanks, I want VisualStudio can auto suggest class, method, when its namespace is not imported in file

    • Mika DumontMicrosoft employee

      Thanks for taking the time to provide this feedback! We do have this but it is currently disabled by default. We hope to enable it soon by default but in the mean time you can enable it in Tools > Options > Text Editor > C# > IntelliSense and check off `Show items from unimported namespaces`.

      • Guillermo Mazzari

        Hi Mika! Does this work with Github Copilot?

      • Peter GroenewegenMicrosoft employee Author

        When Copilot is on in Visual Studio we do not do disable displaying of IntelliCode code suggestions in the editor. You can toggle this by disabling and enabling Copilot at the bottom of the editor.