Skip to content

Commit

Permalink
Document code referencing for Copilot Chat in VS Code (#51877)
Browse files Browse the repository at this point in the history
Co-authored-by: Sam Browning <[email protected]>
  • Loading branch information
hubwriter and sabrowning1 authored Sep 30, 2024
1 parent 5fb98cc commit 381a31a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ In addition to the configuration for the {% data variables.product.prodname_copi

> [!NOTE] If you are a member of an organization on {% data variables.product.prodname_ghe_cloud %} who has been assigned a {% data variables.product.prodname_copilot %} seat through your organization, you will not be able to configure suggestions matching public code in your personal account settings. Your setting for suggestions matching public code will be inherited from your organization or enterprise.
Your personal settings for {% data variables.product.prodname_copilot %} include an option to either allow or block code completion suggestions that match publicly available code. If you choose to block suggestions matching public code, {% data variables.product.prodname_copilot %} checks code completion suggestions with their surrounding code of about 150 characters against public code on {% data variables.product.prodname_dotcom %}. If there is a match, or a near match, the suggestion is not shown to you.
Your personal settings for {% data variables.product.prodname_copilot %} include an option to either allow or block code suggestions that match publicly available code. If you choose to block suggestions matching public code, {% data variables.product.prodname_copilot %} checks code suggestions with their surrounding code of about 150 characters against public code on {% data variables.product.prodname_dotcom %}. If there is a match, or a near match, the suggestion is not shown to you.

If you choose to allow suggestions matching public code, and you accept a suggestion for which one or more matches were found, you can click through from an entry in the {% data variables.product.prodname_copilot %} log to view a list of references on {% data variables.product.prodname_dotcom %}. For more information, see "[AUTOTITLE](/copilot/using-github-copilot/finding-public-code-that-matches-github-copilot-suggestions)."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The policy settings selected by an organization owner determine the behavior of

### Policies for suggestion matching

Organization settings include an option to either allow or block code completion suggestions that match publicly available code. If you choose to block suggestions matching public code, {% data variables.product.prodname_copilot %} will check potential code completion suggestions and the surrounding code of about 150 characters against public code on {% data variables.product.prodname_dotcom %}. If there is a match, or a near match, the suggestion is not shown.
Organization settings include an option to either allow or block code suggestions that match publicly available code. If you choose to block suggestions matching public code, {% data variables.product.prodname_copilot %} will check potential code suggestions and the surrounding code of about 150 characters against public code on {% data variables.product.prodname_dotcom %}. If there is a match, or a near match, the suggestion is not shown.

{% ifversion ghec %}If your enterprise admin has selected **No policy** for suggestion matching at the enterprise level, you can set a suggestion matching policy for your organization.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Finding public code that matches GitHub Copilot suggestions
shortTitle: Find matching code
intro: 'If you allow {% data variables.product.prodname_copilot %} to make suggestions that match publicly available code, you can see references to the matching code on {% data variables.product.prodname_dotcom_the_website %}.'
intro: 'If you allow {% data variables.product.prodname_copilot %} to make suggestions that match publicly available code, you''ll see references to the matching code that was found on {% data variables.product.prodname_dotcom_the_website %}.'
redirect_from:
- /early-access/copilot/code-referencing-in-github-copilot
topics:
Expand All @@ -10,30 +10,42 @@ versions:
feature: copilot
---

> [!NOTE] {% data variables.product.prodname_copilot %} code referencing is in {% data variables.release-phases.public_preview %} and is subject to change.
## Limitations

References to matching code are currently only available in {% data variables.product.prodname_vscode %}.

## Prerequisites

References to matching code are only generated if {% data variables.product.prodname_copilot_short %} is configured to allow suggestions that match publicly available code. For more information, see "[AUTOTITLE](/copilot/configuring-github-copilot/configuring-your-personal-github-copilot-settings-on-githubcom#enabling-or-disabling-suggestions-matching-public-code)."

## About code referencing in {% data variables.product.prodname_copilot %}

You can opt to allow {% data variables.product.prodname_copilot %} to suggest code completions that match publicly available code on {% data variables.product.prodname_dotcom_the_website %}. For more information, see "[AUTOTITLE](/copilot/configuring-github-copilot/configuring-your-personal-github-copilot-settings-on-githubcom#enabling-or-disabling-suggestions-matching-public-code)."
If you've allowed suggestions that match public code, {% data variables.product.prodname_copilot %} in {% data variables.product.prodname_vscode_shortname %} can provide you with details of the code that a suggestion matches. This happens:

* When you accept a code completion suggestion in the editor.
* When a response in {% data variables.product.prodname_copilot_chat_short %} includes matching code.

If you have allowed suggestions that match public code, {% data variables.product.prodname_copilot %} can provide you with details about the matching code when you accept such suggestions. This feature is called code referencing. It is currently only available in {% data variables.product.prodname_vscode %}.
This feature is called code referencing.

### Code referencing for {% data variables.product.prodname_copilot_short %} code completion

When you accept a code completion suggestion that matches code in a public {% data variables.product.prodname_dotcom %} repository, an entry is added to a {% data variables.product.prodname_copilot %} log. The log entry includes a link to a page on {% data variables.product.prodname_dotcom_the_website %} where you can view references to similar code in public {% data variables.product.prodname_dotcom %} repositories.

The linked web page includes details of any license identified for the repository where the matching code was found. Having reviewed the references, you can decide how to proceed. For example, you can decide what attribution to use, or whether you want to remove this code from your project.

> [!NOTE]
> * Code referencing does not currently apply to code completion suggestions that you add to your code using {% data variables.product.prodname_copilot_chat %}.
> * Code referencing currently only looks for matches of accepted {% data variables.product.prodname_copilot_short %} suggestions. Matches to code you have written, or {% data variables.product.prodname_copilot_short %} suggestions you have altered, is not checked for matches to public code.
> * Typically, matches to public code occur in less than one percent of {% data variables.product.prodname_copilot_short %} suggestions, so you should not expect to see code references for many of the suggestions you accept.
> * Code referencing only occurs for matches of accepted {% data variables.product.prodname_copilot_short %} suggestions. Code you have written, and {% data variables.product.prodname_copilot_short %} suggestions you have altered, are not checked for matches to public code.
> * Typically, matches to public code occur in less than one percent of {% data variables.product.prodname_copilot_short %} suggestions, so you should not expect to see code references for many suggestions.
### Code referencing for {% data variables.product.prodname_copilot_chat_short %}

When {% data variables.product.prodname_copilot_chat_short %} provides a response that includes code that matches code in a public {% data variables.product.prodname_dotcom %} repository, this is indicated at the end of the response with a link to display details of the matched code in the {% data variables.product.prodname_vscode_shortname %} editor.

### How code referencing finds matching code

{% data variables.product.prodname_copilot_short %} code referencing searches for matches by taking the code suggestion, plus some surrounding code, and comparing it against an index of all public repositories on {% data variables.product.prodname_dotcom_the_website %}. Code in private {% data variables.product.prodname_dotcom %} repositories, or code outside of {% data variables.product.prodname_dotcom %}, is not included in the search process. The search index is refreshed every few months. As a result, newly committed code, and code from public repositories deleted before the index was created, may not be included in the search. For the same reason, the search may return matches to code that has been deleted or moved since the index was created.

## Using code referencing in {% data variables.product.prodname_vscode %}

To use code referencing you must have allowed suggestions matching public code. For more information, see "[AUTOTITLE](/copilot/configuring-github-copilot/configuring-your-personal-github-copilot-settings-on-githubcom#enabling-or-disabling-suggestions-matching-public-code)."
## View code references for code completion

You can access code references from one of the {% data variables.product.prodname_copilot %} logs in {% data variables.product.prodname_vscode %}.

Expand Down Expand Up @@ -88,3 +100,19 @@ You can verify that code referencing is working by prompting {% data variables.p
1. Accept the suggestion by pressing <kbd>Tab</kbd>.

If code referencing finds a match to public code, a log entry is added to the **{% data variables.product.prodname_copilot %} Log** view.

## View code references for {% data variables.product.prodname_copilot_chat_short %}

If a response in {% data variables.product.prodname_copilot_chat_short %} includes matching code, this is indicated at the end of the response by the following text:

> Similar code found with _n_ license types - **View matches**

1. Click **View matches** to display details of the matched code in a new editor tab.

For each example of matching code, the editor displays:

* The license type for the matching code, if known.
* The URL of the file on {% data variables.product.prodname_dotcom_the_website %} where the matching code was found.
* A code snippet showing the matching code.

1. In the editor, <kbd>Ctrl</kbd>+click (Windows/Linux) or <kbd>Command</kbd>+click (Mac) a URL to view the full file on {% data variables.product.prodname_dotcom_the_website %}.
22 changes: 21 additions & 1 deletion data/reusables/rai/copilot/copilot-chat-ide-limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,27 @@ Depending on factors such as your codebase and input data, you may experience di

### Matches with public code

{% data variables.product.prodname_copilot_chat_short %} is capable of generating new code, which it does in a probabilistic way. While the probability that it may produce code that matches code in the training set is low, a {% data variables.product.prodname_copilot_chat_short %} suggestion may contain some code snippets that match code in the training set. {% data variables.product.prodname_copilot_chat_short %} utilizes filters that block matches with public code on {% data variables.product.prodname_dotcom %} repositories, but you should always take the same precautions as you would with any code you write that uses material you did not independently originate, including precautions to ensure its suitability. These include rigorous testing, IP scanning, and checking for security vulnerabilities. You should make sure your IDE or editor does not automatically compile or run generated code before you review it.
{% data variables.product.prodname_copilot_chat_short %} is capable of generating new code, which it does in a probabilistic way. While the probability that it may produce code that matches code in the training set is low, a {% data variables.product.prodname_copilot_chat_short %} suggestion may contain some code snippets that match code in the training set.

{% vscode %}

If you have disabled suggestions that match public code then {% data variables.product.prodname_copilot_chat_short %} utilizes filters that prevent it from showing code that matches code found in public repositories on {% data variables.product.prodname_dotcom %}. However, you should always take the same precautions as you would with any code you write that uses material you did not independently originate, including precautions to ensure its suitability. These include rigorous testing, IP scanning, and checking for security vulnerabilities. You should make sure your IDE or editor does not automatically compile or run generated code before you review it.

If you have enabled suggestions that match public code then {% data variables.product.prodname_copilot_chat_short %} displays a message if matching code is found. The message includes a link that allows you to show the details of the matched code, and any license details that were found, in the {% data variables.product.prodname_vscode_shortname %} editor. For more information, see "[AUTOTITLE](/copilot/using-github-copilot/finding-public-code-that-matches-github-copilot-suggestions)."

{% endvscode %}

{% visualstudio %}

{% data variables.product.prodname_copilot_chat_short %} utilizes filters that block matches with public code on {% data variables.product.prodname_dotcom %} repositories, but you should always take the same precautions as you would with any code you write that uses material you did not independently originate, including precautions to ensure its suitability. These include rigorous testing, IP scanning, and checking for security vulnerabilities. You should make sure your IDE or editor does not automatically compile or run generated code before you review it.

{% endvisualstudio %}

{% jetbrains %}

{% data variables.product.prodname_copilot_chat_short %} utilizes filters that block matches with public code on {% data variables.product.prodname_dotcom %} repositories, but you should always take the same precautions as you would with any code you write that uses material you did not independently originate, including precautions to ensure its suitability. These include rigorous testing, IP scanning, and checking for security vulnerabilities. You should make sure your IDE or editor does not automatically compile or run generated code before you review it.

{% endjetbrains %}

### Inaccurate code

Expand Down

0 comments on commit 381a31a

Please sign in to comment.