Skip to main content

Asking GitHub Copilot questions in your IDE

Use Copilot Chat in your editor to give code suggestions, explain code, generate unit tests, and suggest code fixes.

Prerequisites

  • Access to GitHub Copilot. See 什么是 GitHub Copilot?.

  • A compatible JetBrains IDE. GitHub Copilot is compatible with the following IDEs:

    • IntelliJ IDEA(旗舰版、社区版、教育版)
    • Android Studio
    • AppCode
    • CLion
    • Code With Me Guest
    • DataGrip
    • DataSpell
    • GoLand
    • JetBrains Client
    • MPS
    • PhpStorm
    • PyCharm(专业版、社区版、教育版)
    • Rider
    • RubyMine
    • RustRover
    • WebStorm
    • Writerside

    请参阅 JetBrains IDE 工具查找器进行下载。

  • GitHub Copilot**** 插件。 请参阅 JetBrains Marketplace 中的 GitHub Copilot 插件。 有关安装说明,请参阅“在环境中安装 GitHub Copilot 扩展”。

  • 在 JetBrains IDE 中登录到 GitHub。 有关身份验证说明,请参阅“在环境中安装 GitHub Copilot 扩展”。

如果可通过组织 访问 GitHub Copilot,则如果组织所有者 禁用了聊天,你将无法使用 GitHub Copilot Chat。 请参阅“管理组织中的 Copilot 策略”。

Submitting prompts

You can ask Copilot Chat to give code suggestions, explain code, generate unit tests, and suggest code fixes.

  1. Open the Copilot Chat window by clicking the Copilot Chat icon at the right side of the JetBrains IDE window.

    Screenshot of the Copilot Chat icon in the Activity Bar.

  2. Enter a prompt in the prompt box. For example prompts, see Copilot Chat 提示入门.

  3. Evaluate Copilot's response, and submit a follow up prompt if needed.

    The response often includes interactive elements. For example, the response may include buttons to copy or insert a code block.

    To see the files that Copilot Chat used to generate the response, select the References dropdown below the response.

Using keywords in your prompt

You can use special keywords to help Copilot understand your prompt.

Chat participants

Chat participants are like domain experts who have a specialty that they can help you with. You can use a chat participant to scope your prompt to a specific domain. To do this, type @ in the chat prompt box, followed by a chat participant name.

For a list of available chat participants, type @ in the chat prompt box. See also GitHub Copilot Chat 速查表.

Extending Copilot Chat

GitHub Copilot Extensions 将外部工具的强大功能集成到 Copilot Chat 中,帮助减少上下文切换并接收具有特定域上下文的响应。 可以从 GitHub Marketplace 安装 Copilot Extensions,或在组织中构建私有的 Copilot Extensions,然后在聊天窗口中键入 @ 即可查看可用扩展的列表。 若要使用扩展,请从列表中选择该扩展或键入完整的 slug 名称,然后键入提示。

若要了解详细信息,请参阅 使用扩展将外部工具与 Copilot Chat 集成

Slash commands

Use slash commands to avoid writing complex prompts for common scenarios. To use a slash command, type / in the chat prompt box, followed by a command.

To see all available slash commands, type / in the chat prompt box. See also GitHub Copilot Chat 速查表

File references

By default, Copilot Chat will reference the file that you have open or the code that you have selected. You can also tell Copilot Chat which files to reference by dragging a file into the chat prompt box. Alternatively, you can right click on a file, select GitHub Copilot, then select Reference File in Chat.

Using GitHub skills for Copilot

Copilot 的特定于 GitHub 的技能扩展了 Copilot 可提供的信息类型。 若要在 Copilot Chat 中访问这些技能,请在问题中包含 @github

向问题添加 @github 时,Copilot 会根据问题的内容动态选择适当的技能。 此外,还可以明确要求 Copilot Chat 使用某项特定技能。 可通过两种方式实现此目的:

  • 使用自然语言要求 Copilot Chat 使用技能。 例如: @github Search the web to find the latest GPT model from OpenAI.
  • 若要专门调用 Web 搜索,可以在问题中包含 #web 变量。 例如: @github #web What is the latest LTS of Node.js?

可以通过询问 Copilot 来生成当前可用的技能列表:@github What skills are available?

Additional ways to access Copilot Chat

  • Built-in requests. In addition to submitting prompts through the chat window, you can submit built-in requests by right clicking in a file, selecting GitHub Copilot, then selecting one of the options.
  • Inline. You can submit a chat prompt inline, and scope it to a highlighted code block or your current file.
    • To start an inline chat, right click on a code block or anywhere in your current file, hover over GitHub Copilot, then select Copilot: Inline Chat, or enter Ctrl+Shift+I.

Sharing feedback

To share feedback about Copilot Chat, you can use the share feedback link in JetBrains.

  1. At the right side of the JetBrains IDE window, click the Copilot Chat icon to open the Copilot Chat window.

    Screenshot of the Copilot Chat icon in the Activity Bar.

  2. At the top of the Copilot Chat window, click the share feedback link.

    Screenshot of the share feedback link in the Copilot Chat window.

Further reading