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.

Note

Xcode 中的 Copilot Chat 为 公共预览版,可能随时更改。

Prerequisites

To use GitHub Copilot for Xcode, you must install the GitHub Copilot for Xcode extension. See 在环境中安装 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. To open the chat view, click Copilot in the menu bar, then click Open Chat.

  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.

Using keywords in your prompt

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

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. For more information, see GitHub Copilot Chat 速查表.

File references

By default, Copilot Chat will reference the file that you have open or the code that you have selected. To attach a specific file as reference, click in the chat prompt box.

Chat management

You can open a conversation thread for each Xcode IDE to keep discussions organized across different contexts. You can also revisit previous conversations and reference past suggestions through the chat history.

Sharing feedback

To indicate whether a response was helpful, use or that appear next to the response.

Further reading