September 11th, 2024

Fix C++ warnings and errors with Copilot: Introducing AI-Assisted Code Fixes in Visual Studio

Sinem Akinci
Product Manager II

Stuck on an unfamiliar build error? Want to resolve your code errors quickly? Copilot is now integrated into Visual Studio error workflows to assist you with understanding and resolving C++ errors and warnings.

To access this new feature, you will need an active Copilot subscription and the latest 17.11 GA version of Visual Studio.

How does it work?

There are two different entry points to accommodate where you are at in your error workflow:

  • The Quick Action lightbulb proposes a fix of a given error inline in your code window.
  • The Error List Integration invokes Copilot in the chat window to explain the error code and showcase a proposed fix.

Semantically relevant code snippets from your active file and related files are automatically included as context to increase the relevant of the proposed fix.

Fix with Copilot in the Quick Action Lightbulb

Copilot is integrated into the Quick Action lightbulb in your code editor, so that you can invoke Copilot and view proposed fixes inline with a few simple clicks. Just hover over the diagnostic squiggle or double-click on a diagnostic message in your Error List to access Fix with Copilot via Quick Action Lightbulb.

Option to fix with Copilot over an error in the light bulb.From here, Copilot will invoke the /fix command with semantically relevant C++ code snippets to propose a fix for your code.

VS diff viewer showing the implementation of a proposed fix.

You can edit the proposed code, accept any changes inline, or ask any follow-up questions in the inline Copilot Chat pane, without having to navigate away from the code editor.

Explain and Fix with Copilot in the Error List

If you want to learn more about the error itself, Copilot is integrated in the Error List to invoke by selecting the Copilot icon to the left of a code warning or error to provide an explanation alongside a proposed fix through the Chat pane. This can be beneficial for more complex fixes, as it can provide multiple code snippets across several files and a deeper understanding of the error itself.

Copilot icon in the error list to ask copilot for an explanation and a fix,

Given the same relevant C++ context, it will help you more deeply understand the error code and propose a fix for the code. You also can ask follow-up questions or add any additional details via the Chat pane to probe further.

Copilot Chat pane proposing an explanation and how to fix an error.

What do you think?

Please let us know anything you’d like to see added to this feature or your experiences with this fixing experience. We have a survey available for any feedback here: https://www.surveymonkey.com/r/RKG68YN. You’ll need an active GitHub Copilot subscription. Download the latest version of Visual Studio and give it a try.

In addition, our team is working hard on improving C++ integrations with Copilot Chat, so please let us know any other enhancements you’d like to see to your C++ workflows and content you’d like to see.

We welcome all types of feedback on your experience with the product. Comment below, or you can find us via email at visualcpp@microsoft.com or via X at @VisualC.

Category
C++Copilot

Author

Sinem Akinci
Product Manager II

C++ Product Manager working on Copilot, CMake, and Linux experiences in Visual Studio and VS Code

2 comments

  • Rob Bernstein

    This feature works great! However, I’m seeing the Copilot icon to the right of the code warning or error. Why isn’t it on the left? Is this configurable?

    • Sinem AkinciMicrosoft employee Author

      Thanks for the feedback and letting us know, we’ll look into it!

      In the meantime, you should be able to configure the Copilot icon to be on the left (or wherever you prefer) by clicking and dragging the top of the column heading around.