Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "codebank"
version = "0.4.5"
edition = "2024"
edition = "2021"
description = """
A powerful code documentation generator that creates structured markdown documentation from your codebase.
Supports multiple languages including Rust, Python, TypeScript, C, and Go with intelligent parsing and formatting.
Expand Down Expand Up @@ -44,12 +44,12 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = [
"env-filter",
], optional = true }
tree-sitter = "0.23"
tree-sitter-cpp = "0.23"
tree-sitter-go = "0.23"
tree-sitter-python = "0.23"
tree-sitter-rust = "0.23"
tree-sitter-typescript = "0.23"
tree-sitter = "0.20.10"
tree-sitter-cpp = "0.20.1"
tree-sitter-go = "0.20.0"
tree-sitter-python = "0.20.0"
tree-sitter-rust = "0.20.3"
tree-sitter-typescript = "0.20.0"

[dev-dependencies]
tempfile = "3.19"
Expand Down
Empty file added fixtures/empty.rs
Empty file.
14 changes: 14 additions & 0 deletions fixtures/only_comments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This is a line comment.
//! This is an inner line comment, often used for module-level docs.

/*
This is a block comment.
It can span multiple lines.
*/

/*!
This is an inner block comment.
Also for module-level docs usually.
*/

// Another line comment.
207 changes: 127 additions & 80 deletions fixtures/sample.rs
Original file line number Diff line number Diff line change
@@ -1,128 +1,148 @@
//! This is a file-level documentation comment
//! It describes the purpose of this file
//! This is a file-level documentation comment.
//! It describes the purpose of this sample file which includes a variety of Rust items.

/// This is a public module
// Example of extern crate
extern crate proc_macro;
extern crate serde as serde_renamed;


// Example of use declarations
use std::collections::HashMap;
use std::fmt::{self, Debug as FmtDebug}; // aliased import
use crate::public_module::PublicStruct; // use item from same crate

/// This is a public module.
/// It has multiple lines of documentation.
#[cfg(feature = "some_feature")]
#[deprecated(note = "This module is old")]
pub mod public_module {
/// This is a public struct with documentation
//! Inner documentation for public_module.

/// This is a public struct with documentation.
/// It also has generics and attributes.
#[derive(Debug, Clone)]
pub struct PublicStruct {
#[serde(rename_all = "camelCase")]
pub struct PublicStruct<T: FmtDebug + Clone, U>
where
U: Default,
{
/// Public field with documentation
pub field: String,
pub field: T,
/// Private field with documentation
private_field: i32,
private_field: U, // Changed to U for generic usage
#[doc="Inner attribute doc for another_field"]
pub another_field: i32,
}

/// This is a public trait with documentation
pub trait PublicTrait {
/// Method documentation
fn method(&self) -> String;
#[allow(unused_variables)]
pub trait PublicTrait<T> {
/// Method documentation for trait.
fn method(&self, input: T) -> String;
}

/// This is a public enum with documentation
#[derive(Debug)]
pub enum PublicEnum {
/// Variant documentation
/// Variant documentation for Variant1
Variant1,
/// Another variant documentation
/// Another variant documentation for Variant2
#[allow(dead_code)] // Attribute on variant
Variant2(String),
/// Yet another variant documentation
Variant3 { field: i32 },
/// Yet another variant documentation for Variant3
/*! Block-style inner doc for Variant3 */
Variant3 {
/// Field inside a variant
#[serde(skip)]
field: i32
},
}

impl PublicStruct {
// Function with pub(crate) visibility
pub(crate) fn crate_visible_function() {
println!("This function is crate visible.");
}

// Function with pub(super) visibility (relative to current module 'public_module')
// This would typically be in a nested module to make sense.
// For demonstration, let's put it here. If it were in `super::public_module::nested_mod`,
// `pub(super)` would make it visible to `public_module`.
// Here, it's visible to the crate root (super of public_module is the crate root).
pub(super) fn super_visible_function() {
println!("This function is super visible.");
}


impl<T: FmtDebug + Clone, U: Default> PublicStruct<T, U> {
/// Constructor documentation
pub fn new(field: String, private_field: i32) -> Self {
pub fn new(field: T, private_field: U, another_field: i32) -> Self {
Self {
field,
private_field,
another_field,
}
}

/// Method documentation
pub fn get_private_field(&self) -> i32 {
self.private_field
pub fn get_private_field(&self) -> &U {
&self.private_field
}
}

impl PublicTrait for PublicStruct {
fn method(&self) -> String {
format!("{}: {}", self.field, self.private_field)
impl<T: FmtDebug + Clone> PublicTrait<T> for PublicStruct<T, String> { // Assuming U = String for this impl
fn method(&self, input: T) -> String {
format!("Field: {:?}, Private: {}, Input: {:?}", self.field, self.private_field, input)
}
}
}

pub mod nested_module {
//! Inner docs for nested_module.

// This function's pub(super) makes it visible to public_module
pub(super) fn visible_to_public_module() {}

/// This is a private module
mod private_module {
/// Private struct
struct PrivateStruct {
field: String,
}

/// Private trait
trait PrivateTrait {
fn method(&self) -> String;
}

/// Private enum
enum PrivateEnum {
Variant1,
Variant2(String),
}
// This function's pub(crate) makes it visible throughout the crate
pub(crate) fn crate_visible_from_nested() {}

impl PrivateStruct {
fn new(field: String) -> Self {
Self { field }
}
struct OnlyInNested {}
}
}

impl PrivateTrait for PrivateStruct {
fn method(&self) -> String {
self.field.clone()
}
}
/// This is a private module
mod private_module {
/*! Inner block doc for private_module. */
struct PrivateStruct { field: String }
trait PrivateTrait { fn method(&self) -> String; }
enum PrivateEnum { Variant1, Variant2(String) }
impl PrivateStruct { fn new(field: String) -> Self { Self { field } } }
impl PrivateTrait for PrivateStruct { fn method(&self) -> String { self.field.clone() } }
}

/// This is a public function with documentation
/// A public function with multiple attributes and docs.
/// Second line of doc.
#[inline]
#[must_use = "Return value should be used"]
pub fn public_function() -> String {
"Hello, world!".to_string()
}

/// This is a private function with documentation
fn private_function() -> String {
"Private hello".to_string()
#[allow(dead_code)]
fn private_function(s: &str) -> String {
format!("Private hello: {}", s)
}

/// This is a public macro with documentation
#[macro_export]
macro_rules! public_macro {
($x:expr) => {
println!("{}", $x);
};
}

/// This is a public type alias with documentation
pub type PublicType = String;
pub type PublicTypeAlias<T> = Result<T, Box<dyn std::error::Error>>;

/// This is a public constant with documentation
pub const PUBLIC_CONSTANT: &str = "constant";
pub const PUBLIC_CONSTANT: &str = "constant value";

/// This is a public static with documentation
pub static PUBLIC_STATIC: &str = "static";
#[no_mangle]
pub static PUBLIC_STATIC_VAR: i32 = 100;

/// This is a public attribute with documentation
#[derive(Debug)]
pub struct AttributedStruct {
#[doc = "Field documentation"]
pub field: String,
}

/// This is a public implementation block with documentation
impl AttributedStruct {
/// Method documentation
pub fn new(field: String) -> Self {
Self { field }
}
}

/// This is a public generic struct with documentation
pub struct GenericStruct<T> {
Expand All @@ -131,27 +151,54 @@ pub struct GenericStruct<T> {
}

/// This is a public generic trait with documentation
#[allow(unused_variables)]
pub trait GenericTrait<T> {
/// Method documentation
/// Method documentation for trait
fn method(&self, value: T) -> T;
}

/// This is a public generic implementation with documentation
/// Implementation for GenericStruct.
#[allow(dead_code)]
impl<T> GenericStruct<T> {
/// Creates a new GenericStruct.
fn new(value: T) -> Self {
Self { field: value }
}
}


/// Implementation of GenericTrait for GenericStruct.
/// Includes a where clause.
impl<T> GenericTrait<T> for GenericStruct<T>
where
T: Clone,
T: Clone + FmtDebug, // Added FmtDebug here
{
/// Method from GenericTrait.
fn method(&self, value: T) -> T {
println!("Value: {:?}", value);
value.clone()
}
}

// A module defined in another file (declaration)
mod my_other_module;

#[cfg(test)]
mod tests {
use super::*;
use super::*; // Imports items from the parent module (the file scope)

#[test]
fn test_public_function() {
fn test_public_function_output() { // Renamed to avoid conflict
assert_eq!(public_function(), "Hello, world!");
}

#[test]
fn check_public_struct_instantiation() {
// This test is more about Rust syntax than parser, but ensures sample code is valid.
let _ps = public_module::PublicStruct {
field: "test".to_string(),
private_field: 10, // Original was i32, now U, assuming i32 for test.
another_field: 20,
};
}
}
Loading
Loading