{"id":34429,"date":"2024-07-22T14:43:56","date_gmt":"2024-07-22T14:43:56","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=34429"},"modified":"2024-07-22T14:43:56","modified_gmt":"2024-07-22T14:43:56","slug":"improving-github-copilot-completions-in-vs-code-for-c-developers","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/improving-github-copilot-completions-in-vs-code-for-c-developers\/","title":{"rendered":"Improving GitHub Copilot Completions in VS Code for C++ Developers"},"content":{"rendered":"<p>GitHub Copilot code completions are autocomplete-stye suggestions that appear inline as you code. Until today, they have used context from your <a href=\"https:\/\/code.visualstudio.com\/docs\/copilot\/ai-powered-suggestions#_context\">active file and other tabs open in the editor<\/a> to inform the suggestion that is returned. However, we know that more contextually relevant input leads to better suggestions. Our team has made changes to the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-vscode.cpptools-extension-pack\">C\/C++ extension<\/a> and the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=GitHub.copilot\">GitHub Copilot extension<\/a> in VS Code to ensure that other relevant C++ context \u2014 like available types and methods \u2014 are also provided to Copilot completions.<\/p>\n<p>When you use the latest version of the C\/C++ extension and the GitHub Copilot extension together in VS Code, directly-referenced header files will be automatically considered when gathering additional context for Copilot completions, even if they\u2019re not open in the editor. This helps to reduce hallucinations and provide more relevant suggestions. Let\u2019s look at an example.<\/p>\n<h5>Before: Directly-referenced header files are not considered as context for GitHub Copilot code completions<\/h5>\n<p>In this example, I want to create a new function in the OSS <a href=\"https:\/\/github.com\/dolphin-emu\/dolphin\/tree\/321c4649a5c9d185ea163707d0ee9f296df1ecd6\">Dolphin codebase<\/a> to find text files. When directly-referenced header files are not considered as context, GitHub Copilot hallucinates a <a href=\"https:\/\/github.com\/search?q=repo%3Adolphin-emu%2Fdolphin%20FindFiles&amp;type=code\">non-existent FindFiles() function<\/a>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/07\/headers-context-off-blog.gif\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-34432\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/07\/headers-context-off-blog.gif\" alt=\"A snippet of C++ code in VS Code. A user types a function name (FindAllTextFiles), and Copilot hallucinates a non-existent function (FindFiles()) in the function body.\" width=\"1440\" height=\"379\" \/><\/a><\/p>\n<h5>After: Directly-referenced header files are considered as context for Github Copilot code completions<\/h5>\n<p>Now, when directly-referenced header files are considered as context, Copilot correctly suggests an <a href=\"https:\/\/github.com\/dolphin-emu\/dolphin\/blob\/321c4649a5c9d185ea163707d0ee9f296df1ecd6\/Source\/Core\/Common\/FileSearch.h#L13-L15\">existing DoFileSearch()<\/a> utility function declared in FileSearch.h.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/07\/headers-context-on-blog.gif\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-34433\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2024\/07\/headers-context-on-blog.gif\" alt=\"A snippet of C++ code in VS Code. A user types a function name (FindAllTextFiles), and Copilot suggests an existing utility function (DoFileSearch) in the function body.\" width=\"1440\" height=\"379\" \/><\/a><\/p>\n<p>To get started, make sure you\u2019re using the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=GitHub.copilot\">GitHub Copilot extension<\/a> version 1.205 or later and have an active <a href=\"https:\/\/github.com\/features\/copilot?utm_source=vscom&amp;utm_medium=hero&amp;utm_campaign=cta-get#pricing\">GitHub Copilot subscription<\/a>. You\u2019ll also need the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-vscode.cpptools-extension-pack\">C\/C++ extension<\/a> version 1.21 or later with <a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/configure-intellisense\">IntelliSense configured correctly<\/a>. Version 1.21 of the C\/C++ extension is currently in pre-release. Our team is committed to C++ Copilot support in both Visual Studio and VS Code, and similar support is coming to Visual Studio in Visual Studio 2022 version 17.12.<\/p>\n<h3>Contacts Us<\/h3>\n<p>Your feedback helps inform our work to improve the Copilot experience for C++ developers in Visual Studio and VS Code. You can provide feedback on GitHub Copilot by opening a <a href=\"https:\/\/github.com\/orgs\/community\/discussions\/categories\/copilot\">GitHub discussion<\/a>. You can also reach our team via email (<a href=\"mailto:visualcpp@microsoft.com\">visualcpp@microsoft.com<\/a>), X (<a href=\"https:\/\/x.com\/visualc\">@VisualC<\/a>), or through the comments below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GitHub Copilot code completions are autocomplete-stye suggestions that appear inline as you code. Until today, they have used context from your active file and other tabs open in the editor to inform the suggestion that is returned. However, we know that more contextually relevant input leads to better suggestions. Our team has made changes to [&hellip;]<\/p>\n","protected":false},"author":2953,"featured_media":34436,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[270,1,3940,275],"tags":[],"class_list":["post-34429","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcement","category-cplusplus","category-copilot","category-visual-studio-code"],"acf":[],"blog_post_summary":"<p>GitHub Copilot code completions are autocomplete-stye suggestions that appear inline as you code. Until today, they have used context from your active file and other tabs open in the editor to inform the suggestion that is returned. However, we know that more contextually relevant input leads to better suggestions. Our team has made changes to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/34429","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/2953"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=34429"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/34429\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/34436"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=34429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=34429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=34429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}