Sub topic 1
What Copilot does in VS Code
GitHub Copilot is an AI coding assistant that runs inside Visual Studio Code. This chapter describes what it can do and how its features fit together. Later chapters cover installing it, signing in, and configuring it.
Prerequisites
This chapter assumes you have:
- Basic use of Visual Studio Code, such as opening folders, using the Extensions view, and running commands from the Command Palette.
- A GitHub account.
- Familiarity with editing code in at least one programming language.
You don't need to install anything yet to follow along.
The two main features
Copilot adds two kinds of help to the editor.
- Inline suggestions appear as faded "ghost text" while you type. Copilot predicts the next few characters, a line, or a whole block of code. You accept the suggestion or ignore it.
- Copilot Chat is a conversation with a language model. You ask questions, request changes, and get explanations in plain language.
Both features read context from your editor, such as the current file and the code around your cursor. The quality of the answer depends largely on how much useful context Copilot has.
Inline suggestions
Inline suggestions work best when you describe your intent in code. A descriptive comment and a function signature are often enough:
# Return the n-th Fibonacci number using iteration
def fibonacci(n):After you type this, Copilot may propose a function body as ghost text. Press Tab to accept it. Keep typing to ignore it, or press Esc to dismiss it. You will practice these controls in a later chapter.
Chat and its entry points
Chat is available in several places, and each suits a different task.
| Entry point | What it is for |
|---|---|
| Chat view | Longer conversations, questions about your project, multi-step requests |
| Inline chat | A quick request about the code at your cursor or your selection |
| Chat modes | Ask for questions, Edit for changes you direct, Agent for multi-step tasks |
Chat requests can point at specific context. For example, the #file reference attaches a file to your question:
Explain what #file:utils.ts does and suggest one way to simplify it.Copilot then bases its answer on the contents of that file instead of guessing.
Shaping Copilot's behavior
You have two ways to control what Copilot does.
Instructions tell chat about your project. A file at .github/copilot-instructions.md holds conventions that Copilot follows without you repeating them in each prompt:
# Copilot instructions
- Use TypeScript with strict typing; avoid `any`.
- Write unit tests with Vitest.
- Prefer named exports over default exports.Settings control where Copilot is active. This settings.json fragment keeps inline suggestions on for most languages but turns them off for plaintext and Markdown:
{
"github.copilot.enable": {
"*": true,
"plaintext": false,
"markdown": false
}
}How the pieces connect
The diagram shows the order in which this tutorial builds up the setup. Account access comes first, and the features depend on being signed in.
Things to keep in mind
Check your understanding
Exercise
Name the two main kinds of help Copilot adds to VS Code, and give one way each gets context from your work.
Show answer
Inline suggestions and Copilot Chat. Inline suggestions use the current file and the code around your cursor, including comments and signatures you type. Chat uses the editor context plus anything you attach, such as a file with #file, and project instructions in .github/copilot-instructions.md.
Exercise
You want Copilot to stop suggesting code in Markdown files but keep suggesting it elsewhere. Which setting do you change?
Show answer
In settings.json, set "github.copilot.enable" with "*": true and "markdown": false.