GitHub Copilot: Getting the Most from In-Editor AI
2 / 5GitHub Copilot is the most widely adopted AI coding tool. Many developers install it, find it acceptable, and stop there. This lesson is about unlocking significantly more value from it.
How Copilot Reads Your Context
- Copilot does not just see the current line. It reads:
- The current file (with particular attention to nearby code)
- Other open files in your editor (in some configurations)
- File names, function names, and variable names
- Comments in your code
This means context quality determines suggestion quality. You can significantly improve Copilot suggestions by improving your context.
Context-Improving Techniques
Write descriptive comments before coding Before writing a function, write a comment describing what it should do. Copilot uses this to generate more accurate implementations.
// Returns the total order value for a customer in a given date range.
// Excludes cancelled orders. Returns 0 if no orders found.
function getCustomerOrderTotal(customerId, startDate, endDate) {With this comment, Copilot has significantly more context than if you just wrote the function signature.
Use descriptive naming Copilot reads your names. A function called processData tells it very little. A function called calculateMonthlyRecurringRevenue tells it a great deal.
Keep related code open in tabs Copilot performs better when relevant files are open. If you are writing code that uses a specific data model, keep that model file open.
Copilot Chat: The Underused Feature
Many Copilot users ignore the chat interface. This is a mistake. Copilot Chat is available in VS Code via the sidebar and handles:
Explain this code Select a block of code and ask "explain what this does" — particularly useful for understanding legacy code or unfamiliar patterns.
Fix this error Paste an error message and ask Copilot to fix it. It often identifies the cause correctly.
Generate tests "Write unit tests for the selected function" — handles standard cases quickly.
Refactor this "Refactor this function to be more readable" or "extract this logic into a separate function" — useful for improving code structure.
Working with Copilot on Larger Tasks
For tasks that span multiple functions or files, break them into smaller sub-tasks and work through them sequentially:
- 1.Describe the overall goal in a comment
- 2.Ask Copilot to outline the functions you will need
- 3.Implement each function one at a time
- 4.Test as you go
This structured approach produces better results than asking Copilot to generate large amounts of code at once.
When to Turn Copilot Off
Copilot is always running in the background. There are times to pause it:
- When debugging a subtle issue (Copilot suggestions can distract your thinking)
- When writing security-sensitive code that requires full attention
- When you want to think through an algorithm yourself before seeing suggestions
The Tab key accepts; Escape dismisses. Developing the habit of critically evaluating before accepting is more important than any specific technique.