尝试以扩展 VS Code 中的代理模式!

在 VS Code 中设置 GitHub Copilot

本指南将引导你在 Visual Studio Code 中设置 GitHub Copilot。要在 VS Code 中使用 Copilot,你需要通过 GitHub 账户获取 GitHub Copilot 的访问权限。

提示

如果你还没有 Copilot 订阅,可以通过注册 Copilot 免费计划 来免费使用 Copilot,并获得每月限额的代码补全和聊天交互次数。

获取 GitHub Copilot 访问权限

获取 GitHub Copilot 访问权限有多种方式

用户类型 描述
个人用户
组织/企业成员

在 VS Code 中设置 Copilot

要在 VS Code 中使用 Copilot,你需要拥有 GitHub Copilot 订阅的访问权限。

在 VS Code 中设置 Copilot

  1. 将鼠标悬停在状态栏中的 Copilot 图标上,然后选择 设置 Copilot

    Hover over the Copilot icon in the Status Bar and select Set up Copilot.

  2. 选择登录以登录你的 GitHub 账户,如果你已登录,则选择使用 Copilot

    Sign in to your GitHub account or use Copilot if you're already signed in.

    如果你还没有 Copilot 订阅,将为你注册 Copilot 免费计划

    重要

    你的 GitHub Copilot 免费版本中的遥测功能目前已启用。默认情况下,允许与公共代码匹配的代码建议,包括 VS Code 和 <github.com> 体验中的代码引用。你可以通过在 VS Code 中将遥测功能设置为 off 来禁用遥测数据收集,方法是设置 telemetry.telemetryLevel,或者你可以在Copilot 设置中调整遥测和代码建议设置。

  3. 你现在可以在 VS Code 中开始使用 Copilot。通过Copilot 快速入门了解基本功能。

使用其他 GitHub 账户登录 Copilot

如果你的 Copilot 订阅与另一个 GitHub 账户相关联,请在 VS Code 中登出你的 GitHub 账户,然后用另一个账户登录。

  1. 在活动栏中选择账户菜单,然后选择登出你当前用于 Copilot 的账户。

    Accounts menu in VS Code, showing the option to sign out of the current GitHub account.

  2. 使用以下任一方法登录你的 GitHub 账户

    • 从 Copilot 状态菜单中选择登录以使用 Copilot

      Sign in to use Copilot from the Copilot status menu.

    • 在活动栏中选择账户菜单,然后选择使用 GitHub 登录以使用 GitHub Copilot

      Accounts menu in VS Code, showing the option to sign in with GitHub to use GitHub Copilot.

    • 在命令面板中运行GitHub Copilot: 登录命令 (⇧⌘P (Windows, Linux Ctrl+Shift+P))。

在 VS Code 中隐藏 Copilot

要在 VS Code 中完全隐藏 Copilot,请从 VS Code 标题栏中的 Copilot 菜单中选择隐藏 Copilot

Screenshot that shows the Copilot menu in the VS Code title bar, with the option to hide Copilot.

要重新启用 Copilot,请在命令面板中运行聊天:免费使用 Copilot 的 AI 功能命令 (⇧⌘P (Windows, Linux Ctrl+Shift+P))。

为工作区禁用 Copilot

为特定工作区禁用 Copilot

  1. 在 VS Code 中打开扩展视图 (⇧⌘X (Windows, Linux Ctrl+Shift+X))。
  2. 搜索 GitHub Copilot 扩展。
  3. 选择齿轮图标,然后选择禁用 (工作区)

Screenshot that shows the GitHub Copilot extension in the Extensions view, with the option to disable it for the workspace.

后续步骤