Edit

Share via


What is GitHub Copilot Completions in Visual Studio?

GitHub Copilot in Visual Studio enables enhanced AI-assisted development in Visual Studio. This ability helps you be more productive and efficient when you're writing code.

In this article, you learn about GitHub Copilot Completions, an AI-powered pair programmer for Visual Studio that provides you with context-aware code completions, suggestions, and even entire code snippets. It helps developers reduce the time spent on repetitive tasks and minimize errors.

For related information about GitHub Copilot Chat, see What is the GitHub Copilot Chat experience for Visual Studio?.

How GitHub Copilot works

GitHub Copilot works by using advanced machine-learning models trained on a vast dataset of publicly available code from GitHub repositories. As you type code, AI analyzes the context and provides relevant suggestions in real time. You can also receive suggestions by writing a comment in natural language that describes what you want the code to do.

Animated screenshot that shows 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

GitHub Copilot supports several programming languages and frameworks, including (but not limited to) C#, C++, and Python.

How to get GitHub Copilot for Visual Studio

With Visual Studio 2022 version 17.10 or later, the unified GitHub Copilot extension is available as a recommended component in the Visual Studio Installer. It's installed by default with all workloads, unless you choose to exclude it during installation.

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 it works especially well for Python, JavaScript, TypeScript, Ruby, Go, C#, and C++. The following examples are in C#, but other languages work similarly.

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

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

  3. In the editor, enter 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.

    To accept the suggestion, select the Tab key. To reject the suggestion, continue typing.

    Screenshot that shows suggestions to accept or modify a GitHub Copilot code suggestion in Visual Studio.

    If the command palette doesn't appear, you might have reached the default limit for its display. To change this limit, go to Tools > Options > IntelliCode > Advanced, and adjust the value for Minimum commits to suppress hint text.

  5. Add the following code to see completions from GitHub Copilot:

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

    Animated screenshot that shows the use of the GitHub Copilot completions in Visual Studio.

Tips and tricks

Here are keyboard shortcuts related to completions:

  • Manually trigger a completion: Alt+. or Alt+,
  • Cycle through available completions: Alt+. (next) and Alt+, (previous)
  • Partially accept a completion word by word: Ctrl+Right arrow
  • Partially accept a completion line by line: Ctrl+Down arrow

Customize your completion experience by using settings:

  • If you feel that completions appear too quickly and interrupt your typing, go to Tools > Options > IntelliCode > Advanced and turn on Wait for pauses in typing before showing whole line completions. This setting adds a debounce delay, so completions don't flash and disappear while you're typing quickly.
  • By default, each of your keystrokes automatically triggers completions. To disable automatic completions, go to Tools > Options > IntelliCode > General and turn off Automatically generate code completions in the Editor. Then, use Alt+, to manually trigger completions.

Content exclusion

With Visual Studio 2022 version 17.11, content exclusion is available for GitHub Copilot Completions. Completions and suggestions aren't available for content that your admin excludes. To learn more, see Excluding content from GitHub Copilot.

Code referencing

With Visual Studio 2022 version 17.13, code referencing is available for GitHub Copilot Completions. If you or your organization enabled suggestions that match public code, Copilot notifies you when you accept a completion that matches code from a public GitHub repository.

Screenshot that shows GitHub Copilot Completions code referencing in Visual Studio. :::

To see detailed information in GitHub Copilot logs in the Output window, select View code matches. The log entry includes a link to a GitHub.com page where you can view details on license type. It also includes references to similar code in public GitHub repositories.

Screenshot that shows the log entry for a code reference in an output window.

Code referencing enables you to make an informed decision on using code attribution or removing the code from your project.

Completions model

The GPT-4o Copilot model for code completions is available for GitHub Copilot in Visual Studio version 17.14 Preview 2 or later.

To try the new model for better suggestions and performance:

  1. Go to Tools > Options > GitHub > Copilot > Copilot Completions.

  2. In the Copilot Completions Model dropdown list, select GPT-4o Copilot.

    Screenshot that shows the dropdown list for selecting a completions model.

If you don't see the new GPT-4o model in the dropdown list, try restarting Visual Studio to retrieve the latest model list.

You can also access Settings > Options from the Copilot badge in the upper-right corner of the editor.

Access

  • If you're a Copilot Pro user, the new model is available for you in 17.14 Preview 2 and later.
  • If you're a Copilot Business or Enterprise user, your administrator needs to enable this model for your organization by opting in to editor preview features in the Copilot policy settings on GitHub.com.
  • If you're a Copilot Free user, using this model counts toward your 2,000 free monthly completions.

Generation of documentation comments

To use automatic generation of documentation comments on your C++ or C# project file, type the comment pattern according to your configuration (for example, ///). Copilot instantly completes the function description based on the function's content.

Animated screenshot that shows the automatic generation of documentation comments from Copilot.

Exploring GitHub Copilot

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

Video length is 1 minute and 19 seconds.

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