Copilot Chat

Copilot Chat is an interactive AI assistant that lets you have conversations about your code, get explanations, and receive help with programming tasks directly within VS Code. VS Code makes extensive use of audio cues and the accessible view to make chat accessible. I will list the signal sounds that you may hear.

Copilot Chat provides 3 modes: ask, edit, agent. Ask mode allows you to ask questions and get explanations about code. Edit mode helps you modify existing code with natural language instructions. With Agent Mode, you can have Copilot generate entire codebases across multiple files, run commands, and iterate on its work. We will cover chat and agent in this tutorial. Edit is very similar to agent and next edit suggestions so we will not be explicitly covering it.

You can access Copilot Chat by pressing Control+Alt+I or by opening the Command Palette (Control+Shift+P) and typing “Copilot Chat: Open Chat”. You can switch between ask, edit, and agent modes by pressing Control+.

Ask Mode

Ask mode is the most basic way to interact with Copilot Chat, where you can ask questions about programming concepts, get code explanations, or request help with specific coding problems.

You can ask Copilot Chat straightforward questions about programming concepts, syntax, or best practices. For example:

  • “What is a Python dictionary?”
  • “How do I create a for loop in Python?”
  • “What’s the difference between a list and a tuple?”
  • “How do I handle exceptions in Python?”

Copilot Chat will provide clear explanations with code examples.

Once you open the chat, your cursor will be placed in the edit field. You can type your question, and press Enter to submit it. Similar to other chat applications, you can press Shift+Enter to insert a new line in the chat box. I highly encourage you to go through the accessibility help for the chat edit field.

Once you submit the question, you will hear the “chat request sent” audio signal and announcement. Copilot indicates that it is processing the question by playing the “progress” audio signal and announcement. Once Copilot has a response, it will indicate this by playing the “chat response received” audio signal and announcement. The screen reader starts reading the response. You can listen to these audio cues using the media controls below. You can explore the chat response by pressing Alt+F2.

Chat request sent signal indicating that the message has been sent.
Chat Response received signal indicating that copilot has responded.
Progress signal indicating that Copilot is working on your request.

Try it Yourself

  1. Open VS Code and press Control+Alt+I to open Copilot Chat.
  2. Ask a simple question: “What is the difference between == and is in Python?”
  3. Read through the response using your screen reader.

Practice: Working with Copilot Chat

  1. Open the read_exampleCode.py file from our previous lesson.
  2. Select the NumberProcessor class definition.
  3. In Copilot Chat, type: “Explain what this class does and how it works.”
  4. Compare the explanation to your own understanding of the code.

Providing Context

You can provide the model context using the @ (at the rate) symbol.

When you type @ in the chat box, VS Code will show you a list of available context options that you can reference. Common context options include:

  • @workspace: Provides information about your entire workspace and project structure
  • @terminal: References recent terminal output or commands
  • @vscode: Ask questions about VS Code features, settings, and APIs
  • @github: Ask questions about GitHub repositories, issues, and pull requests

For example, you can type “@workspace how is authentication implemented?” to get information about your project, or “@terminal list the 5 largest files in this workspace” to get help with terminal commands.

You can also instruct chat to execute specific commands like fetching information from a link, generating documentation for your code, or creating unit tests using the # (number) key.

When you type # in the chat box, VS Code will show you a list of available commands and tools. Some useful examples include:

  • #selection: Add the current editor selection as context to your prompt
  • #file: Add a specific file as context (e.g., #file:mycode.py)
  • #problems: Add workspace issues and problems from the Problems panel as context
  • #changes: Add the current source control changes as context
  • #codebase: Perform a code search in the current workspace to find relevant context
  • #extensions: Find and ask questions about VS Code extensions

You can also use slash commands for specific tasks:

  • /explain: Explain a code block, file, or programming concept
  • /fix: Ask Copilot to fix code or resolve compiler/linting errors
  • /tests: Generate tests for selected methods and functions
  • /docs: Generate code documentation comments
  • /new: Scaffold a new VS Code workspace or file

For example, you can type “#selection /explain” to get a detailed explanation of your selected code, or “/tests #file:calculator.py” to generate tests for a specific file.

Practice: Context and Commands Practice

Using the read_exampleCode.py file from our previous lesson, complete the following tasks to practice using Copilot Chat with different context providers and commands:

  1. Using # context variables:
    • Open the read_exampleCode.py file
    • Select the deep_check method in the NumberValidator class
    • In Copilot Chat, type: “#selection /explain”
    • Record what Copilot explains about this method
  2. Using @ context providers:
    • In Copilot Chat, type: “@workspace what are the main classes in this project?”
    • Compare Copilot’s response to your own understanding of the project structure
  3. Using # file context:
    • In Copilot Chat, type: “#file:read_exampleCode.py /fix”
    • What bugs or issues does Copilot identify?
    • Did it find the Python 2 syntax error we discussed?
  4. Combining context and commands:
    • Select the entire main() function
    • Type: “#selection what is wrong with this function design?”
    • Reflect on whether Copilot identifies any design flaws we discussed