49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
|
|
package docs
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"strings"
|
||
|
|
)
|
||
|
|
|
||
|
|
// BuildDocsMessages builds the messages for documentation generation.
|
||
|
|
// Exported for use by MCP server.
|
||
|
|
func BuildDocsMessages(language, code string) []map[string]string {
|
||
|
|
style := docStyle(language)
|
||
|
|
systemPrompt := fmt.Sprintf(
|
||
|
|
"You are a documentation expert. Add %s documentation comments to the provided code. "+
|
||
|
|
"Return ONLY the documented code with no explanations, markdown, or extra text. "+
|
||
|
|
"Do NOT include markdown code fences. Document all public functions, methods, types, and constants.",
|
||
|
|
style,
|
||
|
|
)
|
||
|
|
|
||
|
|
userPrompt := fmt.Sprintf("Add documentation comments to the following %s code:\n\n%s", language, code)
|
||
|
|
|
||
|
|
return []map[string]string{
|
||
|
|
{"role": "system", "content": systemPrompt},
|
||
|
|
{"role": "user", "content": userPrompt},
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func docStyle(language string) string {
|
||
|
|
switch strings.ToLower(language) {
|
||
|
|
case "go":
|
||
|
|
return "godoc"
|
||
|
|
case "python":
|
||
|
|
return "PEP 257 docstring"
|
||
|
|
case "c", "c++":
|
||
|
|
return "doxygen style"
|
||
|
|
case "javascript", "typescript":
|
||
|
|
return "JSDoc"
|
||
|
|
case "rust":
|
||
|
|
return "rustdoc"
|
||
|
|
case "ruby":
|
||
|
|
return "YARD"
|
||
|
|
case "java":
|
||
|
|
return "javadoc"
|
||
|
|
case "shell":
|
||
|
|
return "shell style comments"
|
||
|
|
default:
|
||
|
|
return "standard"
|
||
|
|
}
|
||
|
|
}
|