在 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 图标上,然后选择 Set up Copilot

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

  2. 选择 Sign in 以登录到你的 GitHub 帐户,如果你已登录,则选择 Use 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 中禁用遥测来选择退出遥测数据收集,方法是将 telemetry.telemetryLevel 设置为 off,或者你可以在 Copilot 设置中调整遥测和代码建议设置。

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

将 Copilot 与其他 GitHub 帐户一起使用

如果你的 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: Sign in 命令 (⇧⌘P (Windows、Linux Ctrl+Shift+P))。

后续步骤