| name | generate-code-documentation |
| description | Analyzes Rust code and generates comprehensive documentation following project standards. Traverses functions, structs, enums, traits, and modules to create complete documentation with examples, parameters, return values, and error conditions. Use when documenting code, generating API docs, or when the user asks to document functions, modules, or create documentation. |
| metadata | {"author":"hivellm"} |
Generate Code Documentation
Overview
This skill generates comprehensive documentation for Rust code by analyzing functions, structs, enums, traits, and modules. It follows Vectorizer project standards and creates documentation in English with proper formatting.
Documentation Standards
Module Documentation (//!)
Use //! for crate/module-level documentation at the top of files:
Item Documentation (///)
Use /// for all public functions, structs, enums, traits, and their fields:
pub fn function_name(param1: Type1, param2: Type2) -> Result<ReturnType, ErrorType> {
}
Documentation Generation Workflow
Step 1: Analyze Code Structure
-
Read the target file(s) using read_file or MCP Hive-Vectorizer get_file_content
-
Identify all public items:
- Functions (
pub fn)
- Structs (
pub struct)
- Enums (
pub enum)
- Traits (
pub trait)
- Modules (
pub mod)
- Constants (
pub const)
- Type aliases (
pub type)
-
Check existing documentation:
- Does module have
//! docs?
- Do public items have
/// docs?
- Are examples present?
- Are error conditions documented?
Step 2: Generate Module Documentation
For each module file:
Step 3: Document Functions
For each public function:
-
Analyze function signature:
- Function name and purpose
- Parameters (types, names, purposes)
- Return type and meaning
- Error types possible
-
Generate documentation:
pub fn function_name(...) -> Result<...> {
Step 4: Document Structs
For each public struct:
#[derive(Debug, Clone)]
pub struct StructName {
pub field_name: Type,
pub other_field: Type,
}
Step 5: Document Enums
For each public enum:
#[derive(Debug, Clone)]
pub enum EnumName {
Variant1,
Variant2(Type),
}
Step 6: Document Traits
For each public trait:
pub trait TraitName {
fn method_name(&self) -> Result<Type, Error>;
}
Code Analysis Checklist
When analyzing code for documentation:
Documentation Quality Standards
Required Elements
- One-line summary: Brief description in first line
- Detailed description: Multi-line explanation
- Parameters: All parameters documented with types and purposes
- Return values: Success and error cases explained
- Error conditions: All possible errors documented
- Examples: At least one usage example
- Panics: Document if function can panic
Optional Elements
- Performance notes: For performance-critical functions
- Thread safety: For concurrent code
- Lifetime parameters: For complex lifetime scenarios
- Generic constraints: For generic functions/types
Examples
Example 1: Function Documentation
Before:
pub fn create_collection(name: &str, config: CollectionConfig) -> Result<(), VectorizerError> {
}
After:
pub fn create_collection(name: &str, config: CollectionConfig) -> Result<(), VectorizerError> {
}
Example 2: Struct Documentation
Before:
pub struct CollectionConfig {
pub dimension: usize,
pub metric: DistanceMetric,
}
After:
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct CollectionConfig {
pub dimension: usize,
pub metric: DistanceMetric,
}
Markdown Documentation Generation
In addition to code comments (//! and ///), generate standalone Markdown documentation files in docs/ directory.
Markdown Documentation Structure
Generate Markdown files following this structure:
docs/
āāā api/ # API documentation
ā āāā README.md # API overview
ā āāā [endpoint].md # Individual endpoint docs
āāā modules/ # Module documentation
ā āāā [module-name].md # Module documentation
āāā reference/ # Reference documentation
āāā [component].md # Component reference
Markdown File Template
For each module or component, create a Markdown file:
# [Module/Component Name]
## Overview
[Brief description of what this module/component does]
## Purpose
[Detailed explanation of purpose and responsibilities]
## Key Components
### [Component 1]
[Description of component 1]
### [Component 2]
[Description of component 2]
## Functions
### `function_name`
[Function description]
**Signature:**
```rust
pub fn function_name(param1: Type1, param2: Type2) -> Result<ReturnType, ErrorType>
Parameters:
param1 - [Type1] [Description]
param2 - [Type2] [Description]
Returns:
[Description of return value]
Errors:
ErrorType::Variant - [When this error occurs]
Example:
Types
StructName
[Struct description]
Fields:
field1 - [Type] [Description]
field2 - [Type] [Description]
Usage Examples
[Complete usage examples]
See Also
- [Related documentation links]
### Generating Markdown from Code Documentation
1. **Extract code documentation** from `//!` and `///` comments
2. **Convert to Markdown format**:
- Module docs (`//!`) ā Overview section
- Function docs (`///`) ā Functions section
- Struct/Enum docs ā Types section
- Examples ā Usage Examples section
3. **Organize by module**:
- One Markdown file per module
- Group related modules in subdirectories
- Create index files for navigation
4. **Add cross-references**:
- Link to related modules
- Link to API documentation
- Link to examples
### Markdown Documentation Workflow
1. **Analyze code structure** - Identify modules and components
2. **Extract documentation** - Read `//!` and `///` comments
3. **Generate Markdown** - Convert to Markdown format
4. **Organize files** - Create appropriate directory structure
5. **Add navigation** - Create index and cross-references
6. **Verify links** - Ensure all links are valid
## API Documentation Generation
For REST API endpoints, also generate documentation in `docs/api/`:
1. **Identify API handlers** in `src/server/` or `src/api/`
2. **Extract endpoint information**:
- HTTP method (GET, POST, etc.)
- Path pattern
- Request parameters
- Request body structure
- Response structure
- Error responses
3. **Generate API documentation** following format in `docs/api/README.md`
## Workflow for Complete Documentation
1. **Identify target**: File, module, or entire crate
2. **Analyze structure**: Read code and identify public items
3. **Check existing docs**: See what's already documented
4. **Generate code documentation**:
- Add `//!` module documentation if missing
- Add `///` item documentation for all public items
- Include examples, parameters, return values, errors
5. **Generate Markdown documentation**:
- Extract documentation from code comments
- Convert to Markdown format
- Organize in `docs/modules/` or appropriate directory
- Create cross-references and navigation
6. **Enhance existing docs**: Improve incomplete documentation
7. **Add examples**: Include usage examples in both code and Markdown
8. **Verify standards**: Ensure all docs follow project standards
9. **Update API docs**: If applicable, update `docs/api/` files
10. **Verify Markdown**: Check links and formatting
## Best Practices
### DO's ā
- ā
Always document public items
- ā
Include examples for complex functions
- ā
Document all error conditions
- ā
Use clear, concise language
- ā
Follow project naming conventions
- ā
Keep examples up-to-date with code
- ā
Document edge cases and constraints
### DON'Ts ā
- ā Don't document private items (unless internal module docs)
- ā Don't repeat obvious information
- ā Don't use vague descriptions
- ā Don't skip error documentation
- ā Don't use Portuguese in code documentation
- ā Don't create documentation that will quickly become outdated
## Integration with MCP Hive-Vectorizer
When analyzing code, prefer using MCP Hive-Vectorizer tools:
- Use `get_file_content` instead of `read_file` for indexed files
- Use `intelligent_search` to find related code
- Use `get_related_files` to discover dependencies
- Use `get_project_outline` to understand module structure
## Verification
After generating documentation:
1. Run `cargo doc --no-deps` to verify documentation compiles
2. Check for warnings about missing documentation
3. Verify examples compile and run
4. Ensure all public items are documented
5. Verify documentation follows English-only rule
---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/hivellm) ā claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-11 -->