{"meta":{"title":"在 IDE 中使用 GitHub Copilot 聊天提示语入门","intro":"大致了解在 IDE 中使用的 Copilot Chat 方法。","product":"GitHub Copilot","breadcrumbs":[{"href":"/zh/copilot","title":"GitHub Copilot"},{"href":"/zh/copilot/how-tos","title":"操作方法"},{"href":"/zh/copilot/how-tos/chat-with-copilot","title":"与Copilot聊天"},{"href":"/zh/copilot/how-tos/chat-with-copilot/get-started-with-chat-in-your-ide","title":"IDE 中的聊天入门"}],"documentType":"article"},"body":"# 在 IDE 中使用 GitHub Copilot 聊天提示语入门\n\n大致了解在 IDE 中使用的 Copilot Chat 方法。\n\n您可以询问有关您项目的特定问题或一般软件问题。 还可以要求 Copilot Chat 编写代码、修复错误、编写测试和文档代码。\n\n使用上面的选项卡选择正在使用 Copilot Chat的环境。\n\n<div class=\"ghd-tool vscode\">\n\n<a href=\"vscode://GitHub.Copilot-Chat?ref_product=copilot&ref_type=engagement&ref_style=button\" target=\"_blank\" class=\"btn btn-primary mt-3 mr-3 mb-3 no-underline\">\n<span>打开 Copilot Chat（在 Visual Studio Code</span><svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-link-external\" aria-label=\"link external icon\" role=\"img\"><path d=\"M3.75 2h3.5a.75.75 0 0 1 0 1.5h-3.5a.25.25 0 0 0-.25.25v8.5c0 .138.112.25.25.25h8.5a.25.25 0 0 0 .25-.25v-3.5a.75.75 0 0 1 1.5 0v3.5A1.75 1.75 0 0 1 12.25 14h-8.5A1.75 1.75 0 0 1 2 12.25v-8.5C2 2.784 2.784 2 3.75 2Zm6.854-1h4.146a.25.25 0 0 1 .25.25v4.146a.25.25 0 0 1-.427.177L13.03 4.03 9.28 7.78a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042l3.75-3.75-1.543-1.543A.25.25 0 0 1 10.604 1Z\"></path></svg> 中）\n</a>\n\n以下示例提示中的一些提示使用聊天参与者（前面有 `@`）、斜杠命令（前面有 `/`）或聊天变量（前面有 `#`）。 有关提示中关键字的详细信息，请参阅“[在 IDE 中向 GitHub Copilot 提问问题](/zh/copilot/how-tos/chat-with-copilot/chat-in-ide#using-keywords-in-your-prompt)”。\n\n## 询问常见软件问题\n\n你可以向 Copilot Chat 询问一般软件问题。 例如：\n\n* `tell me about nodejs web server frameworks`\n* `how can I create an Express app`\n* `@terminal how to update an npm package`\n\n## 询问有关您项目的问题\n\n你可以向 Copilot Chat 询问项目相关问题。\n\n* `what sorting algorithm does this function use`\n* `@workspace how are notifications scheduled`\n* `#file:gameReducer.js #file:gameInit.js how are these files related`\n\n若要提供 Copilot 正确的上下文，请尝试以下一些策略：\n\n* 突出显示相关代码行。\n* 使用聊天变量，例如 `#selection`、`#file`、`#editor`、`#codebase` 或 `#git`。\n* 使用 `@workspace` 聊天参与者。\n\n## 编写代码\n\n你可以要求 Copilot 为你编写代码。 例如：\n\n* `write a function to sum all numbers in a list`\n* `add error handling to this function`\n* `@workspace add form validation, similar to the newsletter page`\n\n当 Copilot 返回代码块时，响应中包含用于将代码复制到或将代码插入到光标位置、新文件或终端中的选项。\n\n## 询问有关 GitHub Advanced Security 功能产生的警报的问题\n\n你可以向 Copilot 询问有关组织内存储库中的安全警报的问题，这些警报来自于 GitHub Advanced Security 功能（code scanning、secret scanning 和 Dependabot alerts）。 例如：\n\n* `How would I fix this alert?`\n* `How many alerts do I have on this pull request?`\n* `Which line of code is this code scanning alert referencing?`\n* `What library is affected by this Dependabot alert?`\n\n## 设置新项目\n\n使用 `/new` 斜杠命令设置新项目。 例如：\n\n* `/new react app with typescript`\n* `/new python django web application`\n* `/new node.js express server`\n\nCopilot将建议目录结构，并提供用于创建建议的文件和内容的按钮。 要预览建议的文件，请在建议的目录结构中选择文件名称。\n\n使用 `/newNotebook` 斜线命令来设置新的 Jupyter Notebook。 例如：\n\n* `/newNotebook retrieve the titanic dataset and use Seaborn to plot the data`\n\n## 修复、改进和重构代码\n\n如果活动文件包含错误，请使用 `/fix` 斜杠命令请求 Copilot 修复错误。\n\n还可以提出常规请求来改进或重构代码。\n\n* `how would you improve this code?`\n* `translate this code to C#`\n* `add error handling to this function`\n\n## 编写测试\n\n`/tests`使用斜杠命令请求Copilot为活动文件或所选代码编写测试。 例如：\n\n* `/tests`\n* `/tests using the Jest framework`\n* `/tests ensure the function rejects an empty list`\n\n`/tests` 斜杠命令将为现有代码编写测试。 如果希望在编写代码之前编写测试（测试驱动的开发），请省略 `/tests` 命令。 例如：\n\n* `Add tests for a JavaScript function that should sum a list of integers`\n\n## 询问有关Visual Studio Code的问题\n\n使用`@vscode`与聊天参与者交流，以询问有关Visual Studio Code的具体问题。 例如：\n\n* `@vscode tell me how to debug a node.js app`\n* `@vscode how do I change my Visual Studio Code colors`\n* `@vscode how can I change key bindings`\n\n## 询问有关命令行的问题\n\n使用 `@terminal` 聊天参与者工具来询问有关命令行的特定问题。 例如：\n\n* `@terminal find the largest file in the src directory`\n* `@terminal #terminalLastCommand` 解释上一个命令以及任何错误\n\n</div>\n\n<div class=\"ghd-tool visualstudio\">\n\n## 询问常见软件问题\n\n你可以向 Copilot Chat 询问一般软件问题。 例如：\n\n* `tell me about nodejs web server frameworks`\n* `how can I create an Express app`\n* `what's the process for updating an npm package`\n\n## 询问有关您项目的问题\n\n你可以向 Copilot Chat 询问项目相关问题。 若要提供 Copilot 正确的上下文，请尝试以下一些策略：\n\n* 突出显示相关代码行。\n* 打开相关文件。\n* 使用 `#file` 指示 Copilot 引用特定文件。\n* 使用 `#solution` 命令 Copilot 引用活动文件。\n\n例如：\n\n* `what sorting algorithm does this function use`\n* `#file:gameReducer.js what happens when a new game is requested`\n\n## 编写代码\n\n你可以要求 Copilot 为你编写代码。 例如：\n\n* `write a function to sum all numbers in a list`\n* `add error handling to this function`\n\n返回代码块时 Copilot ，响应包括用于复制代码、将代码插入新文件中或预览代码输出的选项。\n\n## 询问有关 GitHub Advanced Security 功能产生的警报的问题\n\n你可以向 Copilot 询问有关组织内存储库中的安全警报的问题，这些警报来自于 GitHub Advanced Security 功能（code scanning、secret scanning 和 Dependabot alerts）。 例如：\n\n* `How would I fix this alert?`\n* `How many alerts do I have on this pull request?`\n* `Which line of code is this code scanning alert referencing?`\n* `What library is affected by this Dependabot alert?`\n\n## 修复、改进和重构代码\n\n如果活动文件包含错误，请使用 `/fix` 斜杠命令请求 Copilot 修复错误。\n\n还可以提出常规请求来改进或重构代码。\n\n* `how would you improve this code?`\n* `translate this code to C#`\n* `add error handling to this function`\n\n## 编写测试\n\n`/tests`使用斜杠命令请求Copilot为活动文件或所选代码编写测试。 例如：\n\n* `/tests`\n* `/tests using the Jest framework`\n* `/tests ensure the function rejects an empty list`\n\n`/tests` 斜杠命令将为现有代码编写测试。 如果希望在编写代码之前编写测试（测试驱动的开发），请省略 `/tests` 命令。 例如：\n\n* `Add tests for a JavaScript function that should sum a list of integers`\n\n</div>\n\n<div class=\"ghd-tool jetbrains\">\n\n## 询问常见软件问题\n\n你可以向 Copilot Chat 询问一般软件问题。 例如：\n\n* `tell me about nodejs web server frameworks`\n* `how can I create an Express app`\n* `what's the process for updating an npm package`\n\n## 询问有关您项目的问题\n\n你可以向 Copilot Chat 询问项目相关问题。 若要提供 Copilot 正确的上下文，请尝试以下一些策略：\n\n* 突出显示相关代码行。\n* 打开相关文件。\n* 添加文件作为引用。 有关如何使用文件引用的信息，请参阅 [在 IDE 中向 GitHub Copilot 提问问题](/zh/copilot/how-tos/chat-with-copilot/chat-in-ide?tool=jetbrains#file-references)。\n* 使用 `@project` 聊天参与者。\n\n例如：\n\n* `what sorting algorithm does this function use`\n* `how are these files related`（引用相关文件）\n* `@project how are notifications scheduled`\n\n## 编写代码\n\n你可以要求 Copilot 为你编写代码。 例如：\n\n* `write a function to sum all numbers in a list`\n* `add error handling to this function`\n\n返回代码块时，Copilot 的响应包括选项，可用于复制代码或将代码插入光标所在位置。\n\n## 修复、改进和重构代码\n\n如果活动文件包含错误，请使用 `/fix` 斜杠命令请求 Copilot 修复错误。\n\n还可以提出常规请求来改进或重构代码。\n\n* `how would you improve this code?`\n* `translate this code to C#`\n* `add error handling to this function`\n\n## 编写测试\n\n`/tests`使用斜杠命令请求Copilot为活动文件或所选代码编写测试。 例如：\n\n* `/tests`\n* `/tests using the Jest framework`\n* `/tests ensure the function rejects an empty list`\n\n`/tests` 斜杠命令将为现有代码编写测试。 如果希望在编写代码之前编写测试（测试驱动的开发），请省略 `/tests` 命令。 例如：\n\n* `Add tests for a JavaScript function that should sum a list of integers`\n\n</div>\n\n<div class=\"ghd-tool eclipse\">\n\n## 询问常见软件问题\n\n你可以向 Copilot Chat 询问一般软件问题。 例如：\n\n* `tell me about nodejs web server frameworks`\n* `how can I create an Express app`\n* `what's the process for updating an npm package`\n\n## 询问有关项目中的文件的问题\n\n你可以向 Copilot Chat 提问关于当前在编辑器中显示的文件的问题，或者关于你在 Copilot Chat 面板中已附加到对话的文件的问题。 若要提供 Copilot 正确的上下文，\n\n* 在编辑器中打开相关文件。\n* 单击面板中的剪纸图标 Copilot Chat ，然后搜索并选择要附加到对话的文件。\n\n例如：\n\n* `how can I make this file run faster`\n* `how are these files related`（具有两个或多个附加文件）\n* `explain the getSearchReplaceRules function`\n\n## 编写代码\n\n你可以要求 Copilot 为你编写代码。 例如：\n\n* `write a TypeScript function to sum all numbers in a list`\n* `using the comments in this file, create appropriate Node JavaScript`\n\n返回代码块时 Copilot ，响应包含复制代码的选项。\n\n## 修复、改进和重构代码\n\n如果活动文件包含错误，请使用 `/fix` 斜杠命令请求 Copilot 修复错误。\n\n还可以提出常规请求来改进或重构代码。\n\n* `how would you improve the code in this file`\n* `translate this code to C#`\n* `add error handling to the main function`\n\n## 编写测试\n\n`/tests`使用斜杠命令请求Copilot为活动文件或所选代码编写测试。 例如：\n\n* `/tests`\n* `/tests using the Jest framework`\n* `/tests ensure the function rejects an empty list`\n\n`/tests` 斜杠命令将为现有代码编写测试。 如果希望在编写代码之前编写测试（测试驱动的开发），请省略 `/tests` 命令。 例如：\n\n* `Add tests for a JavaScript function that should sum a list of integers`\n\n</div>"}