December 5th, 2024

Introducing Code Referencing for GitHub Copilot Chat in Visual Studio

Rhea Patel
Product Manager

Are you tired of the uncertainty that comes with using code suggestions from AI tools? We’ve got exciting news for you! Visual Studio 2022 now includes code referencing in GitHub Copilot, ensuring greater transparency and control for developers.

We are thrilled to announce that code referencing is now available in GitHub Copilot Chat within Visual Studio. This new feature introduces a filter that detects when code suggestions match public code on GitHub, providing you with valuable context to make more informed decisions about the code you incorporate into your projects.

Make Informed Decisions with Code Suggestions

In the rare instances where GitHub Copilot suggests code that matches public repositories on GitHub, this feature displays a list of those repositories along with their licenses directly in the editor. This transparency empowers you to:

  • Learn from existing implementations: Gain insights from how others have tackled similar problems.
  • Consider dependencies: Decide whether to use an existing library instead of writing new code.
  • Acknowledge similar work: Give or receive credit for comparable code within the community.

How It Works

When GitHub Copilot suggests code that matches public code, it now lets you know of this match. You can view the matching code, its source file, and any associated licensing information directly within Visual Studio. This allows you to make more informed decisions about whether to use the suggested code.

If a match is found, a notification appears in the editor showing:

  1. The matching code snippet
  2. Repositories where the code appears
  3. The licenses governing each repository

You have the option to block suggestions containing matching code or allow them with full awareness of their context.

In Copilot Chat it will show like this

Highlighting that copilot found similar code in git repos with the option to view

Instead of this:

Original error showing that the response matched public code so it was blcoked

Try It Out Today

We believe this new code referencing feature enhances your development experience by adding an extra layer of transparency and choice. Try it out in Visual Studio 17.12 Preview 3 and above, and let us know your feedback. Your insights help us improve and tailor our tools to better meet your needs.

Configuration Note

Please note that this feature may need to be configured by your administrator. To ensure its enabled for you, check your settings:

  • Copilot – Suggestions matching public code (duplication detection filter): Allowed

GitHub Copilot can provide you with details about matching code when you accept such suggestions. Learn more.

Enabling or Disabling Suggestions Matching Public Code

Note: If you are a member of an organization on GitHub Enterprise Cloud and have been assigned a GitHub Copilot seat through your organization, you may not be able to configure suggestions matching public code in your personal account settings. Your settings will be inherited from your organization or enterprise.

Your personal settings for GitHub Copilot include an option to either allow or block code suggestions that match publicly available code:

  • Block suggestions matching public code: GitHub Copilot checks code suggestions with their surrounding code against public code on GitHub. If there’s a match or near match, the suggestion is not shown.
  • Allow suggestions matching public code: When Copilot suggests matching code, you can view details of the matches and navigate to the relevant repositories on GitHub.

To adjust your settings:

  1. In the upper-right corner of any page on GitHub, click your profile photo, then click Your Copilot.
  2. Next to Suggestions matching public code, use the dropdown menu to select Allow or Block.

For more information, see Managing Copilot policies as an individual subscriber.

Developers often face the challenge of not knowing the origins of code suggestions offered by AI tools. This can lead to concerns about licensing and the appropriateness of using certain code snippets. With the new code referencing feature in GitHub Copilot, those worries are outdated.

Fostering knowledge sharing

By integrating code referencing into GitHub Copilot, we are fostering a culture of knowledge sharing and transparency. This feature not only empowers individual developers but also supports larger teams in navigating the complexities of public code with ease.

Author

Rhea Patel
Product Manager