{"id":237366,"date":"2022-05-11T09:00:46","date_gmt":"2022-05-11T16:00:46","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=237366"},"modified":"2022-05-09T15:53:11","modified_gmt":"2022-05-09T22:53:11","slug":"just-in-time-refactoring-intellicode-suggestions","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/just-in-time-refactoring-intellicode-suggestions\/","title":{"rendered":"Just-in-time refactoring made even easier with IntelliCode auto suggested code for C#"},"content":{"rendered":"<p>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.\u201d<\/p>\n<p><span class=\"TextRun Highlight SCXW65281388 BCX9\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW65281388 BCX9\">Since the release of Visual Studio 2022,<\/span><span class=\"NormalTextRun SCXW65281388 BCX9\"> IntelliCode <\/span><\/span><a class=\"Hyperlink SCXW65281388 BCX9\" href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/discover-quick-action-intellicode\/\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"FieldRange SCXW65281388 BCX9\"><span class=\"TextRun Highlight Underlined SCXW65281388 BCX9\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun CommentStart CommentHighlightPipeClicked CommentHighlightClicked SCXW65281388 BCX9\" data-ccp-charstyle=\"Hyperlink\">has code <\/span><span class=\"NormalTextRun CommentHighlightClicked SCXW65281388 BCX9\" data-ccp-charstyle=\"Hyperlink\">actions and refactorings <\/span><span class=\"NormalTextRun CommentHighlightClicked SCXW65281388 BCX9\" data-ccp-charstyle=\"Hyperlink\">for common tasks <\/span><span class=\"NormalTextRun CommentHighlightClicked SCXW65281388 BCX9\" data-ccp-charstyle=\"Hyperlink\">in the <\/span><span class=\"NormalTextRun CommentHighlightClicked SCXW65281388 BCX9\" data-ccp-charstyle=\"Hyperlink\">IntelliSense list<\/span><span class=\"NormalTextRun CommentHighlightClicked SCXW65281388 BCX9\" data-ccp-charstyle=\"Hyperlink\">.<\/span><\/span><\/span><\/a><span class=\"EOP CommentHighlightPipeClicked SCXW65281388 BCX9\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\"> <span class=\"TextRun Highlight SCXW165706080 BCX9\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW165706080 BCX9\">In Visual Studio 17.3, <\/span><span class=\"NormalTextRun SCXW165706080 BCX9\">these <\/span><span class=\"NormalTextRun SCXW165706080 BCX9\">code actions and refactorings<\/span><span class=\"NormalTextRun SCXW165706080 BCX9\">\u00a0are now offered <\/span><span class=\"NormalTextRun SCXW165706080 BCX9\">as <\/span><span class=\"NormalTextRun CommentStart CommentHighlightPipeRest CommentHighlightRest SCXW165706080 BCX9\">auto suggestion code<\/span> <span class=\"NormalTextRun SCXW165706080 BCX9\">upon typing<\/span><span class=\"NormalTextRun SCXW165706080 BCX9\">. You can accept a<\/span><span class=\"NormalTextRun CommentStart CommentHighlightPipeRest CommentHighlightRest SCXW165706080 BCX9\">uto suggested code by <\/span><span class=\"NormalTextRun CommentHighlightPipeRest SCXW165706080 BCX9\">pressing <\/span><span class=\"NormalTextRun SCXW165706080 BCX9\">[Tab]<\/span><span class=\"NormalTextRun CommentHighlightPipeRest SCXW165706080 BCX9\">.<\/span><\/span><\/span><\/p>\n<p><div style=\"width: 640px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-237366-1\" width=\"640\" height=\"360\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/04\/intellicode_intents.mp4?_=1\" \/><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/04\/intellicode_intents.mp4\">https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/04\/intellicode_intents.mp4<\/a><\/video><\/div><\/p>\n<h2>How it works<\/h2>\n<p><span class=\"TextRun SCXW161856333 BCX9\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW161856333 BCX9\">In the video, you\u2019ll see <\/span><span class=\"NormalTextRun SCXW161856333 BCX9\">how<\/span> <span class=\"NormalTextRun SpellingErrorV2Themed SCXW161856333 BCX9\">IntelliCode<\/span><span class=\"NormalTextRun SCXW161856333 BCX9\"> detects<\/span><\/span><span data-contrast=\"none\"> three common patterns:<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:789,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><span data-contrast=\"none\">Creating a constructor<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:789,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><span data-contrast=\"none\">Adding parameters to that constructor<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:789,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"3\" data-aria-level=\"1\"><span data-contrast=\"none\">Repetitive code changes that only involve adding new code<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span class=\"TextRun Highlight SCXW218083878 BCX9\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun CommentStart CommentHighlightPipeRest CommentHighlightRest SCXW218083878 BCX9\">IntelliCode suggests the code change as an auto suggested code insertion<\/span><span class=\"NormalTextRun CommentHighlightRest SCXW218083878 BCX9\">.<\/span><span class=\"NormalTextRun CommentHighlightPipeRest SCXW218083878 BCX9\"> If the suggestion is correct, you can use <\/span><span class=\"NormalTextRun CommentStart CommentHighlightPipeRest CommentHighlightRest SCXW218083878 BCX9\">[TAB] to <\/span><span class=\"NormalTextRun CommentHighlightPipeRest SCXW218083878 BCX9\">insert the code change. if the suggestion <\/span><span class=\"NormalTextRun CommentStart CommentHighlightPipeRest CommentHighlightRest SCXW218083878 BCX9\">is not the code you intended to write<\/span><span class=\"NormalTextRun CommentHighlightPipeRest SCXW218083878 BCX9\">, you can either continue typing, or press [ESC].<\/span><\/span><span class=\"EOP SCXW218083878 BCX9\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\"> <span class=\"TextRun Highlight SCXW202114151 BCX9\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW202114151 BCX9\">Under the hood,<\/span><span class=\"NormalTextRun SCXW202114151 BCX9\"> intent detection is made possible by the <a href=\"https:\/\/www.microsoft.com\/en-us\/research\/group\/prose\/\" target=\"_blank\" rel=\"noopener\">PROSE engine<\/a><\/span><span class=\"NormalTextRun SCXW202114151 BCX9\">. The <\/span><span class=\"NormalTextRun CommentStart CommentHighlightPipeRest CommentHighlightRest SCXW202114151 BCX9\">code suggestion <\/span><span class=\"NormalTextRun CommentHighlightPipeRest SCXW202114151 BCX9\">offered is generated either by PROSE, or by the .NET compiler platform (\u201cRoslyn\u201d).<\/span><span class=\"NormalTextRun SCXW202114151 BCX9\">\u00a0<\/span><\/span><span class=\"EOP SCXW202114151 BCX9\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/span><\/p>\n<h2>Try it now<\/h2>\n<p><span class=\"TextRun SCXW162292295 BCX9\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW162292295 BCX9\">These new IntelliCode suggestions <\/span><span class=\"NormalTextRun CommentHighlightPipeRest SCXW162292295 BCX9\">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!<\/span><\/span><span class=\"EOP SCXW162292295 BCX9\" data-ccp-props=\"{&quot;134233118&quot;:true,&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:240}\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":11554,"featured_media":237681,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[155],"tags":[5,467,6782,1054,526],"class_list":["post-237366","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-studio","tag-csharp","tag-intellicode","tag-intellicode-suggestions","tag-ml","tag-productivity"],"acf":[],"blog_post_summary":"<p>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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/237366","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\/11554"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=237366"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/237366\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/237681"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=237366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=237366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=237366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}