{"id":226303,"date":"2019-09-05T10:00:53","date_gmt":"2019-09-05T17:00:53","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=226303"},"modified":"2019-09-05T10:39:22","modified_gmt":"2019-09-05T17:39:22","slug":"refactoring-made-easy-with-intellicode","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/refactoring-made-easy-with-intellicode\/","title":{"rendered":"Refactoring made easy with IntelliCode!"},"content":{"rendered":"<p>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.<\/p>\n<p>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 <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">Visual Studio 2019 version 16.3 Preview 3<\/a> 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:<\/p>\n<p><div style=\"width: 2744px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-226303-1\" width=\"2744\" height=\"1780\" poster=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2018\/08\/vsfeaturemed.png\" autoplay preload=\"auto\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/09\/intellicode-refactorings.mp4?_=1\" \/><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/09\/intellicode-refactorings.mp4\">https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/09\/intellicode-refactorings.mp4<\/a><\/video><\/div><\/p>\n<h3><\/h3>\n<p>&nbsp;<\/p>\n<h3>Try it now<\/h3>\n<p>Refactoring is a preview feature of IntelliCode, so when you get <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">Visual Studio 2019 version 16.3 Preview 3<\/a> \u00a0it will be off by default. Visit the Tools-Options page, IntelliCode General tab, Preview features area, and switch C# refactorings to \u201cEnabled\u201d to turn it on.<\/p>\n<p>Once you change this setting, close any files you may have open, then restart Visual Studio:<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-226306 size-large\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/09\/refactorings-toolsoptions-1024x660.png\" alt=\"How to turn on the refactorings feature in tools-options\" width=\"640\" height=\"413\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/09\/refactorings-toolsoptions-1024x660.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/09\/refactorings-toolsoptions-300x193.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/09\/refactorings-toolsoptions-768x495.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/09\/refactorings-toolsoptions.png 1262w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<h3><\/h3>\n<h3 style=\"text-align: left;\">How it works<\/h3>\n<p>Under the hood, IntelliCode looks at each of your edits as you type. It uses <a href=\"https:\/\/nam06.safelinks.protection.outlook.com\/?url=https%3A%2F%2Fmicrosoft.github.io%2Fprose%2F&amp;data=02%7C01%7CMark.Wilson-Thomas%40microsoft.com%7Ccdb56ee2af63435d211b08d728b7d38b%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637022642299089700&amp;sdata=HlNZ43YNaRARxWWWg7JmKYoNxpzkTHct7Ainp%2FuMd5E%3D&amp;reserved=0\">PROSE<\/a> (PROgram Synthesis by Example) to synthesize generalized edit scripts that can take your code from the \u201cbefore editing\u201d state to the \u201cafter\u201d. 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 \u201csquiggles\u201d. The lightbulb offers actions to apply the refactorings for you. The underlying technology is similar to the <a href=\"https:\/\/nam06.safelinks.protection.outlook.com\/?url=https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fresearch%2Fblog%2Fflash-fill-gives-excel-smart-charge%2F&amp;data=02%7C01%7CMark.Wilson-Thomas%40microsoft.com%7Ccdb56ee2af63435d211b08d728b7d38b%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637022642299089700&amp;sdata=4Fe6vtMKRjyQuFdR7KYz4pPPHE7T1yK8YqM1lPwpKYk%3D&amp;reserved=0\">Excel\u2019s Flash Fill feature<\/a> and is described in <a href=\"http:\/\/aka.ms\/repetitive-edits\">this research paper<\/a>. More details will be presented at the upcoming <a href=\"https:\/\/2019.splashcon.org\/details\/splash-2019-oopsla\/27\/On-the-Fly-Synthesis-of-Edit-Suggestions\">OOPSLA 2019 conference<\/a>.<\/p>\n<p>This isn\u2019t just tracking text changes \u2013 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:<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-226305 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/09\/refactorings-illustrated.png\" alt=\"Illustration showing how IntelliCode can detect patterns syntactically and offer suggestions\" width=\"1023\" height=\"312\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/09\/refactorings-illustrated.png 1023w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/09\/refactorings-illustrated-300x91.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/09\/refactorings-illustrated-768x234.png 768w\" sizes=\"(max-width: 1023px) 100vw, 1023px\" \/><\/p>\n<p>If you don\u2019t like a suggested change you can select the ignore option on the lightbulb, and we won\u2019t bother you about that detected pattern again unless you recreate it.<\/p>\n<h3>Let us know what you think!<\/h3>\n<p>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 <a href=\"https:\/\/docs.microsoft.com\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio?view=vs-2019\">Visual Studio \u201creport a problem\u201d<\/a> . \u00a0We\u2019re 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\u2019ll follow up.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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<\/p>\n","protected":false},"author":587,"featured_media":226305,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[155],"tags":[1055,467,1664],"class_list":["post-226303","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-studio","tag-ai","tag-intellicode","tag-refactoring"],"acf":[],"blog_post_summary":"<p>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<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/226303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/587"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=226303"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/226303\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/226305"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=226303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=226303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=226303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}