11  VS Code and Copilot

12 VS Code and Copilot

VS Code is a code editor. GitHub Copilot is an AI assistant that lives inside it. Together they are the IDE harness for this book — the right tool for writing code, line by line, while you stay in charge.

12.1 What you will get from this chapter

  • VS Code installed and opening on your laptop.
  • A working Python setup inside VS Code.
  • Copilot active, with a sense of how to use it without letting it drive.

12.2 Install VS Code

Download the installer from code.visualstudio.com and run it. On macOS, drag the app into Applications. On Windows, accept the default install options; check the box that says Add to PATH. On Linux, your distribution probably has a .deb or .rpm package; the website will offer one.

Open VS Code once. Close any “welcome” tabs.

12.3 Add Python support

In VS Code’s left sidebar, click the Extensions icon (four squares). Search for Python. Install the one published by Microsoft — there are imitators; this is the one you want.

While you are there, install:

  • Pylance (usually bundles with the Python extension).
  • Jupyter if you plan to work with notebooks.

Open a Python file (or create one called test.py with print("hello")). VS Code asks you to pick an interpreter — point it at the virtual environment from Chapter 0d. Run the file with the play button in the top right. If hello prints in the terminal panel, you are set.

12.4 Add Copilot

Two extensions:

  • GitHub Copilot — the autocomplete that suggests the next few lines as you type.
  • GitHub Copilot Chat — a chat panel that can answer questions about the code in front of you.

Both ask you to sign in with GitHub. Do.

If you have a paid Copilot subscription (or claimed the free Student Developer Pack from Chapter 0c), Copilot will start working immediately. Without one, the free tier is limited but enough to taste it.

12.5 How to use Copilot well

The thing Copilot does most: as you type code, faded suggestions appear ahead of your cursor. Tab accepts; Esc dismisses; just keep typing to ignore.

Three small habits will save you grief.

1. Keep typing your intention before letting it complete. A clear half-line — # load the hotels CSV and parse the date column as datetime — gets you a much better completion than a bare df =.

2. Read what it suggests before you press Tab. The whole point of having an editor with AI in it is that you see the code. If you press Tab without reading, you have downgraded the harness to “chat with extra steps.”

3. Use Copilot Chat for “why” and “what’s wrong.” Open the chat panel (Ctrl/Cmd+Shift+I), select a chunk of code, and ask. “Why is this regression returning NaN coefficients?” Copilot Chat sees the file; it will look first.

12.6 A worked example

Imagine you have a CSV of EU air-quality readings and you want a daily mean by city. You type:

# load eea_air_quality_2023.csv and compute the daily mean of PM2.5 by city

Copilot suggests:

import pandas as pd

df = pd.read_csv("eea_air_quality_2023.csv", parse_dates=["timestamp"])
daily = (
    df.groupby([df["timestamp"].dt.date, "city"])["pm25"]
      .mean()
      .reset_index(name="pm25_daily")
)

You read it. The column name pm25 matches your file (you check). You press Tab. You run it. You print daily.head(). You confirm a city you already know about — Vienna, say — has plausible numbers. You move on.

That whole cycle, including the check, takes ninety seconds. By hand it takes ten minutes.

12.7 VS Code as a terminal

VS Code has a terminal pane built in (Ctrl/Cmd+`, the backtick). This means you can do everything from Chapter 0g — terminal basics inside VS Code, without alt-tabbing. Many readers stop opening a separate Terminal app once they discover this.

12.8 A note on alternatives

Cursor and Windsurf are independent editors built on VS Code’s open-source core, with deeper AI integration. Their autocomplete and chat features tend to be a step ahead of Copilot’s at any given moment, at the cost of being less stable and less universally supported. If you already use one, fine. The book does not assume them.

RStudio with the Copilot integration also works for the chapters that are language-agnostic. Where the chapter is Python-specific (most of them are), VS Code is the better fit.

12.9 Where AI helps · Where AI bluffs

Helps. Writing the boilerplate at the top of a script. Suggesting the next few lines of an obvious computation. Drafting tests for a function you just wrote. Explaining a chunk of unfamiliar code in plain language.

Bluffs. Suggesting code that looks right and uses a method that does not exist on the object you are calling it on. Inventing column names that match the spirit of your file but not the letter. Confidently completing a regression with the wrong sample restriction. The IDE harness is fast; that is the danger.

12.10 Keep this with you, not the AI

  • Whether to accept a suggestion. Read it first. Every time.
  • The shape of the code you want. Copilot fills in the lines; you decide the structure of the script.
  • What “done” looks like. Copilot will keep suggesting until you tell it to stop.

12.11 Try this

Open VS Code. Open a folder with one of your old scripts. Add a comment at the top of a function: # add a docstring. Watch what Copilot suggests. Edit it until it actually reflects what the function does. Save. Total time: five minutes. You have now used the IDE harness for real.

12.12 AI and me

  1. How did AI support me here?
  2. How did AI fail me?
  3. How did AI extend me?

12.13 Where to go next

Installing a CLI agent for the third harness — or jump to Part I if your first reading pass is going to live in chat and IDE only.