在 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> 体验中的代码引用。您可以通过将telemetry.telemetryLevel设置为off来禁用 VS Code 中的遥测数据收集,或者您可以在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.

后续步骤