{"id":35053,"date":"2025-01-30T15:48:47","date_gmt":"2025-01-30T15:48:47","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=35053"},"modified":"2025-01-30T18:29:00","modified_gmt":"2025-01-30T18:29:00","slug":"document-build-instructions-and-more-with-enhanced-c-awareness-from-copilot-chat-in-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/document-build-instructions-and-more-with-enhanced-c-awareness-from-copilot-chat-in-visual-studio\/","title":{"rendered":"Document build instructions and more with enhanced C++ awareness from Copilot Chat in Visual Studio"},"content":{"rendered":"<p>C++ development often involves nuances beyond the file you\u2019re developing in. This can leave developers with many mental tabs open, balancing all the relevant context for their project to develop their C++ code properly.<\/p>\n<p>Copilot Chat in Visual Studio can already utilize context provided by <a href=\"https:\/\/learn.microsoft.com\/en-us\/visualstudio\/ide\/copilot-chat-context?view=vs-2022#reference\">specified files and invoked agents such as @workspace<\/a> to generate suggestions. However, to improve the relevance of Copilot suggestions, we must provide tailored context to Copilot with considerations specific to the C++ language for developers to achieve better results. That way, developers can focus less on providing all the information necessary for their questions and focus more on the task at hand.<\/p>\n<p>Visual Studio can now provide Copilot Chat with various levels of C++ project context. These updates are designed to help C++ developers incorporate more relevant suggestions into their code, faster than ever.<\/p>\n<p>To showcase Copilot\u2019s increased awareness of C++, we will walk through 3 sample C++ workflows where Chat can provide assistance:<\/p>\n<ol>\n<li>Improving documentation for build instructions<\/li>\n<li>Generating new tests<\/li>\n<li>Modernizing C++ code<\/li>\n<\/ol>\n<p>Upgrade to <a href=\"aka.ms\/vs\">the latest version of Visual Studio 2022<\/a> and try out <a href=\"https:\/\/github.com\/features\/copilot\">GitHub Copilot<\/a> (<a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/github-copilot-free-is-here-in-visual-studio\/\">now with plans available for free<\/a>) to access these updates for C++.<\/p>\n<h4>Documenting Build Instructions<\/h4>\n<p>C++ projects can sometimes require developers to undergo several steps to be able to configure a project for development before they are even able to begin coding. Due to these requirements, it is important to document relevant instructions for onboarding developers thoroughly.<\/p>\n<p>We asked Copilot Chat to improve documentation in the <a href=\"https:\/\/github.com\/endless-sky\/endless-sky\">open-source project Endless Sk<\/a>y&#8217;s README. Copilot was able to include relevant context, such as dependencies like Ninja, to enhance Chat suggestions for improving documentation specific to this project\u2019s needs, minimizing manual toil to onboard developers onto a project.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-readme2.png\"><img decoding=\"async\" class=\"alignnone wp-image-35055\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-readme2.png\" alt=\"Copilot providing suggestions to add relevant configuration instructions to endless sky's readme file\" width=\"1935\" height=\"969\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-readme2.png 2166w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-readme2-300x150.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-readme2-1024x513.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-readme2-768x385.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-readme2-1536x769.png 1536w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-readme2-2048x1026.png 2048w\" sizes=\"(max-width: 1935px) 100vw, 1935px\" \/><\/a><\/p>\n<h4>Generating Additional Tests<\/h4>\n<p>Writing unit tests for C++ can be cumbersome and painstaking. With the <strong>\/tests<\/strong> command, Copilot can assist with generating unit tests for the selected code. Copilot now has awareness of the available testing structure found in your project, so that when you invoke <strong>\/tests<\/strong> to generate tests in your projects, friction is minimal for integrating the generated tests that fit in with your existing ones.<\/p>\n<p>For example, when we prompted to generate new unit tests for the <code>Step<\/code> method in the <code>Weather.cpp<\/code> file in <a href=\"https:\/\/github.com\/endless-sky\/endless-sky\">endless-sky<\/a> using the<strong> \/tests <\/strong>command, Copilot generated new tests that resemble the existing tests in the project:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-tests.png\"><img decoding=\"async\" class=\"alignnone wp-image-35056\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-tests.png\" alt=\"Generating Unit Tests for the Weather.cpp file using Copilto provides Catch2 framework\" width=\"1538\" height=\"842\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-tests.png 2139w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-tests-300x164.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-tests-1024x561.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-tests-768x420.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-tests-1536x841.png 1536w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-tests-2048x1121.png 2048w\" sizes=\"(max-width: 1538px) 100vw, 1538px\" \/><\/a><\/p>\n<p>When compared to existing test code, like <code>test_ship.cpp<\/code>, the Chat response includes the same relevant header files and test case structure like using <code>SCENARIO<\/code> and <code>GIVEN<\/code> for test cases.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-tests-2.png\"><img decoding=\"async\" class=\"alignnone wp-image-35058\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-tests-2.png\" alt=\"Existing tests for test_ship.cpp with SCENARIO and GIVEN cases\" width=\"1176\" height=\"703\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-tests-2.png 1506w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-tests-2-300x179.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-tests-2-1024x612.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/endless-sky-tests-2-768x459.png 768w\" sizes=\"(max-width: 1176px) 100vw, 1176px\" \/><\/a><\/p>\n<h4>Refactoring C++ code for modernization<\/h4>\n<p>Maintainability of C++ code can be difficult as C++ coding conventions evolve over the years. C++ developers often need to refactor legacy code to improve code clarity and maintainability over time.<\/p>\n<p>Now, when asking Copilot questions related to C++ development such as refactoring code, <strong>\u00a0<\/strong>Copilot has the awareness to not only provide suggestions that are relevant to your selected code, but also suggestions that are compliant with your project\u2019s configurations and standards.<\/p>\n<p>Let\u2019s take a look at an example, using some loop code that finds the greatest even element in a given container below. It can be useful to<a href=\"https:\/\/www.youtube.com\/watch?v=W2tWOdzgXHA\"> update C++ raw loop code<\/a> to utilize algorithms instead for a myriad of reasons, including improving code readability and minimizing errors<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/raw-loop.png\"><img decoding=\"async\" class=\"alignnone wp-image-35059\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/raw-loop.png\" alt=\"Raw loop code in C++\" width=\"1277\" height=\"526\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/raw-loop.png 1551w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/raw-loop-300x124.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/raw-loop-1024x422.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/raw-loop-768x316.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/raw-loop-1536x633.png 1536w\" sizes=\"(max-width: 1277px) 100vw, 1277px\" \/><\/a><\/p>\n<p>When initially asked to refactor the code to incorporate algorithms or ranges using older C++\/CMake versions, Copilot suggests using <code>std::max_element<\/code> to improve the code to be more concise instead of requiring a manual loop.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/refactor-raw-loop.png\"><img decoding=\"async\" class=\"alignnone wp-image-35060\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/refactor-raw-loop.png\" alt=\"Copilot is refactoring the raw loop code to use the algorithm header in the original implementation\" width=\"1412\" height=\"878\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/refactor-raw-loop.png 1993w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/refactor-raw-loop-300x187.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/refactor-raw-loop-1024x637.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/refactor-raw-loop-768x478.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/refactor-raw-loop-1536x956.png 1536w\" sizes=\"(max-width: 1412px) 100vw, 1412px\" \/><\/a><\/p>\n<p>After updating the standard of the project to the latest standard of C++23, Copilot responses now include newer C++ features that can be relevant to the question, such as <code>std::ranges<\/code>, to improve the code.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/refactor-raw-loop-2.png\"><img decoding=\"async\" class=\"alignnone wp-image-35061\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/refactor-raw-loop-2.png\" alt=\"Copilot refactoring the raw loop to use ranges with the latest C++ standard\" width=\"1578\" height=\"840\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/refactor-raw-loop-2.png 2188w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/refactor-raw-loop-2-300x160.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/refactor-raw-loop-2-1024x545.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/refactor-raw-loop-2-768x409.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/refactor-raw-loop-2-1536x818.png 1536w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2025\/01\/refactor-raw-loop-2-2048x1090.png 2048w\" sizes=\"(max-width: 1578px) 100vw, 1578px\" \/><\/a><\/p>\n<h4>What do you think?<\/h4>\n<p>Try out the latest Chat improvements for your C++ workflows today. To access these updates to Copilot, you\u2019ll need an\u00a0<a href=\"https:\/\/github.com\/features\/copilot?utm_source=vscom&amp;utm_medium=hero&amp;utm_campaign=cta-get#pricing\">active GitHub Copilot subscription<\/a>\u00a0and the\u00a0<a href=\"http:\/\/aka.ms\/vs\">latest version of Visual Studio<\/a>.<\/p>\n<p>In addition, our team is working hard on improving C++ integrations with Copilot, so please let us know any other enhancements you\u2019d like to see to your C++ workflows and content you\u2019d like to see. Comment below, or you can find us via email at\u00a0<a href=\"mailto:visualcpp@microsoft.com\">visualcpp@microsoft.com<\/a>\u00a0or via X at\u00a0<a href=\"https:\/\/x.com\/visualc\">@VisualC<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C++ development often involves nuances beyond the file you\u2019re developing in. This can leave developers with many mental tabs open, balancing all the relevant context for their project to develop their C++ code properly. Copilot Chat in Visual Studio can already utilize context provided by specified files and invoked agents such as @workspace to generate [&hellip;]<\/p>\n","protected":false},"author":85413,"featured_media":35055,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,266,3949],"tags":[],"class_list":["post-35053","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","category-cmake","category-copilot-2"],"acf":[],"blog_post_summary":"<p>C++ development often involves nuances beyond the file you\u2019re developing in. This can leave developers with many mental tabs open, balancing all the relevant context for their project to develop their C++ code properly. Copilot Chat in Visual Studio can already utilize context provided by specified files and invoked agents such as @workspace to generate [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/35053","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\/85413"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=35053"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/35053\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35055"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=35053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=35053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=35053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}