Exercise - Set up GitHub Copilot to work with Visual Studio Code

Completed

Open the existing React portfolio in a browser codespace. Before you edit it, check that Copilot can suggest JavaScript and that you can see the portfolio home page.

Check your account access

Check that your GitHub account gives you access to both services:

  • Codespaces: Sign in to GitHub with an account that can create a codespace on the MicrosoftDocs sample repository. If you have read-only access, you need permission to fork it, but you don't need to make a fork first. An Enterprise Managed User account can't create a codespace on this repository if MicrosoftDocs is outside your organization. A Copilot seat doesn't change that restriction.
  • Copilot: The same GitHub account needs access to both inline completions and Copilot Chat in VS Code. If your organization or enterprise provides your seat, it must allow Chat in the IDE. If you're eligible and don't have an individual plan or an assigned seat, you can activate Copilot Free without starting a Pro trial or entering a payment card.

Copilot Free includes up to 2,000 inline completions per month. Inline completions don't use GitHub AI Credits. On Free, Copilot Chat selects the model automatically and uses a monthly AI credit allowance, not a fixed number of messages. Copilot Pro includes unlimited inline completions. On usage-based Pro plans, Chat uses GitHub AI Credits.

Verified students can activate Copilot Student through GitHub Education. Verified teachers and qualifying maintainers of popular open-source projects may be eligible for Copilot Pro at no cost.

Open the sample in a codespace

The sample configuration requests at least four cores. One hour on a running four-core machine uses four core-hours. With all 120 monthly core-hours available on a personal GitHub Free account, you get up to 30 running hours at four cores. Other Codespaces billed to your account share that allowance, and larger machines use it faster. This Codespaces allowance is separate from Copilot Free. Organization and enterprise plans don't include a free Codespaces quota.

To stay within your personal account's included usage, check both compute and storage. They're metered separately. If either allowance runs out and paid usage isn't enabled, you can't create or reopen a codespace billed to you until the allowance resets. If paid usage is enabled, additional use can incur charges.

If you can't reopen a codespace with edits you want to keep, export the changes without launching it while it still exists. Only the currently checked-out branch is exported. With read-only access to the sample, the export creates a branch in your fork. Verify your edited files on that branch on GitHub before relying on the copy.

If you already have a codespace for this sample, find it on Your Codespaces. Its name opens your default editor. To open it in your browser, select … > Open in and choose the browser option. Continue to Check a JavaScript inline suggestion.

If you don't have a codespace for this exercise yet, create one:

  1. Select Open in GitHub Codespaces.

    Illustration of the Open in GitHub Codespaces button for the JavaScript portfolio.

  2. Confirm the repository is MicrosoftDocs/mslearn-copilot-codespaces-javascript, review the machine type, and create the codespace. This opens a working copy of the sample; it doesn't create a new repository.

  3. Wait for the codespace to open. Startup can take a few minutes. If it opens outside the browser, use Open in on Your codespaces to switch to the browser. Use this same codespace for the rest of the module.

Check a JavaScript inline suggestion

The desktop version of VS Code includes the built-in GitHub Copilot Chat extension for both Chat and inline suggestions. You don't need to install VS Code or an extension on your computer for this exercise. Test inline suggestions in the preconfigured browser editor:

  1. Select File > New Text File. With the untitled file active, select the language mode in the status bar (usually Plain Text) and choose JavaScript.
  2. Open the Copilot menu in the status bar. Sign in with the GitHub account that has your Copilot access if prompted. Make sure inline suggestions are enabled for JavaScript.
  3. Type const gitHub = "microsoft"; on the first line and // Build the GitHub profile URL from the gitHub username. on the next. Press Enter and pause. Look for dimmed code that uses gitHub to build https://github.com/microsoft. The exact suggestion can vary.
  4. If nothing appears, open View > Command Palette and run Trigger Inline Suggestion. If it still doesn't appear, confirm that you're signed in with the intended GitHub account. Open the Copilot status dashboard from the status bar. Check that suggestions are enabled for JavaScript and look at the inline usage shown for your plan before trying again.
  5. Press Esc to dismiss the suggestion, then close the untitled file without saving.

This checks inline suggestions, not Chat. You'll try your first Chat prompt when you edit the portfolio profile.

Note

If Chat reports a policy or usage limit, read the message. On a credit-based plan, check AI credit usage in the Copilot status dashboard, not the inline count. With a managed seat, ask your administrator about the IDE Chat policy and organization usage limits; you might not have a personal credit balance. Creating a new codespace doesn't change your Copilot access.

Check the portfolio preview

If the portfolio home page already loads, leave Parcel running and go straight to Ports below. The preview inside the editor is enough for this first check. If the page doesn't load, check the startup messages:

  1. Let setup finish installing the dependencies. For a container or installation failure, check the creation log: select View logs during creation if offered, or run Codespaces: View Creation Log from the Command Palette once connected. If the container works but installation failed, resolve the reported error, then retry npm install from the repository root.
  2. After VS Code connects, look in Terminal for the session that runs npm start. If it's visible, check for Parcel's listening address or a startup error. If you only see an empty terminal, check the preview from Ports before starting another server. The first server might still be running.
  3. If Parcel is listening but reports an application build error, leave it running and fix the reported error. If setup succeeded but no Parcel server is running, resolve any startup error, then run npm start once from the repository root.

In Ports next to the terminal, find the port Parcel reports. The sample labels port 1234 as Application. If Parcel reports a different number, use that port even if it has no label. If the port isn't listed, select Add port and enter the reported number. Keep the forwarded port Private.

Right-click that port and select Open in Browser. Confirm that the portfolio home page loads. Use this tab instead of the embedded preview for the link and motion checks in the portfolio exercise.