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 the C/C++ extension and the GitHub Copilot extension in VS Code to ensure that other relevant C++ context — like available types and methods — are also provided to Copilot completions.
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’re not open in the editor. This helps to reduce hallucinations and provide more relevant suggestions. Let’s look at an example.
Before: Directly-referenced header files are not considered as context for GitHub Copilot code completions
In this example, I want to create a new function in the OSS Dolphin codebase to find text files. When directly-referenced header files are not considered as context, GitHub Copilot hallucinates a non-existent FindFiles() function.
After: Directly-referenced header files are considered as context for Github Copilot code completions
Now, when directly-referenced header files are considered as context, Copilot correctly suggests an existing DoFileSearch() utility function declared in FileSearch.h.
To get started, make sure you’re using the GitHub Copilot extension version 1.205 or later and have an active GitHub Copilot subscription. You’ll also need the C/C++ extension version 1.21 or later with IntelliSense configured correctly. 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.
Contacts Us
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 GitHub discussion. You can also reach our team via email ([email protected]), X (@VisualC), or through the comments below.
I have been waiting for this capability for a while, nice to see this Erika. I hope the vscode’s builtin javascript language features are also getting a similar update with copilot integration.
——-
out of context question:
Is there a
‘s GUI version being planned for VS2022?
Nice to hear about this improvement for VS Code. When will Visual Studio get it?
Similar support is coming to Visual Studio in Visual Studio 2022 version 17.12.
not sure if this has been implemented:
if there is a compile_commands.json file for clangd, use this file as a context, to auto complete and auto include corresponding headers.