2025年8月31日日曜日

Using Chat in VS Code with GitHub Copilot

 

GitHub Copilot Chat in VS Code allows you to interact with your codebase using natural language. You can:

  • Ask questions about your code

  • Fix bugs

  • Add features

  • Optimize performance

  • Learn best practices


✅ Prerequisites


🚀 Chat Interfaces in VS Code

ExperienceShortcutBest For
Chat ViewCtrl+Alt+IOngoing multi-turn chats, multiple modes
Inline ChatCtrl+IIn-place edits or suggestions in files/terminal
Quick ChatCtrl+Shift+Alt+LFast, one-off questions

Access any of these via the Copilot icon or Command Palette.


🧰 Built-in Chat Modes

ModeDescription
AskAsk about your codebase, frameworks, or dev concepts
EditMake precise edits across multiple files based on natural language prompts
AgentAutonomously analyze, plan, and implement complex multi-file changes

✨ You can create custom chat modes for tasks like code review, documentation, etc.


🔄 Switch Models

  • In the chat input field, use the Model Picker dropdown to choose from available models.

  • Different models are better suited for different tasks (e.g., fast code gen vs. deeper reasoning).


🗨️ Submitting Prompts

Use natural language like:

  • 📖 “Explain how the login system works”

  • 🐞 “Fix the null reference in script.js

  • 🚀 “Create a new endpoint for updating user settings”

  • 🎨 “Style the submit button using #styles.css

  • 📘 “What’s the best way to handle async errors in Node?”


🧩 Add Context to Prompts

Use # to reference:

  • #codebase — entire project

  • #<filename> — specific file

  • #usages — show where a function is used

  • #problems — unresolved issues

  • #fetch <url> — web content (e.g. docs)

  • #githubRepo — search GitHub repos (e.g. #githubRepo microsoft/vscode)

Also use the "Add Context" button in the Chat View for visual selection.


🧪 Experimental Features

✏️ Edit Previous Prompts

  • Edit a previous chat message in place (via hover or inline).

  • Reverts changes made after that prompt.

  • Enable via chat.editRequests setting (inline, hover, input, none).

🔁 Checkpoints (Preview)

  • Restores workspace to a pre-prompt state.

  • Enable via chat.checkpoints.enabled

  • Use Restore Checkpoint or Redo to manage file changes.

  • Enable chat.checkpoints.showFileChanges to show which files were affected.


🖼️ Vision Support

  • Drag & drop images or screenshots into Chat View.

  • Example: ask “What does this diagram show?” or “Implement this UI sketch.”


🗃️ Chat History & Management

  • Use New Chat (+) to reset context

  • Use Show Chats... to view previous sessions

  • Export chat to JSON (Command Palette: Chat: Export Chat...)

  • Copy individual messages (Markdown format)


🪄 Open Chat in New Window or Tab

In the Chat View:

  • Click ... > Open Chat in Editor

  • Or ... > Open Chat in New Window

  • Enable Always on Top for floating windows


🎙️ Voice Interactions (Optional)

Install VS Code Speech extension:

  • Dictate prompts

  • Use “Hey Code” to start chats

  • Hold-to-speak mode for faster input


🔧 Developer Tools

  • Use Developer: Show Chat Debug View (from Command Palette) to inspect:

    • System/user prompts

    • Tools used

    • Response payloads


💻 Start Chat from the Command Line

code chat "Find and fix all untyped variables"

Options:

  • -m, --mode <ask|edit|agent|custom>: Set chat mode

  • -a, --add-file <path>: Add files as context

  • --maximize: Maximize view

  • -r, --reuse-window: Use current window

  • -n, --new-window: Open in new window

  • -: Pipe from stdin

Example:

cat app.js | code chat "Why does this fail?" -

🔐 Privacy & Transparency

  • Copilot may request additional permissions for private repos

  • All actions and chat content are managed securely

  • See GitHub Copilot Trust Center


🎓 More Learning Resources

0 件のコメント:

コメントを投稿