# Function Markdown Feature - Living Blueprints of Your Code! 📚🔍
## Overview
Smart Tree now includes a **function-markdown** formatter that automatically extracts and documents functions from your codebase. This creates a living documentation that updates as you code!
## Usage
```bash
# Generate function documentation for a directory
st --mode function-markdown src/
# Include private functions
st --mode function-markdown --show-private src/
# Save to a file
st --mode function-markdown src/ > FUNCTIONS.md
# Watch for changes and regenerate
watch -n 5 'st --mode function-markdown src/ > FUNCTIONS.md'
```
## Features
### 1. Automatic Function Discovery
- Extracts function names from code files using regex patterns
- Supports 25+ programming languages:
- Rust (`fn`, `pub fn`)
- Python (`def`, `async def`)
- JavaScript/TypeScript (`function`, `const`, arrow functions)
- Java (methods with visibility modifiers)
- Go (`func`)
- C/C++ (function definitions)
- And many more!
### 2. Rich Documentation Output
- **Summary Statistics**: Total functions, public vs private breakdown
- **Language Breakdown**: Functions grouped by programming language
- **Table of Contents**: Clickable navigation to each file and function
- **Function Details**: Location, signature, visibility
- **Call Graphs**: Mermaid diagrams showing function relationships (future enhancement)
### 3. Smart Organization
- Groups functions by file (default)
- Shows file paths with line numbers for easy navigation
- Language-specific emoji indicators
## Example Output
```markdown
# 📚 Function Documentation
*Generated by Smart Tree - 42 functions found*
## 📊 Summary
- **Total Functions**: 42
- **Public Functions**: 28
- **Private Functions**: 14
### 🗣️ Languages
- 🦀 rs: 25 functions
- 🐍 py: 10 functions
- 📜 ts: 7 functions
## 📑 Table of Contents
- [src/scanner.rs](#src-scanner-rs)
- [new()](#src-scanner-rs-new)
- [scan()](#src-scanner-rs-scan)
- [scan_stream()](#src-scanner-rs-scan-stream)
## 🔧 Functions
### 📄 src/scanner.rs
#### 🔓 new `public`
📍 **Location**: `src/scanner.rs:1-10`
**Signature**:
```rust
new(...)
```
---
```
## Current Implementation
The current implementation uses regex-based extraction to quickly identify functions. This provides:
- Fast scanning of large codebases
- Language-agnostic approach
- No external dependencies
## Future Enhancements
1. **Full AST Parsing**: Use tree-sitter for accurate parsing
2. **Doc Comment Extraction**: Include function documentation
3. **Complexity Analysis**: Calculate cyclomatic complexity
4. **Call Graph Generation**: Show which functions call which
5. **Type Information**: Extract parameter and return types
6. **Live Updates**: File watching with automatic regeneration
7. **Export Formats**: HTML, PDF, and interactive web views
## Integration Ideas
### CI/CD Pipeline
```yaml
- name: Generate Function Docs
run: |
st --mode function-markdown src/ > docs/FUNCTIONS.md
git add docs/FUNCTIONS.md
git commit -m "📚 Update function documentation"
```
### IDE Integration
- Live preview pane showing functions in current file
- Jump-to-definition from markdown
- Auto-update on save
### Team Collaboration
- Track function ownership
- Show last modified dates
- Link to commits and PRs
## Trisha's Take
"This is AMAZING! 🎉 It's like having a GPS for your code! No more getting lost in huge codebases wondering 'where was that function again?'
You know how I keep meticulous records of every transaction? This is like that but for functions! And the best part? It updates itself! No more outdated documentation that lies to you (we've all been there).
The emojis for different languages? *Chef's kiss* 🤌 Makes it so easy to spot what kind of code you're looking at. Python gets a snake, Rust gets a crab - it's perfect!
This is going to save SO much time during code reviews. Instead of scrolling through files, you get a nice overview of all the functions. It's like having an index for your cookbook!"
## How It Works
1. **File Scanning**: Walks through the directory tree
2. **Language Detection**: Identifies programming language by file extension
3. **Pattern Matching**: Uses language-specific regex patterns to find functions
4. **Markdown Generation**: Formats findings into beautiful documentation
5. **Smart Filtering**: Excludes common false positives (if, for, while, etc.)
## Command-Line Options
- `--mode function-markdown`: Enable function documentation mode
- `--show-private`: Include private/internal functions (default: public only)
- `--depth N`: Limit directory traversal depth
- `--type ext`: Focus on specific file types (e.g., `--type rs`)
## Performance
- Processes thousands of files in seconds
- Minimal memory footprint
- Scales to large codebases
- No external dependencies or language servers required
## The Vision
As mentioned by Hue: "Eventually.. a video like experience of coding as we move through it. showing the functions and relations in real time."
This is just the beginning! Future versions will include:
- Real-time updates as you code
- Animated transitions showing code evolution
- Interactive call graphs
- AI-powered insights and suggestions
- Integration with MEM|8 for semantic understanding
---
*"It's like having a living blueprint of your code!" - Trisha* 📐