What is GitHub Copilot Completions for Visual Studio?
GitHub Copilot in Visual Studio enables enhanced AI-assisted development in Visual Studio, helping you be more productive and efficient when writing code.
In this article, you learn about Copilot Completions, an AI-powered pair programmer for Visual Studio that provides you with context-aware code completions, suggestions, and even entire code snippets. This powerful tool aids AI-assisted development in Visual Studio and helps developers write code more efficiently, reduce the time spent on repetitive tasks, and minimize errors.
For more information on GitHub Copilot Chat in Visual Studio, see About GitHub Copilot Chat in Visual Studio.
How GitHub Copilot works
GitHub Copilot works by utilizing advanced machine learning models trained on a vast dataset of publicly available code from GitHub repositories. As you type code, the AI analyzes the context and provides relevant suggestions in real-time. You can receive suggestions also by writing a natural language comment describing what you want the code to do.
You can also use GitHub Copilot to convert comments to code, create unit tests, create SQL queries, and more.
Prerequisites
To get started, you need:
Visual Studio 2022 version 17.8 or later
Active subscription to GitHub Copilot for Individuals or GitHub Copilot for Business
Sign in to Visual Studio with the GitHub account that has an active GitHub Copilot subscription
Tip
GitHub Copilot is free for verified students and for maintainers of popular open source projects on GitHub. If you are not a student or maintainer of a popular open source project, you can try GitHub Copilot for free with a one-time 30-day trial. After the free trial, you will need a paid subscription for continued use.
GitHub Copilot supports several programming languages and frameworks, including but not limited to: C#, C++, and Python.
Get GitHub Copilot for Visual Studio
- If you're using Visual Studio version 17.10 or later, the unified GitHub Copilot extension is available as a recommended component in the Visual Studio Installer. It is installed by default with all workloads, unless you choose to exclude it during installation.
- If you're using Visual Studio versions 17.9 or earlier, install the GitHub Copilot extension.
Using GitHub Copilot for code completions and suggestions
As you type code or comments in the editor, GitHub Copilot provides context-aware code completions and suggestions. GitHub Copilot provides suggestions for numerous languages, but works especially well for Python, JavaScript, TypeScript, Ruby, Go, C# and C++. The following examples are in C#, but other languages will work similarly.
Open Visual Studio and create a new C# project.
Open a C# file (
Program.cs
) in the editor.In the code editor, type a comment or a method signature to see inline code suggestions from GitHub Copilot.
// method to add two numbers
int subtractNumbers(
Hover over the suggestion to see the GitHub Copilot command palette. You can select Tab or press
Tab
to accept the suggestion or continue typing to reject it. If alternate suggestions are available, you can select next suggestion or use theAlt + .
keyboard shortcut to cycle through them.
Add following code to see whole line completions from GitHub Copilot.
int a = 5; int b = 10; int sum
Exploring GitHub Copilot
To see GitHub Copilot in action, check out the following video tutorial.
Video length: 1.19 minutes
Next steps
To learn more about the current GitHub Copilot extension for Visual Studio, consider exploring the following resources:
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for