Making repeated edits easier with IntelliCode suggestions

Avatar

Peter

What if your developer tools could track your edits and learn while you are making changes? What if they could offer to do remaining edits for you?

Your repeated edit experience is now enhanced by IntelliCode suggestions in Visual Studio 2019 16.7. IntelliCode spots repetitions and suggests other places in your code where you could apply that same change.

 

Try it now

IntelliCode suggestions is available for C# from Visual Studio 2019 16.7. Check out the release notes for all the details. 

How it works

Under the hood, IntelliCode looks at each of your edits as you type. Using PROSE (PROgram Synthesis by Example), IntelliCode synthesizes generalized edit scripts that take your code from the “before editing” state to the “after”. When IntelliCode suggestions discovers that it can apply one of these scripts in your code, IntelliCode lets you know via the Visual Studio lightbulb in the margin and when you hover over the affected code. In both the lightbulb and by hovering over the affected code, IntelliCode offers actions to apply the suggestion for you. The underlying technology is like the Excel’s Flash Fill feature and is described in this research paper.

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

If you do not like a suggested change you can select the ignore option on the lightbulb, and we will not bother you about that detected pattern again.

Let us know what you think!

We would love to hear about your experiences as you try this new feature. Your feedback, good or bad, will help us improve. Please raise issues Visual Studio “report a problem”.

 

20 comments

Leave a comment

  • Avatar
    Keith Burgoyne

    This is a really neat feature. I’ll definitely have to give it a try.

    It does, however, bring up the point of the IntelliCode pop-up menus becoming their own time consuming navigation problem with all the things they can contain these days.

    Here is an efficiency improvement idea…

    Maintain a list of the (five?) most recent actions the developer has performed withOUT the developer having used a hotkey to invoke the action. Obviously which entries in this list get displayed would be subject to the context.

    If the developer used a hotkey, clearly the developer is already educated in a quicker way to perform that action. So don’t waste a slot in the list.

    If an entry in the list has a hotkey, display the hotkey to the right like the main menus do to help “educate” the developer on a faster way to perform the operation. (That’s always been my main way of learning new hotkeys. It’s a GREAT way to educate the developer.) The more a developer learns to use an available hotkey, the more list entries will remain available for actions which don’t have hotkeys.

    Assign a standard hotkey to pop-up the list.

    Note how this is a bit like the new Windows 10 multi-entry clipboard.

    Also…

    Add the construct of right-clicking on IntelliCode pop-up menu items to bring up a list of configuration options — most specifically an option for assigning the action to a hotkey.

    There also doesn’t “seem” (at least in my poking around I haven’t found) to be a way to configure VS to not offer some of the IntelliCode options which a developer might never use. Specifically what comes to mind is removing some of the “wrap” and “unwrap” arguments/parameters options which a developer might never use.

    In my case I only ever use one of the wrap options (wrap all and indent), so theoretically I could eliminate the other options and my sole remaining option could be elevated up one menu level.

    I can see where the assigning of hotkeys to IntelliCode actions will present a bit of an intellectual challenge to the VS developers. The “intelligent” way to do it is also context sensitive. The same hotkey should be reusable within different contexts in which the different actions never appear in the same context.

    Or… if a hotkey gets associated with two or more actions that might occur in the same context, that might mean hitting the hotkey pops up a menu for the developer to select between the possible actions. This second idea is probably more “user friendly” since it is less restrictive than the first idea, thus it’s more flexible.

    Probably also easier to implement. No (limited?) need to check for hotkey assignment collisions based on context. Instead VS maintains a list of “possible” actions for each hotkey, and then figures out which actions are applicable within the context when the hotkey is hit. If only one action is applicable, it just invokes. If more than one action, the developer gets a pop-up menu to choose which to perform.

  • Avatar
    Ian Marteens

    I gave the feature a try. Actually, it popped up without being called first. And the suggestion it’s making are pretty silly. I was editing a method for matrix transposing: load this from here, load that from there, store that here, store this there. It got confused by this very simple pattern. I wouldn’t put a cent for buying this if it were on sale.

    • Avatar
      Peter GroenewegenMicrosoft logo

      Thank you for trying out IntelliCode Suggestions! We appreciate your feedback and it would be great if you could give us more details so that we can improve this feature. Could you report this issue to “Report a Problem in Visual Studio”. Please, include the step-by-step process to reproduce it. You can also include the IntelliCode logs on your machine. These logs record the code changes that you did. Please be aware any code you edited during editing your session is included and will remain private to Microsoft. The logs will only used to triage the issue and will be deleted after that.

      Steps to retrieve your logs:

      1. Using File Explorer, navigate to the %LocalAppData%\Temp\VSFeedbackIntelliCodeLogs\Suggestions folder.
      2. Inside the logs folder you’ll find a set of uniquely identified folders. Sort them by date and look for the one that corresponds to the time of the session you were 3. working in when you saw the problem.
      4. Right click and create a ZIP of the folder (Send To > Compressed (zipped) folder).

      Submit it as an attachment with a description of your problem using Report a Problem.

      Feel free to email me if you want to give more details (pegroene at microsoft dot com).

  • Eric Helin
    Eric Helin

    More general question…will there always be an ‘off’ option for suggestions? I like using suggestions during specific periods like code polishing or final versions. When I am prototyping (or just thinking with the keyboard), I find suggestions break my thought process.

  • Avatar
    Felipe Fujiy Pessoto

    It will make refactoring much more enjoyable.
    I’m wondering if it can help to change a sync code to async, where we usually have to change the calls like File.Write to File.WriteAsync().ConfigureAwait(false), make our own method async (add the “async” keyword, change the return type to Task) and repeat the same to all methods that call the method we converted. It is very boring and error prone.

    • Avatar
      Peter GroenewegenMicrosoft logo

      Yes, IntelliCode can learn such suggestions. Do 2 edits and the 3th place should show the suggestion. If it does not learn the pattern, feel free to contact me directly to see why it does not learn the suggestion. An extra tip: if you want a list of all places in the current file where you can apply the refactoring, open the IntelliCode suggestion window (View -> Other Windows -> IntelliCode suggestions). By double clicking in the list you can navigate to the suggestion.

  • Avatar
    Chiramisu

    HUGE fan of the IntelliCode. I only wish it was a little more intelligent with the suggestions. For example, sometimes it suggests changes I’ve been making, but at the same time suggests changing them back. It also would be nice if the suggestions could be applied across the entire solution rather than just the current file as well. Currently I have to make the same changes for each file before it will recommend making the changes for the rest of that file. It’s also a pain having to apply each change manually rather than applying it to the everything at once as a set.

    • Mark Wilson-Thomas
      Mark Wilson-ThomasMicrosoft logo

      Thanks for the shout out Chiramisu, and for raising the issue. Much appreciated.

      In order of your comment:
      1. We’d love to hear more about the bad case of suggestions suggesting reversal of it’s own actions – if you can reproduce that, could you raise an issue via Visual Studio report-a-problem and drop me a line at mwthomas at microsoft dot com to let me know you’ve done it? It will be good to gather more data from you and a report-a-problem ticket provides the right venue for that. We will likely need to see your suggestions logs (see Peter Groenewegen’s response higher up, for details of this) and some information about what you saw (a quick screenshot or two) to make some progress on addressing this.

      2. Applying in bulk: we are actively working on features to let you “apply all” for a file for future releases, and also on ways to apply fixes across multiple files. Watch this space. It sounds like both scenarios (file level apply and applying across many files) are equally important to you – is that correct?

      Thanks a ton for trying IntelliCode suggestions and for taking the time to provide feedback – we are always keen to hear about good and bad behavior as you make use of the capabilities.

      Regards
      Mark

  • Avatar
    Wil Wilder Apaza Bustamante

    I found this enabled in a recent VS update. And I noticed the dotted underlines here and there. After a short while I got a basic feeling for how they work. But all in all, it wasn’t a useful experience. The suggested edits were inappropriate most of the time, for example trying to duplicate typed code at any opening brace in the most impossible places. And even when I found a suggestion useful, it took longer to actually apply it than when I just made the edit myself. So to avoid unnecessary distraction by the underlines, I had to disable that feature.

    Macro recording and playback (only available as a third party add-on, what a shame) is a lot more useful in well-organised code. Together with search&replace, I rarely find myself wishing for smarter edits that are still impossible today (change several groups of places in a specific coordinated way, not just applying the same little edit in multiple places).

    • Mark Wilson-Thomas
      Mark Wilson-ThomasMicrosoft logo

      Hi @Marcos

      Thanks for trying IntelliCode Suggestions.

      I’d love to gather more data on the cases where we suggested poor suggestions so we can improve. If you have time could you turn on the feature again and reproduce the bad cases then raise a Report-a-problem bug in Visual Studio? We’ll then help you to attach your suggestions logs so we can debug.

      On the question of a record-and-playback feature, we are considering the possibility of a manual recording feature that uses the same pattern recognition technology behind this capability, but invoked via a keystroke – so you could record what you did on a couple of changes and have the feature extract a generalized rule “macro” based on the underlying pattern and run it anywhere on demand. It sounds like this would be useful to you. If you’d like to chat more with me about it drop me a line on mwthomas at microsoft dot com and share your feedback.

      Thanks again,

      Mark

  • Avatar
    H H

    Except repeat edited one-line-code, project template, add class or menber et.al,
    Suggesting your team can develop tools to one-click-add base-code-frame( like Code snippets ?) using for target-function like Thread, Print, user-message handle, localization, XML-paser, internet-comm….. though some canbe find in project examples.
    you knoe, construct relations between classes is the most inportant and difficult work.

    Please give some relation information if these tool had been supplied , like Code snippets ?

    • Mark Wilson-Thomas
      Mark Wilson-ThomasMicrosoft logo

      Hi HH

      If I am understanding your suggestion, you’d like us to build a feature that provides intelligent code snippets for performing particular tasks in your code/project context.

      I’d love to understand what you’re looking for in more detail, so please drop me a line at mwthomas at microsoft dot com so we can discuss further?

      Thanks
      mark

  • Avatar
    Sala, Bojan

    I’m here because this rascal started showing up some really silly suggestions, didn’t really know what it was supposed to do until I read your post, so it makes sense now. It sounds like a pretty cool idea actually and would love to see where it goes. Luckily it’s not really intrusive and I haven’t noticed any performance loss either.

    • Mark Wilson-Thomas
      Mark Wilson-ThomasMicrosoft logo

      Hi Bojan! Thanks for your comment and for trying this feature out. Sorry about the silly suggestions; I’m glad they have not been intrusive or performance-impacting. We are aware of some cases where we make suggestions that do not compile, and we’re working on improving our filtering logic for an upcoming update to catch those cases better. Can you tell me, in the silly suggestions cases you have seen, would the “after suggestion” cases have compiler errors? If so, you should see some relief in that upcoming update. I’d love to hear more about those cases, so feel free to either raise them as issues over at Visual Studio’s report a problem or drop me a line at mwthomas at microsoft dot com. I’d also love to hear of any cases where the suggestions have helped you out!.

      Thanks again!
      Mark Wilson-Thomas
      Program Manager, Visual Studio IntelliCode.