Copilot Chat

Chat 是「对着仓库说话」的入口:解释代码、写测试、修诊断、起草补丁。官方:Getting started with prompts for Copilot Chat in your IDEPrompt engineering for Copilot Chat

补全加速「你已经知道要写的那一行」;Chat 适合「先问清楚再改」。组织管理员可以关掉 Chat——扩展仍可能给出行内建议。


打开方式

侧栏 Chat(VS Code)

系统快捷键
Windows / LinuxCtrl+Alt+I
macOSControl+Command+I

也可用标题栏 Copilot / Chat 图标。输入框上方通常能切换模式(名称随版本变,常见为 Ask / Edit / Agent):

  • Ask:问答,默认不主动改一堆文件
  • Edit:按你的指令改指定范围
  • Agent:多步骤、可跑命令、动多个文件——见 Coding Agent

行内 Chat(inline chat)
在编辑器里对选区提问,默认常为 Windows Ctrl+I、macOS Cmd+I。若与其他扩展冲突,在 Keyboard Shortcuts 里搜 inline chat。行内适合「只动这一段」;仓库级问题用侧栏 + @workspace

JetBrains:用 Copilot Chat 工具窗;仓库级参与者是 @project,不是 @workspace


把仓库放进上下文

模型看不到「你脑子里的整个 Git 历史」,只看你提供的上下文。官方策略:

手法作用
选中代码当前选区进入提示
打开相关文件当前编辑器作为默认上下文
#file / #selection / #editor / #codebase / #git聊天变量,显式引用
@workspace(VS Code / Visual Studio)按工作区结构回答「项目里怎么调度通知」这类问题
@project(JetBrains)同上,换了参与者名字
@vscode问 VS Code 本身(调试、快捷键、主题)
@terminal问命令行;#terminalLastCommand 解释上一条命令

示例:

@workspace How are notifications scheduled? Cite files. Do not invent a queue if none exists.
#file:app.js #file:routes.js How are these files related?

新任务开 新线程,删掉已经过时的回合,避免历史把模型带偏。


斜杠命令(常用)

以 VS Code 为准,输入 / 看当前列表:

命令典型用途
/explain解释选区或当前文件
/fix针对当前文件里的错误提出修复
/tests为已有代码写测试(可指定框架)
/new建议新项目结构(还可预览后创建文件)
/newNotebook建议 Jupyter notebook

/tests 是「给现有代码补测试」。若你要 TDD,直接说 Add tests for a function that sums integers,不要先 /tests

安全产品(code scanning、secret scanning、Dependabot)相关问题可以在有权限的仓库里问,例如 How would I fix this alert?——以官方 Chat 文档中 Advanced Security 一节为准。


好问题长什么样

有效:

@workspace List install, test, and lint commands from package.json / Makefile / pyproject.toml.
Quote the script names. Do not invent npm scripts.
/tests using the project's existing test runner. Do not add a new framework.

低效: 「优化一下」——没有文件、没有成功标准、没有禁止事项。

Chat 返回代码块时,用官方提供的 复制 / 插入到光标 / 新文件 / 终端 按钮。插入后跑测试,不要只看「看起来像对的」。

提示词写法见官方 Prompt engineering 页:指明相关代码、控制对话历史、一次一件事。


github.com 上的 Chat

不必开 IDE:打开仓库里的文件或 PR,点右上角 Copilot 图标,问 Explain this file.Summarize this pull request。详见 GitHub 集成

Windows Terminal Canary 里有实验性 Terminal Chat,需在设置里选 GitHub Copilot 并认证。稳定版 Windows Terminal 不要假设有同样入口。macOS 用户用 IDE Chat 或 CLI


隐私与范围

  • 不要把密钥、客户数据、未公开的安全细节贴进 Chat。
  • 用组织的 content exclusion 挡住密钥文件、生成物、大型数据目录。
  • Free 套餐的 Chat 次数有限,以计划页为准。

下一步

评论