Using the right context helps Copilot understand what you're asking and where to look. You can add context implicitly (automatically) or explicitly using #-mentions
, @-mentions
, or instruction files.
✅ 1. Implicit Context (Automatic)
VS Code automatically includes context such as:
-
Selected text in the active editor
-
Current file or notebook name
-
The active file in Ask and Edit modes
-
Automatically determined relevant files in Agent mode
🏷️ 2. Use #
-Mentions to Add Context
Type #
in chat to bring up:
-
Files/folders/symbols
-
Tools
-
Context variables
🧾 Examples:
🔎 Available Context Tags:
Tag | Description |
---|---|
#codebase | Searches entire workspace |
#<file> | Adds a specific file (e.g. #app.js ) |
#<folder> | Includes a folder |
#<symbol> | Refers to a function/class (opened in editor) |
#changes | Includes current Git changes |
#problems | Includes unresolved workspace issues |
#testFailure | Adds test failures as context |
#fetch <url> | Fetches & references content from a webpage |
#githubRepo <repo> | Pulls code patterns from GitHub repos (e.g. #githubRepo vercel/next.js ) |
🖱️ You can also:
-
Drag & drop files into Chat view
-
Use Add Context → Files & Folders / Symbols
🌐 3. Reference Web Content with Tools
✅ #fetch <url>
Grab documentation or examples from the web:
✅ #githubRepo <user/repo>
Search code patterns in public GitHub repos:
🛠️ 4. Reference Tools
Tools can be part of extensions, MCP servers, or built-in.
Examples:
💡 You can create tool sets and reference them as a group.
🧑💼 5. Use @
-Mentions for Domain Experts
Mention a chat participant (domain expert assistant):
Mention | Description |
---|---|
@vscode | Help with VS Code settings/config |
@terminal | Ask about terminal commands and usage |
@workspace | Workspace-specific insights |
Examples:
🌍 6. Use the Simple Browser (Experimental)
-
Run your app locally
-
Open Simple Browser via Command Palette
-
Enable element selection (
chat.sendElementsToChat.enabled
) -
Click elements to add them as context
-
Optionally enable:
-
chat.sendElementsToChat.attachCSS
-
chat.sendElementsToChat.attachImages
-
Useful for: Debugging or inspecting live UI components.
🧠 7. Instruction Files (Custom AI Behavior)
Define coding preferences, formatting rules, or team standards in a .md
instruction file:
-
Avoid repeating the same prompts
-
Keep AI behavior consistent across projects
Learn more: Customize AI with instruction files
🧱 8. Workspace Indexing
Improves search and context relevance:
Index Type | Description |
---|---|
Remote | GitHub-hosted index (for large repos) |
Local | Stored on your machine, semantic search |
Basic | Fallback for simpler local searching |
Enable via settings or GitHub Copilot setup.
💬 9. Manage Chat History
-
Chat remembers the context from previous turns
-
Use follow-up prompts like:
“Now make that async”
“Add tests for this”
🔄 To start fresh:
-
Use New Chat (
Ctrl+N
) -
Clears history and resets context
💡 Tips
-
Enable
github.copilot.chat.codesearch.enabled
for better#codebase
results -
Type
/help
in chat for built-in instructions -
Right-click a file → “Add to Chat”
-
Use floating chat windows for multitasking
0 件のコメント:
コメントを投稿