可以向 Copilot Chat 询问有关项目的特定问题或常见软件问题。 还可以要求 Copilot Chat 编写代码、修复错误、编写测试和记录代码。
使用上面的选项卡选择使用 Copilot Chat 的环境。
询问常见软件问题
可以向 Copilot Chat 询问常见软件问题。 例如:
tell me about nodejs web server frameworks
how to create an express app
how to update an npm package
询问有关项目的问题
可以向 Copilot Chat 询问有关项目的问题。 要为 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