Guiding Copilot with context

Software Development with GitHub Copilot

Thalia Barrera

AI Engineering Curriculum Manager, DataCamp

The importance of context

Software Development with GitHub Copilot

The importance of context

Software Development with GitHub Copilot
Software Development with GitHub Copilot

The #codebase variable

$$

#codebase: Performs semantic code search across an entire project

Example prompt:

How is user authentication handled? #codebase

Result:

  • 🔍 Scans entire codebase
  • 💻 Includes relevant logic, function calls, or config settings in its answer
Software Development with GitHub Copilot

How Copilot understands your codebase

Index types:

  • Local index: Stored on your machine
  • Remote index: For repositories hosted on GitHub
Software Development with GitHub Copilot

Checking your index type

Software Development with GitHub Copilot

Checking your index type

Software Development with GitHub Copilot

The #changes variable

$$

#changes: References most recent source control changes

Example prompt:

Will any of these changes break the login flow? #changes

Use when:

  • 💾 Evaluating code modifications
Software Development with GitHub Copilot

The #selection variable

$$

#selection: References highlighted blocks of code

Example prompt:

Can you refactor this? #selection

Use when:

  • 🔧 Making quick edits
  • 📝 Creating targeted prompts
Software Development with GitHub Copilot

The #fetch variable

  • Documentation 📚, API reference 💻, blog post 📰

$$

#fetch: Pulls the contents of a web page

Example prompt:

Summarize this documentation for me #fetch example.com/docs

Result:

  • 🌐 Fetches a web page and uses it for context
Software Development with GitHub Copilot

The #files variable

$$

#files: Attaches specific files to a prompt

Example prompt:

Can you check this file for error handling issues? #files:utils/data_loader.py

Result:

  • 🔍 Analyzes the contents of the referenced file
  • 📄 Includes it as part of the prompt context
Software Development with GitHub Copilot

Other chat variables and tools

$$

Variable/tool Description
#search Enable searching for files in the current workspace.
#testFailure Get unit test failure information. Useful when running and diagnosing tests.
#problems Add workspace issues and problems from the Problems panel as context. Useful while fixing code or debugging.
#terminalLastCommand Get the last run terminal command and its output.
#githubRepo Perform a code search in a GitHub repo.
1 https://code.visualstudio.com/docs/copilot/reference/copilot-vscode-features#_chat-tools
Software Development with GitHub Copilot
Software Development with GitHub Copilot

Building a progressive chat interaction

Single, complex prompt:

Add PostgreSQL integration with authentication, persistence, sessions, error handling, and connection pooling

Progressive complexity flow:

  1. What's the best approach for adding database persistence? #codebase
  2. Implement the database connection using the suggested approach
  3. Help me with the schema design for the Task and the User classes
  4. Now add session management and basic error handling
  5. ...
Software Development with GitHub Copilot

Starting a new chat to clear context

Software Development with GitHub Copilot

Starting a new chat to clear context

Software Development with GitHub Copilot

Software Development with GitHub Copilot

Let's practice!

Software Development with GitHub Copilot

Preparing Video For Download...