Expand description
§CodeBank
codebank
is a powerful documentation generator that creates structured markdown documentation
from your codebase. It supports multiple programming languages and provides flexible strategies
for documentation generation.
§Features
- Multi-language Support: Parse and document Rust, Python, TypeScript, and C code
- Flexible Strategies: Choose between different documentation strategies:
Default
: Complete code representation with full implementationsNoTests
: Exclude test-related code for cleaner documentationSummary
: Generate public interface documentation only
- Intelligent Parsing: Uses tree-sitter for accurate code parsing and analysis
- Customizable Output: Control what gets included in your documentation
§Quick Start
use codebank::{Bank, BankConfig, BankStrategy, CodeBank, Result};
use std::path::Path;
fn main() -> Result<()> {
// Create a new code bank generator
let code_bank = CodeBank::try_new()?;
// Generate documentation for your source directory
let config = BankConfig::new(Path::new("src"), BankStrategy::Default, vec![]);
let content = code_bank.generate(&config)?;
println!("Generated documentation:\n{}", content);
Ok(())
}
§Documentation Strategies
§Default Strategy
The default strategy includes all code elements with their complete implementations:
use codebank::{Bank, BankConfig, BankStrategy, CodeBank, Result};
use std::path::Path;
let code_bank = CodeBank::try_new()?;
let config = BankConfig::new(Path::new("src"), BankStrategy::Default, vec![]);
let content = code_bank.generate(&config)?;
§NoTests Strategy
Exclude test-related code for cleaner documentation:
use codebank::{Bank, BankConfig, BankStrategy, CodeBank, Result};
use std::path::Path;
let code_bank = CodeBank::try_new()?;
let config = BankConfig::new(Path::new("src"), BankStrategy::NoTests, vec![]);
let content = code_bank.generate(&config)?;
§Summary Strategy
Generate documentation for public interfaces only:
use codebank::{Bank, BankConfig, BankStrategy, CodeBank, Result};
use std::path::Path;
let code_bank = CodeBank::try_new()?;
let config = BankConfig::new(Path::new("src"), BankStrategy::Summary, vec![]);
let content = code_bank.generate(&config)?;
§Custom Implementation
You can implement the Bank
trait for your own code bank generator:
use codebank::{Bank, BankConfig, BankStrategy, Result};
use std::path::Path;
struct MyCodeBank;
impl Bank for MyCodeBank {
fn generate(&self, config: &BankConfig) -> Result<String> {
// Your implementation here
Ok("# Code Bank\n\nCustom implementation".to_string())
}
}
§Error Handling
The crate uses a custom Result
type that wraps common error cases:
use codebank::{Bank, BankConfig, BankStrategy, CodeBank, Result, Error};
let code_bank = CodeBank::try_new()?;
let config = BankConfig::new(std::path::Path::new("nonexistent"), BankStrategy::Default, vec![]);
let result = code_bank.generate(&config);
if let Err(err) = result {
eprintln!("Failed to generate documentation: {}", err);
}
Modules§
Structs§
- Bank
Config - Configuration for generating code bank documentation.
- Code
Bank - The code bank generator implementation
- Code
Bank Mcp - CodeBank MCP server implementation
- CppParser
- Declare
Statements - Represents declarations in source code.
- Field
Unit - Represents a field in a struct
- File
Unit - Represents a file in the code.
- Function
Unit - Represents a function or method in the code
- GoParser
- Impl
Unit - Represents an implementation block in the code, not all languages need this
- Module
Unit - Represents a module in the code
- Python
Parser - Rust
Parser - Struct
Unit - Represents a struct or class in the code
- Trait
Unit - Represents a trait or interface in the code
- Type
Script Parser
Enums§
- Bank
Strategy - Strategy for generating code bank documentation.
- Declare
Kind - The kind of declaration statement.
- Error
- Error types for the CodeBank library.
- Language
Type - The language type supported by the parser.
- Visibility
- Represents visibility levels for code elements.
Traits§
- Bank
- Trait to generate a code bank for a given directory.
- Formatter
- Language
Parser - Trait for language-specific parsers.
Type Aliases§
- Result
- Result type alias for CodeBank operations.