Guides for SE student projects »

This is a WIP community resource, containing contribution from community members.

Intellij IDEA: Using GitHub Copilot

GitHub Copilot is an AI-powered coding assistant that integrates smoothly with IntelliJ IDEA. While Copilot is developed by GitHub (a Microsoft-owned company) and initially optimized for VS Code, it also offers robust support for JetBrains IDEs through an official plugin, ensuring a seamless coding experience across different development environments.

Pre-requisites

If you have not enabled Copilot in your GitHub account, follow the guide in the panel below:

Signing Up for GitHub Copilot

GitHub Copilot is an account-linked service that sits on top of your GitHub account. You need to enable it (via subscription or educational benefits) to use it. Given below are the steps:

  • Sign up for a GitHub Account, if you don't have one yet.
  • Fill in your billing information
  • Enable Two-Factor Authentication (2FA). You can skip this step if you have already done so.
    • Go to the Two-factor authentication page for your GitHub account.
    • Click on Enable two-factor authentication.
    • Open the Microsoft Authenticator App on your phone.
    • Tap the scan QR code button at the bottom right.
    • Scan the QR code displayed on the GitHub page.
    • Complete the remaining setup steps.
    • You should see the following page when 2FA is enabled.
  • Link your university email to GitHub (for Education benefits).
    • Go to the emails settings page in GitHub account.
    • Add your university-issued email under the Add email address field.
    • Verify your email using the link sent to your inbox.
    • Once verified, you will see your school email in the list of emails.
  • Apply for GitHub Education benefits
    • Go to the GitHub Education page.
    • Click on Start an application.
    • Select your role as Student.
    • Choose university as your school (e.g., National University of Singapore).
    • Follow the instructions and complete the application form.
    • Once your application is approved, it will show that you have a current student coupon applied.

Contributors: Norbert Loh (@NorbertLoh )


Installing GitHub Copilot in IntelliJ IDEA

  • Updating Visual Studio Code
    • Open IntelliJ IDEA.
    • Go to FileSettingsAppearance & BehaviorSystem SettingsUpdatesCheck for Updates….
    • If updates are available, click Update and Restart.
    • Confirm the update in the pop-up window.
    • After the update is installed, restart IntelliJ IDEA.
  • Install the Extension Pack for GitHub Copilot, to enable support for AI autocompletion.
    • Open IntelliJ IDEA.
    • Go to FileSettingsPluginsMarketplace.
    • Search for "GitHub Copilot".
    • Click Install on the plugin developed by GitHub.
    • Restart IntelliJ by clicking Restart IDERestart.

Signing in to GitHub Copilot

  • Verify Prerequisites
  • Sign in to GitHub Copilot
    • Open IntelliJ IDEA.
    • Click the GitHub Copilot icon in the right-hand sidebar.
    • Click Sign in to GitHub.
    • In the pop-up, click Copy and Open.
    • You'll be redirected to the GitHub login page. Log in or select the account linked to GitHub Education.
    • Paste the copied code Ctrl+V, click Continue, then Authorize GitHub Copilot Plugin.
    • GitHub Copilot will now be signed in within IntelliJ.
  • Verifying the installation of GitHub Copilot
    • Create a scratch file via FileNewScratch FileJava.
    • On line 3, type / and a suggestion should appear automatically.

Using GitHub Copilot in IntelliJ IDEA

Basic Code Completion

  • In a Java file, type a comment like // print Hello World inside the main method.
    public class Main {
        public static void main(String[] args) {
            // print Hello World
        }
    }
    
  • GitHub Copilot will automatically suggest code to complete or implement the comment.
  • Press Tab to accept the suggestion, or continue typing to refine it.
The more descriptive your comment or method signatures, the better Copilot can understand what you want to implement.

Copilot Chat

  • Click the Copilot Chat icon in the right-hand sidebar.
  • Ask something like: "Write a main method that calculates the factorial of N".
  • GitHub Copilot will generate a response in the chat window.
  • You can directly insert or copy code chunks using the buttons in the top right corner.
  • From left to right: Copy to clipboard, Insert at cursor.

Copilot Inline Chat

  • Go to the line or section where you want to ask Copilot for assistance.
    • Use the inline chat feature using the shortcut / Shift+Ctrl+I | Shift+Ctrl+G.
  • Type your request such as "Add a print log here" and press Enter.
  • You can insert the generated lines of code by hovering over the code block and clicking on Insert Code Block at Cursor.

Contributors: Norbert Loh (@NorbertLoh )