September 5th, 2019
0 reactions

Refactoring made easy with IntelliCode!

Principal Program Manager

Have you ever found yourself refactoring your code and making the same or similar changes in multiple locations? Maybe you thought about making a regular expression so you could search and replace, but the effort to do that was too great? Eventually you probably resigned yourself to the time-intensive, error prone task of going through the code manually.

What if your developer tools could track your edits and learn about the repeatable changes you were making? After only a couple of examples they would spot you doing something repetitive and offer to take the remaining actions for you? With Visual Studio 2019 version 16.3 Preview 3 we are happy to announce that refactorings can now be enhanced by IntelliCode. IntelliCode spots repetition quickly and suggests other places in your code where you might want to apply that same change, right in your IDE:

 

Try it now

Refactoring is a preview feature of IntelliCode, so when you get Visual Studio 2019 version 16.3 Preview 3  it will be off by default. Visit the Tools-Options page, IntelliCode General tab, Preview features area, and switch C# refactorings to “Enabled” to turn it on.

Once you change this setting, close any files you may have open, then restart Visual Studio:

How to turn on the refactorings feature in tools-options

How it works

Under the hood, IntelliCode looks at each of your edits as you type. It uses PROSE (PROgram Synthesis by Example) to synthesize generalized edit scripts that can take your code from the “before editing” state to the “after”. When IntelliCode discovers that it can apply one of these scripts elsewhere in your code (which can be based on as few as 2 examples in your code), we let you know via the Visual Studio lightbulb in the margin or when hovering the affected code, and through green “squiggles”. The lightbulb offers actions to apply the refactorings for you. The underlying technology is similar to the Excel’s Flash Fill feature and is described in this research paper. More details will be presented at the upcoming OOPSLA 2019 conference.

This isn’t just tracking text changes – IntelliCode is aware of the syntactic structure of your code. This syntactic awareness allows it to detect cases where the variable names in your refactoring examples differ but the essential structure of the change is the same:

Illustration showing how IntelliCode can detect patterns syntactically and offer suggestions

If you don’t like a suggested change you can select the ignore option on the lightbulb, and we won’t bother you about that detected pattern again unless you recreate it.

Let us know what you think!

We would love to hear about your experiences as you try this new feature. Good or bad, they will help us improve. Please raise issues and comments via Visual Studio “report a problem” .  We’re interested to hear feedback about the recommendations themselves, the performance of the feature, or any capabilities you might be missing. When sending your feedback it would be really useful if you can share details of what was detected and what sort of edits you were making; we’ll follow up.

Author

Mark Wilson-Thomas
Principal Program Manager

Mark is a Program Manager on the Visual Studio IDE team, where he's been building developer tools for over 15 years. Most recently he's been working on AI assisted developer tools like GitHub Copilot Chat for Visual Studio. Prior to that, he worked on the Visual Studio Editor, and on tools for Office, SQL, WPF and Silverlight.

29 comments

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

Sort by :
  • Emiliano Javier González

    Awsome! You people coding stuff like this are awsome! When I grow up, I wanna be like you guys! I’ll check this out!

    Regards!

    • Mark Wilson-ThomasMicrosoft employee Author

      Thanks @Emiliano! Glad you approve 🙂

      Please do let us know how you get on when you try it out.
      Mark

  • Victor Soares

    Awesome, Mark!! I hope to use this feature here in my job.

    • Mark Wilson-ThomasMicrosoft employee Author

      That’s great to hear Victor! Would love to hear how you get on when you try it!
      Mark

  • Yann Duran

    Hey Mark! This sounds like it'd be great for detecting duplicate code, on the fly as it were. And also for repetitive refactoring of code that may be inherited. I've definitely wished for some better way of doing repetitive code refactoring tasks since macros were taken away (yes, I know there's an extension, but it's not the same as it used to be). The storage mechanism should have been C# (or maybe VB, or whatever language was being used), not Javascript. It's been a while since I've looked at it, so hopefully I haven't got that wrong.
    I'm wondering though,...

    Read more
    • Mark Wilson-ThomasMicrosoft employee Author

      Hi @Yann!

      Thanks for your feedback. I'm glad you can see some good use for this feature!

      To take your questions one by one:

      1. "where’s the processing happening. Is it all local, or is there a cloud service out there somewhere that does all the heavy lifting?
      In particular you said “We keep track (of) a certain number of editing ‘sessions’“. My question would be WHERE would those sessions be stored? Locally, or in the cloud?"
      All the processing for IntelliCode refactorings is entirely local. Sessions are stored in memory on the local machine, and culled when you reach the...

      Read more
  • Phillip Mortari

    I kind liked the idea as a first step to help identifying possible portions of code that requires attention/refactoring. There’s any plans or ideas to expand that to something like a “hey – you have these similar pieces on your code, what about refactoring?” thing? I guess that would be something awesome to have it handy!

    • Mark Wilson-ThomasMicrosoft employee Author

      Hi Philip
      Thanks for reading and for your comments. We hope what we've built so far will help you with the case where you've *already found* a couple of places which could use a certain refactoring and figured out what to do, but just need help finding the other target locations. The problem of finding repeated patterns in your code AND then identifying them as good or bad is an even tougher one, but we are certainly interested in it. Are you imagining something that would scan your code for patterns and let you know what they are to decide...

      Read more
      • Phillip Mortari

        Hey Mark – Thanks on the quick response, and sure that helped! Actually this post was my trigger to update my preview.
        I’ll put a few ideas on the paper and definitely I’m sending it to you.

        Thank you!