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

如果可通过组织 或企业 访问 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. In the Visual Studio menu bar, click View, then click GitHub Copilot Chat.

  2. In the Copilot Chat window, enter a prompt, then press Enter. 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, insert, or preview the result of a code block.

    To see the files that Copilot Chat used to generate the response, click the References link below the response. The references may include a link to a custom instructions file for your repository. This file contains additional information that is automatically added to all of your chat questions to improve the quality of the responses. For more information, see Adding repository custom instructions for GitHub Copilot.

Using keywords in your prompt

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

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 速查表 or Slash commands in the Visual Studio documentation.

References

By default, Copilot Chat will reference the file that you have open or the code that you have selected. You can also use # followed by a file name, file name and line numbers, or solution to reference a specific file, lines, or solution.

See also GitHub Copilot Chat 速查表 or Reference in the Visual Studio documentation.

Using GitHub skills for Copilot (preview)

Note

The @github chat participant is currently in preview, and only available in Visual Studio 2022 Preview 2 onwards.

Copilot's GitHub-specific skills expand the type of information Copilot can provide. To access these skills in Copilot Chat in Visual Studio, include @github in your question.

When you add @github to a question, Copilot dynamically selects an appropriate skill, based on the content of your question. You can also explicitly ask Copilot Chat to use a particular skill. For example, @github Search the web to find the latest GPT4 model from OpenAI.

You can generate a list of currently available skills by asking Copilot: @github What skills are available?

Asking a question about a knowledge base (preview)

Note

  • This feature is only available if you have a Copilot Enterprise subscription.
  • Support for knowledge bases is currently in preview, and only available in Visual Studio 2022 Preview 3 onwards.

Organization owners can create knowledge bases, grouping together Markdown documentation across one or more repositories. For more information, see 管理 Copilot 知识库.

You can tell Copilot to answer a question within the context of a knowledge base.

  1. At the bottom of the Copilot Chat window, in the Ask Copilot: Type / for commands and # to reference text box, type @github, press #, then select a knowledge base from the list.
  2. In the Type / for commands and # to reference text box, continue your message with your question, and then press Enter.
  3. Copilot Chat will process your question and provide an answer, with citations from your knowledge base, in the chat window.

AI models for Copilot Chat

你可以更改 Copilot 用来生成聊天提示响应的大型语言模型。 你可能会发现性能更好的不同模型,或提供更有用响应的模型,具体取决于你提出的问题类型。 有关详细信息,请参阅“正在更改 Copilot Chat 的 AI 模型”。

Additional ways to access Copilot Chat

In addition to submitting prompts through the chat window, you can submit prompts inline. To start an inline chat, right click in your editor window and select Ask Copilot.

See Ask questions in the inline chat view in the Visual Studio documentation for more details.

Sharing feedback

To share feedback about Copilot Chat, you can use the Send feedback button in Visual Studio. For more information on providing feedback for Visual Studio, see the Visual Studio Feedback documentation.

  1. In the top right corner of the Visual Studio window, click the Send feedback button.

    Screenshot of the share feedback button in Visual Studio.

  2. Choose the option that best describes your feedback.

    • To report a bug, click Report a problem.
    • To request a feature, click Suggest a feature.

Further reading