尝试以扩展 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 中的 telemetry.telemetryLevel 设置为 off 来选择退出遥测数据收集,或者您可以在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: Sign in 命令 (⇧⌘P (Windows, Linux Ctrl+Shift+P))。

从 VS Code 中移除 AI 功能

要完全隐藏 VS Code 中的 AI 功能,请从命令面板(⇧⌘P (Windows, Linux Ctrl+Shift+P))运行 Chat: Hide AI Features 命令,或从 VS Code 标题栏的 Copilot 菜单中选择隐藏 AI 功能

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

要重新启用 Copilot,请在命令面板(⇧⌘P (Windows, Linux Ctrl+Shift+P))中运行 Chat: Use AI Features with Copilot for Free 命令。

为工作区禁用 Copilot

要为特定工作区禁用 Copilot

  1. 在 VS Code 中打开扩展视图(⇧⌘X (Windows, Linux Ctrl+Shift+X))。
  2. 搜索 GitHub Copilot 扩展。
  3. 选择齿轮图标,然后选择禁用(工作区)
  4. 选择重启扩展
  5. 您可以在之后通过选择重启扩展后出现的启用(工作区)按钮来重新启用它。

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

后续步骤