HOW-TO · DEV
How to use GitHub Copilot Chat for debugging and explaining code in VS Code
Target environment
Ubuntu 24.04 · VS Code 1.98
PREREQUISITES
GitHub Copilot Chat extension installed
What this does
GitHub Copilot Chat brings a conversational interface directly into VS Code. It can parse the active file, selected code blocks, or error messages to provide explanations, suggest fixes, and walk through debugging steps. The chat panel retains conversation history within a session, enabling multi-turn investigations of complex bugs.
Steps
- Open the Copilot Chat panel by clicking the chat icon in the Activity Bar or using the command Copilot Chat: Open Chat.
- Select a code block in the editor, right-click, and choose Ask Copilot to send the selection directly into the chat input.
- Type a debugging question such as "Why is this function returning undefined?" and press
Enter. - Read the response; if a code fix is included, click Insert at Cursor or Apply Suggestion to place it into the active file.
- For exception analysis, paste the full stack trace into the chat and ask Copilot to trace the error origin.
- Use slash commands:
/explainto get a line-by-line breakdown of the selected code, or/fixto receive a proposed patch. - Review the proposed fix in the diff view before accepting it with Accept.
- Re-run the application or tests to confirm the issue is resolved, then ask a follow-up question in the same chat thread if needed.
Verification
code --command workbench.view.extension.copilotChat
Expected output: the Copilot Chat view becomes focused and the panel is visible in the sidebar.
Common failures
- No response from Copilot: Check network connectivity; Copilot Chat requires an active connection to GitHub's backend.
- Selection not sent: Ensure the text is highlighted before invoking Ask Copilot, otherwise the prompt sends with no context.
- Outdated context: Use the Reset Chat button to clear history when the conversation strays from the original issue.