Skip to content

Commit c335cd6

Browse files
hubwriterSiaraMist
andauthored
Document support for Copilot code referencing in Visual Studio (#55024)
Co-authored-by: Siara <[email protected]>
1 parent 91432c1 commit c335cd6

File tree

3 files changed

+128
-57
lines changed

3 files changed

+128
-57
lines changed

content/copilot/using-github-copilot/finding-public-code-that-matches-github-copilot-suggestions.md

Lines changed: 110 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Finding public code that matches GitHub Copilot suggestions
33
shortTitle: Find matching code
4-
intro: 'If you allow {% data variables.product.prodname_copilot %} to make suggestions that match publicly available code, {% data variables.product.prodname_copilot_short %} will display references to any matching code that is found.'
4+
intro: 'If you allow {% data variables.product.prodname_copilot %} to make suggestions that match publicly available code, {% data variables.product.prodname_copilot_short %} will display references to any similar code that is found.'
55
defaultTool: vscode
66
redirect_from:
77
- /early-access/copilot/code-referencing-in-github-copilot
@@ -30,9 +30,15 @@ This version of this article is for {% data variables.product.prodname_copilot_s
3030

3131
{% endwebui %}
3232

33+
{% visualstudio %}
34+
35+
This version of this article is for {% data variables.product.prodname_copilot_short %} in {% data variables.product.prodname_vs %}. For {% data variables.product.prodname_copilot_short %} on other platforms, click the appropriate tab above.
36+
37+
{% endvisualstudio %}
38+
3339
## Limitations
3440

35-
References to matching code are currently only available in JetBrains IDEs, {% data variables.product.prodname_vscode %}, and on the {% data variables.product.github %} website.
41+
References to matching code are currently available in JetBrains IDEs, {% data variables.product.prodname_vs %}, {% data variables.product.prodname_vscode %}, and on the {% data variables.product.github %} website.
3642

3743
## Prerequisites
3844

@@ -58,14 +64,18 @@ If you've allowed suggestions that match public code, then whenever a response f
5864

5965
{% endwebui %}
6066

67+
{% visualstudio %}
68+
69+
{% data reusables.copilot.about-code-referencing %}
70+
71+
{% endvisualstudio %}
72+
6173
This feature is called code referencing.
6274

6375
{% jetbrains %}
6476

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

67-
When you accept a code completion suggestion that matches code in a public {% data variables.product.prodname_dotcom %} repository, an entry is added to the JetBrains log. The log entry includes the URLs of files containing matching code, and the name of the license that applies to that code, if any was found. This allows you to review these references and decide how to proceed. For example, you can decide what attribution to use, or whether you want to remove this code from your project.
68-
6979
{% data reusables.copilot.code-referencing-note %}
7080

7181
### Code referencing for {% data variables.product.prodname_copilot_chat_short %}
@@ -85,10 +95,6 @@ When you accept a code completion suggestion that matches code in a public {% da
8595

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

88-
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.
89-
90-
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.
91-
9298
{% data reusables.copilot.code-referencing-note %}
9399

94100
### Code referencing for {% data variables.product.prodname_copilot_chat_short %}
@@ -97,6 +103,18 @@ The linked web page includes details of any license identified for the repositor
97103

98104
{% endvscode %}
99105

106+
{% visualstudio %}
107+
108+
### Code referencing for {% data variables.product.prodname_copilot_short %} code completion
109+
110+
{% data reusables.copilot.code-referencing-note %}
111+
112+
### Code referencing for {% data variables.product.prodname_copilot_chat_short %}
113+
114+
When {% data variables.product.prodname_copilot_chat_short %} provides a response that includes code that matches code in a public {% data variables.product.github %} repository, this is indicated below the suggested code, with a link to display details of the matched code in the output log.
115+
116+
{% endvisualstudio %}
117+
100118
### How code referencing finds matching code
101119

102120
{% data variables.product.prodname_copilot_short %} code referencing searches for matches by taking the code suggestion, plus some of the code that will surround the suggestion if it is accepted, 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.
@@ -125,7 +143,7 @@ You can view code references in the log file for your JetBrains IDE.
125143
The log entry includes the following details:
126144

127145
* The date and time you accepted the suggestion.
128-
* A "Public Code References" message telling you that matching code was found.
146+
* A "Public Code References" message telling you that similar code was found.
129147
* The path to the file in which the suggestion was added.
130148
* The line and column number where the suggestion was added.
131149
* A list of matches, including:
@@ -134,87 +152,76 @@ The log entry includes the following details:
134152

135153
### Verifying the code referencing functionality
136154

137-
You can verify that code referencing is working by prompting {% data variables.product.prodname_copilot_short %} to add some commonly used code and checking the output in the log file for your IDE.
138-
139-
1. Display the log file for your JetBrains IDE, as described in the previous section.
140-
1. Create a file called `fizz-buzz.js` and open it in the JetBrains editor.
141-
1. In the editor, type:
142-
143-
```javascript
144-
function fizzBuzz()
145-
```
146-
147-
With a space after the closing parenthesis.
148-
149-
{% data variables.product.prodname_copilot %} should suggest code to complete the function. Typically the suggestion will be a common implementation of the fizz buzz algorithm that will match publicly available code on the {% data variables.product.github %} website.
150-
151-
1. Accept the suggestion by pressing <kbd>Tab</kbd>.
152-
1. Check whether a "[Public Code References]" entry has been added to the log file.
155+
{% data reusables.copilot.code-referencing-verifying %}
153156

154157
{% endjetbrains %}
155158

156159
{% vscode %}
157160

158161
## View code references for code completion
159162

160-
You can access code references from one of the {% data variables.product.prodname_copilot %} logs in {% data variables.product.prodname_vscode %}.
163+
You can find code references in one of the {% data variables.product.prodname_copilot %} logs in {% data variables.product.prodname_vscode %}.
161164

162165
1. In {% data variables.product.prodname_vscode %}, open the **Output** window by selecting **View** > **Output** from the menu bar.
163-
1. In the dropdown menu at the right of the **Output** window, select **{% data variables.product.prodname_copilot %} Log**.
164-
165-
![Screenshot of the Output window with "{% data variables.product.prodname_copilot %} Log" selected from the dropdown menu.](/assets/images/help/copilot/copilot-log-selected.png)
166-
167-
1. Leave the **{% data variables.product.prodname_copilot %} Log** view displayed while you use {% data variables.product.prodname_copilot %} in {% data variables.product.prodname_vscode %}.
166+
1. In the dropdown menu at the right of the **Output** window, select **{% data variables.product.prodname_copilot %} Log (Code References)**.
167+
1. Leave the **{% data variables.product.prodname_copilot %} Log (Code References)** view displayed while you use {% data variables.product.prodname_copilot %} in {% data variables.product.prodname_vscode %}.
168168

169169
When you accept a code completion suggestion that matches code in a public {% data variables.product.prodname_dotcom %} repository, an entry is added to the log.
170170

171171
The log entry includes the following details:
172172

173173
* The date and time you accepted the suggestion.
174174
* The name of the file in which the suggestion was added.
175-
* A message telling you that similar code was found, with the number and type of licenses.
176-
* A link to a page on {% data variables.product.prodname_dotcom_the_website %}.
177-
* The location in the file where the suggestion was added.
178-
* A snippet of part of the code that was suggested and added.
175+
* "Similar code at" followed by the location in the file where the suggestion was added.
176+
* An extract of the code that was added by code completion.
177+
* The license type for the matching code, if found, otherwise `unknown`.
178+
* The URL of the file on {% data variables.product.prodname_dotcom_the_website %} where the similar code was found.
179179

180-
![Screenshot of the Output window showing a code referencing log entry.](/assets/images/help/copilot/copilot-code-referencing-log.png)
180+
### Example log entry
181181

182-
> [!NOTE] The {% data variables.product.prodname_copilot %} log is flushed when you close the editor.
182+
```text
183+
2025-03-27 12:17:54.759 [info] file:///Users/monalisa/fizzbuzz.js Similar code at [Ln 2, Col 8] let i = 1; i <= 100; i++) { let output = ''; if (i % 3 === 0) { output += 'Fizz';...
184+
2025-03-27 12:17:54.759 [info] License: unknown, URL: https://github.com/octo-org/octo-repo/blob/8563f3b1d4f33952b22212b86e745539d1567ed1/examples/fizzBuzz.js
185+
2025-03-27 12:17:54.759 [info] License: MIT, URL: https://github.com/octo-org/monalisa/blob/7e974691f4c8e6bc55f9b50688f05d746d1bc52b/exercises/2/fizz-buzz.js
186+
```
183187

184-
1. In the log entry, <kbd>Ctrl</kbd>+click (Windows/Linux) or <kbd>Command</kbd>+click (Mac) the link to view the code references on {% data variables.product.prodname_dotcom_the_website %}.
188+
### Verifying the code referencing functionality
185189

186-
The page lists the matches that were found, showing an excerpt from the relevant file. You can click on the file name to view the whole file.
190+
{% data reusables.copilot.code-referencing-verifying %}
187191

188-
![Screenshot of code references listed on {% data variables.product.prodname_dotcom_the_website %}.](/assets/images/help/copilot/code-references-webpage.png)
192+
{% endvscode %}
189193

190-
Matches may be found in multiple repositories with different, sometimes conflicting, licenses. You can use the checkboxes on the left of the page to show only the matches associated with a particular license.
194+
{% visualstudio %}
191195

192-
You should review all license information within a repository to verify that it applies to the matching code, as repositories may contain multiple licenses and these licenses are subject to human and non-human error.
196+
## View code references for code completion
193197

194-
> [!NOTE] The web page displaying the full set of details will remain available for three months.
198+
You can find code references in the {% data variables.product.prodname_copilot %} log in {% data variables.product.prodname_vs %}.
195199

196-
### Verifying the code referencing functionality
200+
1. In the menu bar, click **View**.
201+
1. In the dropdown menu, click **Output**.
202+
1. In Output view, click the box to the right of "Show output from" and select **{% data variables.product.prodname_copilot %}**.
203+
1. Leave the log displayed while you use {% data variables.product.prodname_copilot %} in {% data variables.product.prodname_vscode %}.
197204

198-
You can verify that code referencing is working by prompting {% data variables.product.prodname_copilot_short %} to add some commonly used code and checking the output in the {% data variables.product.prodname_copilot_short %} log.
205+
When you accept a code completion suggestion that matches code in a public {% data variables.product.prodname_dotcom %} repository, an entry is added to the log.
199206

200-
1. In {% data variables.product.prodname_vscode %}, create a file called `fizz-buzz.js`.
201-
1. Open the **Output** window by selecting **View** > **Output** from the menu bar.
202-
1. In the dropdown menu at the right of the **Output** window, select **{% data variables.product.prodname_copilot %} Log**.
203-
1. In the editor, type:
207+
The log entry includes the following details:
204208

205-
```javascript
206-
function fizzBuzz()
207-
```
209+
* The time you accepted the suggestion. Click the "Show Timestamp" clock icon if the time is not displayed.
210+
* The description `[Completions Public Code Match Information]`.
211+
* The license type for the matching code, if found, otherwise `NOASSERTION`.
212+
* The URL of the file on {% data variables.product.prodname_dotcom_the_website %} where the similar code was found.
208213

209-
With a space after the closing parenthesis.
214+
### Example log entry
210215

211-
{% data variables.product.prodname_copilot %} should suggest code to complete the function. Typically the suggestion will be a common implementation of the fizz buzz algorithm that will match publicly available code on the {% data variables.product.github %} website.
216+
```text
217+
09:39:16:203 [Completions Public Code Match Information] Similar code with license type [MIT] https://github.com/octo-org/octo-repo/blob/34deb75eb6a2e22483ed465a6aec38c02eb2536e/routines/quicksort.js
218+
```
212219

213-
1. Accept the suggestion by pressing <kbd>Tab</kbd>.
220+
### Verifying the code referencing functionality
214221

215-
If code referencing finds a match to public code, a log entry is added to the **{% data variables.product.prodname_copilot %} Log** view.
222+
{% data reusables.copilot.code-referencing-verifying %}
216223

217-
{% endvscode %}
224+
{% endvisualstudio %}
218225

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

@@ -230,6 +237,52 @@ You can verify that code referencing is working by prompting {% data variables.p
230237

231238
{% endvscode %}
232239

240+
{% visualstudio %}
241+
242+
If a response in {% data variables.product.prodname_copilot_chat_short %} includes matching code, this is below the suggested code by the following text:
243+
244+
> Found similar code in public repos. **View matches**
245+
246+
Click **View matches** to open the {% data variables.product.prodname_copilot %} log, if it is not already open, and add details of the matched code.
247+
248+
The details include:
249+
250+
* The time you added the details to the log. Click the "Show Timestamp" clock icon if the time is not displayed.
251+
* The description `[Code Match]` as the first log entry before the list of matching code.
252+
* The license type—if found—for each instance of similar code.
253+
* The URL of the file on {% data variables.product.prodname_dotcom_the_website %} where the matching code was found.
254+
* A code snippet showing the matching code.
255+
256+
### Logging example
257+
258+
```text
259+
09:24:10:525 [Code Match] Similar code with 2 license type(s) [MIT, NOASSERTION]
260+
09:24:10:525 ## License: MIT
261+
09:24:10:525 https://github.com/octo-org/octo-repo/tree/127aac4ab27a42706af01be80f7aae3b83f44fbc/buzzfizz.py
262+
09:24:10:525 ```
263+
09:24:10:525 for i in range(1, n + 1):
264+
09:24:10:525 if i % 3 == 0 and i % 5 == 0:
265+
09:24:10:525 print('FizzBuzz')
266+
09:24:10:525 elif i % 3 == 0:
267+
09:24:10:525 print('Fizz')
268+
09:24:10:525 elif i % 5 == 0:
269+
09:24:10:525 ```
270+
09:24:10:525 ## License: NOASSERTION
271+
09:24:10:525 https://github.com/octo-org/monalisa/tree/011308746e53b26b128fa53c044a2527c39231f0/fizz-buzz.py
272+
09:24:10:525 ```
273+
09:24:10:525 i % 3 == 0 and i % 5 == 0:
274+
09:24:10:525 print('FizzBuzz')
275+
09:24:10:525 elif i % 3 == 0:
276+
09:24:10:525 print('Fizz')
277+
09:24:10:525 elif i % 5 == 0:
278+
09:24:10:525 print('Buzz')
279+
09:24:10:525 else:
280+
09:24:10:525 print(i)
281+
09:24:10:525 ```
282+
```
283+
284+
{% endvisualstudio %}
285+
233286
{% webui %}
234287

235288
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 beneath the code suggestion:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
When you accept a code completion suggestion that matches code in a public {% data variables.product.prodname_dotcom %} repository, information about the matching code is logged. The log entry includes the URLs of files containing matching code, and the name of the license that applies to that code, if any was found. This allows you to review these references and decide how to proceed. For example, you can decide what attribution to use, or whether you want to remove this code from your project.
2+
13
> [!NOTE]
24
> * Code referencing for code completion 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.
35
> * 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.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
You can verify that code referencing is working by prompting {% data variables.product.prodname_copilot_short %} to add some commonly used code and checking the output in the log.
2+
3+
1. Create a file called `fizz-buzz.js` and open it in the editor.
4+
1. Display the log as described in the previous section.
5+
1. In the editor, type:
6+
7+
```javascript
8+
function fizzBuzz()
9+
```
10+
11+
With a space after the closing parenthesis.
12+
13+
{% data variables.product.prodname_copilot %} should suggest code to complete the function. Typically the suggestion will be a common implementation of the fizz buzz algorithm that will match publicly available code on the {% data variables.product.github %} website.
14+
15+
1. To accept the suggestion, press <kbd>Tab</kbd>.
16+
1. Check whether any entries for similar code have been added to the log.

0 commit comments

Comments
 (0)