🧩 场景一:为函数/模块自动生成文档注释
✅ 示例:为 Go 语言函数生成专业英文注释
操作方式:
选中代码(或在代码上右键)
使用 Prompt(英文效果更好):
Add a concise and professional English comment for this function, describing its purpose, parameters, and return value. Follow standard Go documentation style.
func CalculateTax(amount float64) float64 {return amount * 0.13}
// CalculateTax returns the tax amount for a given value,// based on a fixed tax rate of 13%.func CalculateTax(amount float64) float64 {return amount * 0.13}
Generate markdown-style documentation for this API handler, including endpoint, method, parameters, request/response examples, and error cases.
### POST api/v1/ordersCreate a new order.**Request Body:**```json{"product_id": "string","quantity": 2}
{"order_id": "abc123","status": "created"}
Error Codes:
400 Bad Request
– Invalid input500 Internal Server Error
– Server-side error
效果:适合用于内部接口对接、OpenAPI 替代文档、前后端协作。
🧩 场景三:自动生成项目 README
进入项目根目录,使用如下 Prompt:
Write a professional README.md for this project. Include a short description, how to install, how to run, technologies used, and contribution guide.
Explain the structure and purpose of this codebase. Include major components, how they interact, and which parts are responsible for business logic, data access, and configuration.
Act as a technical writer. Summarize the codebase for onboarding new engineers, focusing on design patterns, key flows, and module responsibilities.
Write a concise comment describing what this function does, including parameters and return values. | |
Generate markdown documentation for this REST API controller. | |
Explain the role of this module in the application. Include how it interacts with other components. | |
Write a README for this project, including usage and setup. | |
Generate a high-level system overview based on the code structure. |
🔧 提示:如何提升质量?
上下文越完整,结果越准确:不要只让它看函数,可以从模块/多个文件选中。
尽量用英文 Prompt,Cursor 的 AI 更能理解写文档的意图。
可以后续追加修改 Prompt,比如:
"Now rewrite it in Chinese" 或
"Make it more concise and suitable for a beginner reader."
文章转载自Coding 部落,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




