GitHub Copilot needs context to provide relevant suggestions. The more effectively you provide it, the better the results. Here are key methods:
Copilot heavily relies on the code in your currently active file, especially the code surrounding your cursor.
#selection
in the chat view.In the Copilot Chat view (Ctrl+Alt+I / Cmd+Alt+I), explicitly reference context using #
:
#selection
: Refers to the code currently selected in the active editor.#file
: Refers to the entire content of the active file in the editor.#file:path/to/some/file.ext
: Refers to a specific file within your workspace (start typing after #file:
for suggestions).Example Prompt using #:
Explain the logic in #selection within the context of #file:utils/helpers.py
Engage specialized "participants" using @
in the Chat view for broader context:
@workspace
(VS Code) / @project
(JetBrains): Allows Copilot to search across your entire workspace/project to find relevant context based on your prompt. This is powerful for questions about how different parts of the code interact.Example Prompt using @:
@workspace How is user authentication implemented in this project?
Don't assume Copilot knows the specific technology unless it's obvious from the current file. Explicitly mention it in your prompt.
Example Prompt:
Generate a React component using functional syntax and hooks to...
How do I configure CORS in this Express app? Referencing #file:server.js
Combine clear natural language with explicit context using code selection, #
variables, and @
participants in Copilot Chat to guide the AI towards the most helpful and relevant responses.