掘金 人工智能 08月07日 21:18
Copilot 代码评审:支持 copilot-instructions.md 自定义
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

GitHub Copilot 的自定义文件 `copilot-instructions.md` 已进入公共预览阶段,允许用户通过自然语言和 Markdown 格式在存储库中定义编码标准、技术要求和最佳实践,从而定制 Copilot 的工作方式。用户可以将这些指令存放在 `.github/copilot-instructions.md` 文件中,甚至按主题拆分成多个文件并相互引用。VS Code 会自动将这些自定义指令应用于每个聊天请求,以生成更符合项目规范的代码。此功能同样适用于 Visual Studio 和 GitHub.com,为开发者提供更高效、个性化的代码评审和生成体验。

🚀 GitHub Copilot 的 `copilot-instructions.md` 文件现已提供公共预览,允许开发者在存储库中自定义 Copilot 的代码生成和评审行为。用户可以通过自然语言和 Markdown 格式编写编码标准、技术栈和项目特定要求。

📄 用户可以将自定义指令存储在工作区或存储库根目录下的 `.github/copilot-instructions.md` 文件中,并可以使用 Markdown 语法进行格式化,例如定义命名约定、错误处理策略等。指令可以被组织成多个文件,并可以相互引用以保持清晰和模块化。

💡 VS Code 用户需要将 `github.copilot.chat.codeGeneration.useInstructionFiles` 设置为 `true`,以激活 `copilot-instructions.md` 文件。VS Code 会在每次聊天请求时自动将这些指令纳入,确保生成的代码符合项目规范。

💻 此自定义功能不仅限于 VS Code,Visual Studio 和 GitHub.com 同样支持检测 `.github/copilot-instructions.md` 文件,这意味着用户可以在不同环境中保持一致的 Copilot 工作流,极大地提升了开发效率和代码质量。

大家好!欢迎来到程序视点,我是你们的老朋友.安戈。

前言

早些时候,GitHub官方宣布【Copilot 代码评审】的自定义文件copilot-instructions.md提供公共预览版 。

现在copilot-instructions.md已经普遍可用!需要做的就是在存储库中添加一个copilot-instructions.md文件,并用自然语言编写说明来自定义 Copilot 的工作方式即可。

使用.github/copilot-instructions.md 文件

可以将自定义说明存储在 .github/copilot-instructions.md 工作区或存储库中的文件中,并使用 Markdown 描述编码最佳实践技术项目要求。例如:

---applyTo: "**"---# Project general coding standards## Naming Conventions- Use PascalCase for component names, interfaces, and type aliases- Use camelCase for variables, functions, and methods- Prefix private class members with underscore (_)- Use ALL_CAPS for constants## Error Handling- Use try/catch blocks for async operations- Implement proper error boundaries in React components- Always log errors with contextual information

您可以将说明分成多个文件,并说明如何引用,以保持它们井井有条并专注于特定主题。例如:

---applyTo: "**/*.ts,**/*.tsx"---# Project coding standards for TypeScript and ReactApply the [general coding guidelines](./general-coding.instructions.md) to all code.## TypeScript Guidelines- Use TypeScript for all new code- Follow functional programming principles where possible- Use interfaces for data structures and type definitions- Prefer immutable data (const, readonly)- Use optional chaining (?.) and nullish coalescing (??) operators## React Guidelines- Use functional components with hooks- Follow the React hooks rules (no conditional hooks)- Use React.FC type for components with children- Keep components small and focused- Use CSS modules for component styling

【这些自定义说明仅适用于文件所在的工作区。】

VS Code 会自动在每个聊天请求中包含.github/copilot-instructions.md 文件中的指令,并应用它们来生成代码。

使用 .github/copilot-instructions.md 注意事项

指令之间的空格会被忽略,因此指令可以写成一个段落,每个段落都在一个新行上,或者用空行分隔以方便阅读。

注意
Visual Studio 中的 GitHub Copilot 和 GitHub.com 也会检测该.github/copilot-instructions.md 文件。如果有一个在 VS Code 和 Visual Studio 中使用的工作区,则可以使用同一文件为两个编辑器定义自定义说明。

总结

有了自定义文件copilot-instructions.md的支持,现在每个人都可以利用它来定制的代码评审工作流。 ✨

如果你需要了解如何使用Copilot,可以参考以下教程:

Copilot官方教程:docs.github.com/en/copilot/…

如果遇到什问题可联系我为您解决!关注薇亻言工号【程序视点】,回复copilot,领取优惠激活!GitHub Copilot是普通人接触AI编程最简单最轻松的方式,代码不再是鸿沟!


最后

【程序视点】助力打工人减负,从不是说说而已!

如果你觉得这篇教程有帮助,别忘了【点赞+收藏+关注】三连支持!

后续安戈会持续分享更多开发工具和技巧,敬请期待!如果有其他工具需求,欢迎留言讨论~  🚀

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

GitHub Copilot 代码评审 AI编程 开发工具 Copilot
相关文章