{"id":246625,"date":"2024-01-24T09:00:27","date_gmt":"2024-01-24T17:00:27","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=246625"},"modified":"2024-02-16T09:02:49","modified_gmt":"2024-02-16T17:02:49","slug":"copilot-chat-slash-commands-and-context-variables","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/copilot-chat-slash-commands-and-context-variables\/","title":{"rendered":"Code Faster and Better with GitHub Copilot&#8217;s New Features: Slash Commands and Context Variables"},"content":{"rendered":"<p>Have you ever wished you had an AI assistant that could help you write code faster and better? That\u2019s what <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=VisualStudioExptTeam.VSGitHubCopilot\" target=\"_blank\" rel=\"noopener\">Visual Studio Copilot Chat<\/a> offers you: an AI-powered pair programmer that can answer your questions, suggest code snippets, explain code logic, and chat with you about your project. You can use Copilot to code faster and better, as it helps you avoid errors and learn new skills.<\/p>\n<p>We have added two new features to the latest Visual Studio Copilot Chat extension: slash commands <strong>(\/)<\/strong> that allow you to direct Copilot to perform specific tasks, and context Variables <strong>(#)<\/strong> that allow you to specify a file for Copilot to focus its answer on. We also have several preview features you can get a sneak peek on.<\/p>\n<p><div class=\"alert alert-success\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Lightbulb\"><\/i><strong>Download or update Visual Studio Copilot Chat extension to get the latest features<\/strong><\/p>The ultimate conversational AI assistant for your coding tasks, <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=VisualStudioExptTeam.VSGitHubCopilot\" target=\"_blank\" rel=\"noopener\">download the Visual Studio extension<\/a>.<\/p>\n<p>Compatible with <a href=\"https:\/\/visualstudio.microsoft.com\/downloads\/\" target=\"_blank\" rel=\"noopener\">Visual Studio 2022 version 17.8 and higher<\/a>.<\/p>\n<p>GitHub Copilot is free for verified students and for maintainers of popular open source projects on GitHub. If you are not a student or maintainer of a popular open source project, you can\u00a0<a href=\"https:\/\/github.com\/settings\/copilot\" target=\"_blank\" rel=\"noopener\" data-linktype=\"external\">try GitHub Copilot for free with a one-time 30-day trial<\/a>. After the free trial, you will need a\u00a0<a href=\"https:\/\/docs.github.com\/en\/billing\/managing-billing-for-github-copilot\/about-billing-for-github-copilot\" target=\"_blank\" rel=\"noopener\" data-linktype=\"external\">paid subscription<\/a>\u00a0for continued use.<\/div><\/p>\n<h2>Slash commands<\/h2>\n<p>Slash commands are special commands that you can use in chat to perform specific actions on your code. For example, you can use:<\/p>\n<ul>\n<li><em>\/doc<\/em> to add a documentation comment<\/li>\n<li><em>\/explain<\/em> to explain the code<\/li>\n<li><em>\/fix<\/em> to propose a fix for the problems in the selected code<\/li>\n<li><em>\/generate<\/em> to generate code to answer your question<\/li>\n<li><em>\/help<\/em> to get help on Copilot Chat<\/li>\n<li><em>\/optimize<\/em> to analyze and improve running time of the selected code<\/li>\n<li><em>\/tests<\/em> to create unit tests for the selected code<\/li>\n<\/ul>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/slash-commands-1.jpg\"><img decoding=\"async\" class=\"wp-image-246638 size-large aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/slash-commands-1-1024x459.jpg\" alt=\"Image slash commands 1\" width=\"640\" height=\"287\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/slash-commands-1-1024x459.jpg 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/slash-commands-1-300x135.jpg 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/slash-commands-1-768x345.jpg 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/slash-commands-1-1536x689.jpg 1536w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/slash-commands-1.jpg 1986w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<h2>Context variables<\/h2>\n<p>The context variables feature lets you easily add files from your solution to your questions by using the # symbol. When you reference a file, Copilot can access the file content and answer more specific questions about it. For example, you can ask \u201c<em>How does the <strong>#file:Main.cs<\/strong> file work?<\/em>\u201d or \u201c<em>What is the purpose of the <strong>#file:Calculator.cs<\/strong> file?<\/em>\u201d and get relevant answers from Copilot Chat. You can add multiple files to one question. This feature saves you time and effort by allowing you to include content from your project without copying and pasting.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/references.jpg\"><img decoding=\"async\" class=\"wp-image-246636 size-large aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/references-934x1024.jpg\" alt=\"Image references\" width=\"640\" height=\"702\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/references-934x1024.jpg 934w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/references-274x300.jpg 274w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/references-768x842.jpg 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/references-1401x1536.jpg 1401w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/references.jpg 1434w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>You can see the referenced files in the chat under the answers. Just look for the link to the references to see what was added to your question. If you click on the links, it will take you to the included content.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/references-used.jpg\"><img decoding=\"async\" class=\"wp-image-246643 size-large aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/references-used-1024x524.jpg\" alt=\"Image references used\" width=\"640\" height=\"328\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/references-used-1024x524.jpg 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/references-used-300x154.jpg 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/references-used-768x393.jpg 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/references-used.jpg 1282w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p><div class=\"alert alert-success\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Lightbulb\"><\/i><strong>Tips &amp; Tricks for GitHub Copilot Chat in Visual Studio:<\/strong><\/p><a href=\"https:\/\/learn.microsoft.com\/en-us\/visualstudio\/ide\/copilot-chat-context?view=vs-2022\" target=\"_blank\" rel=\"noopener\">Get better answers by setting the context for GitHub Copilot in Visual Studio.<\/a><\/div><\/p>\n<h2>Preview features<\/h2>\n<p>In addition to the main released feature of Visual Studio Copilot Chat, we also have some exciting preview features that you can try out and give us your feedback. These preview features are experimental and may not work as expected, but they can enhance your development experience with Visual Studio Copilot Chat. Here are some of the preview features and their brief descriptions:<\/p>\n<ul>\n<li><strong>Exception Assistant in debugger<\/strong>: Copilot helps you diagnose and fix exceptions in your code. Copilot will provide you with relevant information about the exception, such as the cause, the location, the stack trace, and possible solutions.\n<a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/exception-copilot.jpg\"><img decoding=\"async\" class=\"size-full wp-image-246719 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/exception-copilot.jpg\" alt=\"Ask copilot we an exception happens.\" width=\"560\" height=\"267\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/exception-copilot.jpg 560w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/exception-copilot-300x143.jpg 300w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><\/a><\/li>\n<li><strong>Suggestions for breakpoint expressions<\/strong>: Copilot helps you set conditional breakpoints in your code. Copilot will suggest expressions that evaluate to true or false based on the current context of your code.<\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/write-your-git-commits-with-github-copilot\/\"><strong>Commit message suggestions<\/strong><\/a>: Copilot helps you describe your set of changes by generating a Git commit message. You can then refine the message with \u201cwhy\u201d the change was made and commit.\n<a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/11\/Generated-Commit-Message.png\"><img decoding=\"async\" class=\"size-large wp-image-246147 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/11\/Generated-Commit-Message-1024x457.png\" alt=\"Generated Commit Message\" width=\"640\" height=\"286\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/11\/Generated-Commit-Message-1024x457.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/11\/Generated-Commit-Message-300x134.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/11\/Generated-Commit-Message-768x343.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2023\/11\/Generated-Commit-Message.png 1317w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/li>\n<li><strong>Solution reference<\/strong>: Copilot helps you find and navigate to the references of your code elements in your solution. By using #solution you are letting Copilot know to search your solution for relevant code to the question. These will than automatically added to the context of your question so copilot can use those for answering your question.<\/li>\n<li><strong>Suggestions in the Performance Profiler<\/strong>: Copilot helps you optimize the performance of your code. Copilot will analyze the performance data collected by the Visual Studio Performance Profiler and suggest ways to improve the speed, memory usage, and responsiveness of your code.<\/li>\n<li><strong>Test failure Analysis<\/strong>: Copilot helps you debug and fix the failures of your unit tests. Copilot will provide you with useful information about the test failure, such as the assertion message, the expected and actual values, the source code, and possible solutions.\n<a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/tests-copilot.jpg\"><img decoding=\"async\" class=\"aligncenter wp-image-246718 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/tests-copilot.jpg\" alt=\"Ask copilot for test failure analysis.\" width=\"792\" height=\"433\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/tests-copilot.jpg 792w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/tests-copilot-300x164.jpg 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2024\/01\/tests-copilot-768x420.jpg 768w\" sizes=\"(max-width: 792px) 100vw, 792px\" \/><\/a><\/li>\n<\/ul>\n<p><div class=\"alert alert-success\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Lightbulb\"><\/i><strong>Enable the Preview features<\/strong><\/p>To enable these preview features, you need to go to<strong> Options -&gt; GitHub -&gt; Copilot Chat -&gt; Preview features<\/strong> and check the boxes for the features you want to try and let us know how you experience is.<\/div><\/p>\n<h3><strong>We want to hear from you!<\/strong><button class=\"linkicon\" title=\"\" aria-label=\"Copy Post URL\" data-id-href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/simplified-code-refinement-and-debugging-with-github-copilot-chat\/#we-want-to-hear-from-you\" data-toggle=\"tooltip\" data-placement=\"right\" data-original-title=\"Copy Post URL\"><i class=\"fabric-icon fabric-icon--Link\"><\/i><\/button><\/h3>\n<p>We appreciate all the feedback you\u2019ve provided so far as we\u2019ve been creating Copilot, and are excited to see where this next wave of AI-assisted productivity takes you as you create great software. Please try the new features and share your feedback \u2013 just use Visual Studio <a href=\"https:\/\/learn.microsoft.com\/en-us\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio?view=vs-2022\" target=\"_blank\" rel=\"noopener\">Visual Studio \u201cSend feedback\u201d<\/a> to send us your suggestions, feedback and issues for GitHub Copilot in Visual Studio.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever wished you had an AI assistant that could help you write code faster and better? That\u2019s what Visual Studio Copilot Chat offers you: an AI-powered pair programmer that can answer your questions, suggest code snippets, explain code logic, and chat with you about your project. You can use Copilot to code faster [&hellip;]<\/p>\n","protected":false},"author":11554,"featured_media":246650,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[6887,6888,155],"tags":[1055,6883],"class_list":["post-246625","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-artificial-intelligence","category-copilot","category-visual-studio","tag-ai","tag-copilot"],"acf":[],"blog_post_summary":"<p>Have you ever wished you had an AI assistant that could help you write code faster and better? That\u2019s what Visual Studio Copilot Chat offers you: an AI-powered pair programmer that can answer your questions, suggest code snippets, explain code logic, and chat with you about your project. You can use Copilot to code faster [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/246625","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=246625"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/246625\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/246650"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=246625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=246625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=246625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}