About Copiloto de GitHub and Visual Studio Code
Copiloto de GitHub provides autocomplete-style suggestions from an AI pair programmer as you code. For more information, see "About Copiloto de GitHub".
If you use Visual Studio Code, you can view and incorporate suggestions from Copiloto de GitHub directly within the editor. This guide demonstrates how to use Copiloto de GitHub within Visual Studio Code for macOS, Windows, or Linux.
Prerequisites
To use Copiloto de GitHub in Visual Studio Code, you must have Visual Studio Code installed. For more information, see the Visual Studio Code download page.
Installing the Visual Studio Code extension
To use Copiloto de GitHub, you must first install the Visual Studio Code extension.
- In the Visual Studio Code Marketplace, go to the Copiloto de GitHub extension page and click Install.
- A popup will appear, asking to open Visual Studio Code. Click Open Visual Studio Code.
- In the "Extension: Copiloto de GitHub" tab in Visual Studio Code, click Install.
- If you have not previously authorized Visual Studio Code in your GitHub account, you will be prompted to sign in to GitHub in Visual Studio Code.
- If you have previously authorized Visual Studio Code for your account on GitHub, Copiloto de GitHub will be automatically authorized.
- If you have previously authorized Visual Studio Code for your account on GitHub, Copiloto de GitHub will be automatically authorized.
- In your browser, GitHub will request the necessary permissions for Copiloto de GitHub. To approve these permissions, click Authorize Visual Studio Code.
- In Visual Studio Code, in the "Visual Studio Code" dialog box, to confirm the authentication, click Open.
Seeing your first suggestion
Copiloto de GitHub provides suggestions for numerous languages and a wide variety of frameworks, but works especially well for Python, JavaScript, TypeScript, Ruby, Go, C# and C++. The following samples are in JavaScript, but other languages will work similarly.
- In Visual Studio Code, create a new JavaScript (*.js) file.
- In the JavaScript file, type the following function header. Copiloto de GitHub will automatically suggest an entire function body in grayed text, as shown below. The exact suggestion may vary.
JavaScript function calculateDaysBetweenDates(begin, end) {
- To accept the suggestion, press Tab.
Seeing alternative suggestions
For any given input, Copiloto de GitHub may offer multiple suggestions. You can select which suggestion to use, or reject all suggestions.
-
In Visual Studio Code, create a new JavaScript (*.js) file.
-
In the JavaScript file, type the following function header. Copiloto de GitHub will show you a suggestion.
JavaScript function calculateDaysBetweenDates(begin, end) {
-
Optionally, you can see alternative suggestions, if any are available.
OS See next suggestion See previous suggestion macOS Option (⌥) or Alt+] Option (⌥) or Alt+[ Windows Alt+] Alt+[ Linux Alt+] Alt+[ -
Alternatively, you can hover over the suggestion to see the Copiloto de GitHub command palette for choosing suggestions.
-
To accept a suggestion, press Tab. To reject all suggestions, press Esc.
Seeing multiple suggestions in a new tab
You may not want any of the initial suggestions Copiloto de GitHub offers. You can use a keyboard shortcut to prompt Copiloto de GitHub to show you multiple suggestions in a new tab.
- In Visual Studio Code, create a new JavaScript (*.js) file.
- In the JavaScript file, type the following function header. Copiloto de GitHub will show you a suggestion.
JavaScript function calculateDaysBetweenDates(begin, end) {
- To open a new tab with multiple additional options, press Ctrl+Enter.
- To accept a suggestion, above the suggestion, click Accept Solution. To reject all suggestions, close the tab.
Generating code suggestions from comments
You can describe something you want to do using natural language within a comment, and Copiloto de GitHub will suggest the code to accomplish your goal.
- In Visual Studio Code, create a new JavaScript (*.js) file.
- In the JavaScript file, type the following comment. Copiloto de GitHub will suggest an implementation of the function.
JavaScript // find all images without alternate text // and give them a red border function process() {
Using a framework
You can also use Copiloto de GitHub to generate suggestions for APIs and frameworks. The following example uses Copiloto de GitHub to create a simple Express server that returns the current time.
- In Visual Studio Code, create a new JavaScript (*.js) file.
- In the JavaScript file, type the following comment and then press Enter. Copiloto de GitHub will suggest an implementation of the Express app.
JavaScript // Express server on port 3000
- To accept each line, press Tab, then Enter.
- Type the following comment and then press Enter. Copiloto de GitHub will suggest an implementation for the default handler.
JavaScript // Return the current time
- To accept each line, press Tab.
Enabling or disabling Copiloto de GitHub
You can enable or disable Copiloto de GitHub from within Visual Studio Code. The Copiloto de GitHub status icon in the bottom panel of the Visual Studio Code window indicates whether Copiloto de GitHub is enabled or disabled. When enabled, the background color of the icon will match the color of the status bar. When disabled, the background color of the icon will contrast with the color of the status bar.
-
To enable or disable Copiloto de GitHub, click the status icon in the bottom panel of the Visual Studio Code window.
-
If you are disabling Copiloto de GitHub, you will be asked whether you want to disable suggestions globally, or for the language of the file you are currently editing.
- To disable suggestions from Copiloto de GitHub globally, click Disable Globally.
- To disable suggestions from Copiloto de GitHub for the specified language, click Disable for LANGUAGE.