{"id":248553,"date":"2024-04-04T03:00:24","date_gmt":"2024-04-04T10:00:24","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=248553"},"modified":"2024-04-05T07:32:14","modified_gmt":"2024-04-05T14:32:14","slug":"how-to-use-comments-to-prompt-github-copilot-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/how-to-use-comments-to-prompt-github-copilot-visual-studio\/","title":{"rendered":"How to use Comments to Prompt GitHub Copilot for Visual Studio"},"content":{"rendered":"<h2><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/Comments-as-Prompts-in-GitHub-Copilot-for-Visual-Studio.png\"><img decoding=\"async\" class=\"alignnone wp-image-248564\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/Comments-as-Prompts-in-GitHub-Copilot-for-Visual-Studio-300x169.png\" alt=\"Image Comments as Prompts in GitHub Copilot for Visual Studio\" width=\"801\" height=\"451\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/Comments-as-Prompts-in-GitHub-Copilot-for-Visual-Studio-300x169.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/Comments-as-Prompts-in-GitHub-Copilot-for-Visual-Studio-1024x576.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/Comments-as-Prompts-in-GitHub-Copilot-for-Visual-Studio-768x432.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/Comments-as-Prompts-in-GitHub-Copilot-for-Visual-Studio.png 1280w\" sizes=\"(max-width: 801px) 100vw, 801px\" \/><\/a><\/h2>\n<p style=\"text-align: center;\">A step-by-step guide to use comments as prompts in GitHub Copilot for Visual Studio<\/p>\n<h2>Introduction to GitHub Copilot for Visual Studio<\/h2>\n<p>GitHub Copilot is a programming assistant that uses AI (Artificial Intelligence) to help you increase efficiency in your daily programming tasks. It is compatible with various IDEs (Integrated Development Environments), text editors, and more. In this series, we will focus on demonstrating how GitHub Copilot can help you become more productive in Visual Studio.<\/p>\n<p><span class=\"TextRun SCXW191908749 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW191908749 BCX8\">One way to get code suggestions from GitHub Copilot is by <\/span><span class=\"NormalTextRun SCXW191908749 BCX8\">leveraging<\/span><span class=\"NormalTextRun SCXW191908749 BCX8\"> code comments. <\/span><span class=\"NormalTextRun SCXW191908749 BCX8\">However,<\/span><span class=\"NormalTextRun SCXW191908749 BCX8\"> we know sometimes even <\/span><span class=\"NormalTextRun SCXW191908749 BCX8\">coming up with<\/span><span class=\"NormalTextRun SCXW191908749 BCX8\"> a comment can be a<\/span><span class=\"NormalTextRun SCXW191908749 BCX8\"> little cumbersome.<\/span><\/span><span class=\"EOP SCXW191908749 BCX8\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335557856&quot;:16777215,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/p>\n<p>What is great about GitHub Copilot for Visual Studio is that it is not only capable of suggesting code but can also provide completions for your comments.<\/p>\n<p><a href=\"https:\/\/youtube.com\/shorts\/9Vmdm6kroCs\">In the second short video in this series<\/a>, my colleague Bruno Capuano will highlight how to use comments to prompt GitHub Copilot to produce code directly within the current file.<\/p>\n<p><em>Make sure to have GitHub Copilot installed, refer to the documentation to learn <a href=\"https:\/\/learn.microsoft.com\/visualstudio\/ide\/visual-studio-github-copilot-chat?view=vs-2022#install-the-visual-studio-extension\/?WT.mc_id=academic-129246-lbugnion\">how to install GitHub Copilot for Visual Studio<\/a><\/em><\/p>\n<p style=\"text-align: center;\"><iframe src=\"\/\/www.youtube.com\/embed\/9Vmdm6kroCs?feature=oembed\" width=\"560\" height=\"314\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<h2>How to use a Comment to Prompt GitHub Copilot<\/h2>\n<p>Let us start by writing a comment. In the example, Bruno is typing a comment that looks like this:<\/p>\n<pre class=\"prettyprint language-cs language-csharp\"><code class=\"language-cs language-csharp\">\/\/ function to get the year of birth<\/code><\/pre>\n<p>As we can see in this example, GitHub Copilot quickly springs into action, proposing to complete the comment as follows:<\/p>\n<pre class=\"prettyprint language-cs language-csharp\"><code class=\"language-cs language-csharp\"> \/\/ function to get the year of birth *from the age*<\/code><\/pre>\n<p>This feature can be particularly useful, for example, when you are writing documentation.<\/p>\n<p>(<strong>Note:<\/strong>\u00a0in this example I added *stars* around the suggested code. In the Visual Studio IDE, the suggestion would appear greyed out).<\/p>\n<p>To accept the comment completion suggestion and incorporate it into your code, simply press the Tab key. Following that, pressing Enter prompts Copilot to offer a code suggestion based off the comment. The suggested code will appear inline and greyed out. You can also accept this suggestion by pressing the Tab key.<\/p>\n<p><em>Additional examples can be found here in <\/em><a href=\"https:\/\/learn.microsoft.com\/visualstudio\/ide\/visual-studio-github-copilot-extension?view=vs-2022#using-github-copilot-for-code-completions-and-suggestions\"><em>Using GitHub Copilot for code completions and suggestions<\/em><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>Validating the output of GitHub Copilot<\/h2>\n<p>The key principle to remember when working with AI assistants is that you should always verify the output. You have the chance to review the Copilot output either before accepting, when the code appears greyed out inline or after you have accepted the suggestion with the Tab key. I frequently accept the suggestion first and then revisit the generated code. If I need to make any changes, I will do so before moving on.<\/p>\n<p><em>GitHub Copilot is not a compiler!<\/em><\/p>\n<p>This means that the code produced by GitHub Copilot can indeed fail to compile and\/or be incorrect. It is your responsibility to review, resolve, and improve the suggested code, as necessary.<\/p>\n<h2>Disabling GitHub Copilot completions<\/h2>\n<p>You might not always want Copilot to suggest completions in your code files. Deactivating it is straightforward, whether for all code files, or even just for specific files such as markdown or C#. Simply click on the small Copilot icon on the Visual Studio taskbar and then select the appropriate option.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/Picture1.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-248555\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/Picture1.png\" alt=\"Image Picture1\" width=\"300\" height=\"139\" \/><\/a><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/Picture2.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-248556\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/04\/Picture2.png\" alt=\"Image Picture2\" width=\"299\" height=\"144\" \/><\/a><\/p>\n<h2>Conclusion<\/h2>\n<p>Now that you have successfully used a comment to GitHub Copilot in Visual Studio, you can continue to leverage this practice in all your projects. This is just one of the ways that GitHub Copilot can help you write code faster and be more productive. To learn more about GitHub Copilot and how to use it,\u00a0<a href=\"https:\/\/learn.microsoft.com\/collections\/ng58uwrk6g53ox?WT.mc_id=academic-129245-abartolo\">check our collection with resources here<\/a>\u00a0or via our\u00a0<a href=\"https:\/\/youtu.be\/z1ycDvspv8U\">full-length video<\/a>.<\/p>\n<h3>Additional Resources<\/h3>\n<ul>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/copilot-chat-slash-commands-and-context-variables\/\">Code Faster and Better with GitHub Copilot\u2019s New Features: Slash Commands and Context Variables<\/a><\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/announcing-the-github-extension-for-visual-studio\/\">Announcing the GitHub Extension for Visual Studio<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>A step-by-step guide to use comments as prompts in GitHub Copilot for Visual Studio. GitHub Copilot is a programming assistant that uses AI (Artificial Intelligence) to help you increase efficiency in your daily programming tasks. &#8230;<\/p>\n","protected":false},"author":154186,"featured_media":248562,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[6887,6888,6941,1388,6904,155],"tags":[1055,4381,6924,6945,6906,287,12],"class_list":["post-248553","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-artificial-intelligence","category-copilot","category-copilot-2024-series","category-extensibility","category-installation-and-updates","category-visual-studio","tag-ai","tag-github","tag-github-copilot","tag-gwyneth-pena-siguenza","tag-install","tag-tips-and-tricks","tag-visual-studio"],"acf":[],"blog_post_summary":"<p>A step-by-step guide to use comments as prompts in GitHub Copilot for Visual Studio. GitHub Copilot is a programming assistant that uses AI (Artificial Intelligence) to help you increase efficiency in your daily programming tasks. &#8230;<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/248553","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\/154186"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=248553"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/248553\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/248562"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=248553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=248553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=248553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}