參加你附近的 ,瞭解 VS Code 中的 AI 輔助開發。

在 VS Code 中設定 GitHub Copilot

本指南將引導您在 Visual Studio Code 中設定 GitHub Copilot。要在 VS Code 中使用 Copilot,您需要擁有一個可訪問 GitHub Copilot 的 GitHub 帳戶。

提示

如果你還沒有 Copilot 訂閱,可以透過註冊 Copilot 免費計劃 免費使用 Copilot,並獲得每月限量的補全和聊天互動次數。

獲取 GitHub Copilot 訪問許可權

有多種方式可以獲取 GitHub Copilot 的訪問許可權

使用者型別 描述
個人
組織/企業成員

在 VS Code 中設定 Copilot

要在 VS Code 中使用 Copilot,您需要擁有 GitHub Copilot 訂閱的訪問許可權。您可以直接在 VS Code 內部設定 Copilot。

  1. 將滑鼠懸停在狀態列中的 Copilot 圖示上,然後選擇設定 Copilot (Set up Copilot)

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

  2. 選擇一種登入方法並按照提示操作。如果您還沒有 Copilot 訂閱,您將被註冊到 Copilot 免費版方案 (Copilot Free plan)

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

    重要

    您免費版 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. 在活動欄中選擇帳戶 (Accounts) 選單,然後為您當前登入的帳戶選擇登出 (Sign out)

    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)

      Sign in to use Copilot from the Copilot status menu.

    • 在活動欄中選擇帳戶 (Accounts) 選單,然後選擇使用 GitHub 登入以使用 GitHub Copilot (Sign in with GitHub to use GitHub Copilot)

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

    • 在命令面板 (⇧⌘P (Windows, Linux Ctrl+Shift+P)) 中執行 GitHub Copilot: Sign in 命令。

從 VS Code 中移除 AI 功能

您可以使用 chat.disableAIFeatures 設定在 VS Code 中停用內建的 AI 功能,這與您在 VS Code 中配置其他功能的方式類似。這將停用並隱藏 VS Code 中的聊天或內聯建議等功能,並停用 Copilot 擴充套件。您可以在工作區或使用者級別配置此設定。

或者,從標題欄的聊天選單中使用瞭解如何隱藏 AI 功能操作來訪問此設定。

注意

如果您之前已停用內建 AI 功能,在更新到新版本的 VS Code 時,您的選擇將得到尊重。

為工作區停用 AI 功能

要為特定工作區停用 AI 功能,請在工作區設定中配置 chat.disableAIFeatures 設定。此設定可在設定編輯器 (⌘, (Windows, Linux Ctrl+,)) 中找到,或者您可以在工作區的 settings.json 檔案中進行編輯。

後續步驟