可以向 Copilot 对话助手 询问有关项目的特定问题或常见软件问题。 还可以要求 Copilot 对话助手 编写代码、修复错误、编写测试和记录代码。
使用上面的选项卡选择使用 Copilot 对话助手 的环境。
以下示例提示中的一些提示使用聊天参与者(前面有 @)、斜杠命令(前面有 /)或聊天变量(前面有 #)。 有关提示中关键字的详细信息,请参阅“在 IDE 中向 GitHub Copilot 提问”。
询问常见软件问题
可以向 Copilot 对话助手 询问常见软件问题。 例如:
- tell me about nodejs web server frameworks
- how can I create an Express app
- @terminal how to update an npm package
询问有关项目的问题
可以向 Copilot 对话助手 询问有关项目的问题。
- what sorting algorithm does this function use
- @workspace how are notifications scheduled
- #file:gameReducer.js #file:gameInit.js how are these files related
要为 Copilot 提供正确的上下文,请尝试以下策略之一:
- 突出显示相关代码行。
- 使用聊天变量,例如 #selection、#file、#editor、#codebase或#git。
- 使用 @workspace聊天参与者。
编写代码
可以要求 Copilot 为你编写代码。 例如:
- write a function to sum all numbers in a list
- add error handling to this function
- @workspace add form validation, similar to the newsletter page
当 Copilot 返回代码块时,回复包含用来复制代码或者将代码插入到光标处、新文件或终端的选项。
询问有关来自 GitHub Advanced Security 功能的警报的问题
可以向 Copilot 询问组织存储库中来自 GitHub Advanced Security 功能(code scanning、secret scanning 和 Dependabot alerts)的安全警报的相关信息。 例如:
- How would I fix this alert?
- How many alerts do I have on this pull request?
- Which line of code is this code scanning alert referencing?
- What library is affected by this Dependabot alert?
设置新项目
使用 /new 斜杠命令设置新项目。 例如:
- /new react app with typescript
- /new python django web application
- /new node.js express server
Copilot 将建议一个目录结构,并提供一个按钮用于创建建议的文件和内容。 要预览建议的文件,请在建议的目录结构中选择文件名称。
使用 /newNotebook 斜杠命令设置新的 Jupyter Notebook。 例如:
- /newNotebook retrieve the titanic dataset and use Seaborn to plot the data
修复、改进和重构代码
如果活动文件包含错误,请使用 /fix 斜杠命令要求 Copilot 修复错误。
还可以提出常规请求来改进或重构代码。
- how would you improve this code?
- translate this code to C#
- add error handling to this function
编写测试
使用 /tests 斜杠命令要求 Copilot 为活动文件或所选代码编写测试。 例如:
- /tests
- /tests using the Jest framework
- /tests ensure the function rejects an empty list
/tests 斜杠命令将为现有代码编写测试。 如果希望在编写代码之前编写测试(测试驱动的开发),请省略 /tests 命令。 例如:
- Add tests for a JavaScript function that should sum a list of integers
询问有关 Visual Studio Code 的问题
使用 @vscode 聊天参与者询问有关 Visual Studio Code 的特定问题。 例如:
- @vscode tell me how to debug a node.js app
- @vscode how do I change my Visual Studio Code colors
- @vscode how can I change key bindings
询问有关命令行的问题
使用 @terminal 聊天参与者询问有关命令行的特定问题。 例如:
- @terminal find the largest file in the src directory
- @terminal #terminalLastCommand解释上一个命令以及任何错误
询问常见软件问题
可以向 Copilot 对话助手 询问常见软件问题。 例如:
- tell me about nodejs web server frameworks
- how can I create an Express app
- what's the process for updating an npm package
询问有关项目的问题
可以向 Copilot 对话助手 询问有关项目的问题。 要为 Copilot 提供正确的上下文,请尝试以下策略之一:
- 突出显示相关代码行。
- 打开相关文件。
- 使用 #file来告知 Copilot 引用特定文件。
- 使用 #solution来告知 Copilot 引用活动文件。
例如:
- what sorting algorithm does this function use
- #file:gameReducer.js what happens when a new game is requested
编写代码
可以要求 Copilot 为你编写代码。 例如:
- write a function to sum all numbers in a list
- add error handling to this function
Copilot 返回代码块时,响应包括用于复制代码、将代码插入新文件或预览代码输出的选项。
询问有关来自 GitHub Advanced Security 功能的警报的问题
可以向 Copilot 询问组织存储库中来自 GitHub Advanced Security 功能(code scanning、secret scanning 和 Dependabot alerts)的安全警报的相关信息。 例如:
- How would I fix this alert?
- How many alerts do I have on this pull request?
- Which line of code is this code scanning alert referencing?
- What library is affected by this Dependabot alert?
修复、改进和重构代码
如果活动文件包含错误,请使用 /fix 斜杠命令要求 Copilot 修复错误。
还可以提出常规请求来改进或重构代码。
- how would you improve this code?
- translate this code to C#
- add error handling to this function
编写测试
使用 /tests 斜杠命令要求 Copilot 为活动文件或所选代码编写测试。 例如:
- /tests
- /tests using the Jest framework
- /tests ensure the function rejects an empty list
/tests 斜杠命令将为现有代码编写测试。 如果希望在编写代码之前编写测试(测试驱动的开发),请省略 /tests 命令。 例如:
- Add tests for a JavaScript function that should sum a list of integers
询问常见软件问题
可以向 Copilot 对话助手 询问常见软件问题。 例如:
- tell me about nodejs web server frameworks
- how can I create an Express app
- what's the process for updating an npm package
询问有关项目的问题
可以向 Copilot 对话助手 询问有关项目的问题。 要为 Copilot 提供正确的上下文,请尝试以下策略之一:
- 突出显示相关代码行。
- 打开相关文件。
- 添加文件作为引用。 有关如何使用文件引用的信息,请参阅“在 IDE 中向 GitHub Copilot 提问”。
- 使用 @project聊天参与者。
例如:
- what sorting algorithm does this function use
- how are these files related(引用相关文件)
- @project how are notifications scheduled
编写代码
可以要求 Copilot 为你编写代码。 例如:
- write a function to sum all numbers in a list
- add error handling to this function
Copilot 返回代码块时,响应包括用于复制代码或在光标处插入代码的选项。
修复、改进和重构代码
如果活动文件包含错误,请使用 /fix 斜杠命令要求 Copilot 修复错误。
还可以提出常规请求来改进或重构代码。
- how would you improve this code?
- translate this code to C#
- add error handling to this function
编写测试
使用 /tests 斜杠命令要求 Copilot 为活动文件或所选代码编写测试。 例如:
- /tests
- /tests using the Jest framework
- /tests ensure the function rejects an empty list
/tests 斜杠命令将为现有代码编写测试。 如果希望在编写代码之前编写测试(测试驱动的开发),请省略 /tests 命令。 例如:
- Add tests for a JavaScript function that should sum a list of integers
某些示例提示要求你位于 GitHub 网站上的特定上下文中。 有关如何访问这些上下文的详细信息,请参阅在不同上下文中向 Copilot 对话助手 提问。
询问常见软件问题
可以向 Copilot 对话助手 询问常见软件问题。 例如:
询问关于仓库的问题
可以向 Copilot 对话助手 询问有关仓库的问题。 例如:
- what is the purpose of this repository?
- When was the most recent release?
- Where is rate limiting implemented in our API?
- What was the last merged PR by USERNAME
询问有关特定文件或符号的问题
可以向 Copilot 对话助手 询问有关特定文件或符号的问题。 例如:
- what sorting algorithm does this function use
- how are these files related
- what is the purpose of this function
询问有关知识库的问题
可以向 Copilot 对话助手 询问有关知识库的问题。 例如:
- How do I deploy a new application?
- What's the process for creating a new REST API?
- What are our best practices for logging?
询问有关特定代码段的问题
可以向 Copilot 对话助手 询问有关特定代码块的问题。 可以询问有关整个文件或特定行的问题。 例如:
如果要询问关于整个文件的问题,则可以输入:
- Explain this file.
- How could I improve this code?
- How can I test this script?
如果要询问特定行,则可以输入:
- Explain the function at the selected lines.
- How could I improve this class?
- Add error handling to this code.
- Write a unit test for this method.
询问有关来自 GitHub Advanced Security 功能的警报的问题
可以向 Copilot 对话助手 询问组织仓库中来自 GitHub Advanced Security 功能(code scanning、secret scanning 和 Dependabot alerts)的安全警报的相关问题。 例如:
- How would I fix this alert?
- How many alerts do I have on this pull request?
- Which line of code is this code scanning alert referencing?
- What library is affected by this Dependabot alert?
在拉取请求中向 Copilot 对话助手 提问
可以在拉取请求中向 Copilot 对话助手 提问。 你的问题可以与拉取请求的各个元素相关,例如:
可以询问拉取请求中的更改摘要问题:
- Summarize this PR for me.
- Summarize the comments in this PR.
- Summarize the changes in this PR.
可以询问拉取请求中特定文件的更改问题:
- What's the purpose of this file?
- Why has this module been included?
可以询问拉取请求中特定行的更改问题:
- What is "actorData" in this line?
- Explain this "do..end" block.
可以询问工作流失败的原因:
- Tell me why this job failed
- Suggest a fix for this error
向 Copilot 对话助手 询问有关特定议题或讨论的问题
可以向 Copilot 对话助手 询问有关特定议题或讨论的问题。 例如:
- what is the purpose of this issue?
向 Copilot 对话助手 询问有关特定提交的问题
可以向 Copilot 对话助手 询问有关特定提交的问题。 例如:
- what is the purpose of this commit?
- what is the expected output of this commit?
- what is the best way to test this commit?
询问常见软件问题
可以向 Copilot 对话助手 询问常见软件问题。 例如:
- tell me about nodejs web server frameworks
- how can I create an Express app
- what's the process for updating an npm package
询问有关项目中的文件的问题
可以向 Copilot 对话助手 询问有关编辑器中当前显示的文件的问题,或者有关你在 Copilot 对话助手 面板中附加到对话中的文件的问题。 为 Copilot 提供正确的上下文:
- 在编辑器中打开相关文件。
- 单击 Copilot 对话助手 面板中的回形针图标,然后搜索并选择要附加到对话的文件。
例如:
- how can I make this file run faster
- how are these files related(具有两个或多个附加文件)
- explain the getSearchReplaceRules function
编写代码
可以要求 Copilot 为你编写代码。 例如:
- write a TypeScript function to sum all numbers in a list
- using the comments in this file, create appropriate Node JavaScript
Copilot 返回代码块时,响应包括用于复制代码。
修复、改进和重构代码
如果活动文件包含错误,请使用 /fix 斜杠命令要求 Copilot 修复错误。
还可以提出常规请求来改进或重构代码。
- how would you improve the code in this file
- translate this code to C#
- add error handling to the main function
编写测试
使用 /tests 斜杠命令要求 Copilot 为活动文件或所选代码编写测试。 例如:
- /tests
- /tests using the Jest framework
- /tests ensure the function rejects an empty list
/tests 斜杠命令将为现有代码编写测试。 如果希望在编写代码之前编写测试(测试驱动的开发),请省略 /tests 命令。 例如:
- Add tests for a JavaScript function that should sum a list of integers