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.

Animated screenshot that shows the code completion capabilities of the GitHub Copilot extension.

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:

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 Preview 3 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.

Exploring GitHub Copilot

To see GitHub Copilot in action, check out the following video tutorial.

Video length: 1.19 minutes

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.

  1. Open Visual Studio and create a new C# project.

  2. Open a C# file (Program.cs) in the editor.

  3. 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(
    
  4. 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 the Alt + . keyboard shortcut to cycle through them.

Animated screenshot that shows using the GitHub Copilot code suggestions in Visual Studio

  1. Add following code to see whole line completions from GitHub Copilot.

        int a = 5;
        int b = 10;
        int sum
    

Animated screenshot that shows using the GitHub Copilot completions in Visual Studio

Next steps

To learn more about the current GitHub Copilot extension for Visual Studio, consider exploring the following resources: