Skip to main content

cargo-aidoc

cargo-aidoc is a Python script that leverages Large Language Models (LLMs) to automatically generate documentation comments for Rust code items like functions, structs, enums, etc.

Features

  • Analyzes Rust source files using tree-sitter.
  • Identifies documentable items (functions, structs, enums, etc.).
  • Uses LLMs (configurable via mirascope) to generate documentation comments.
  • Integrates with Git to prevent overwriting uncommitted changes (can be overridden with --force).
  • Configurable via cargo-aidoc.toml.
  • Supports dry runs to preview generated documentation.

Installation

This project uses uv for package management.

uv tool install cargo-aidoc

Usage

Run the script pointing it to the root of your Rust crate:

cargo aidoc /path/to/your/rust/crate

Options:

  • CRATE_PATH: (Required) The path to the Rust crate directory.
  • -q, --quiet: Disable verbose output.
  • --dry-run: Generate documentation but do not write changes to the files.
  • --force: Ignore the Git uncommitted changes check and modify files directly.
  • -c, --clean-cache: Remove the .cargo-aidoc cache directory after execution.

Example:

# Generate docs for a crate, showing verbose output, but don't modify files
cargo aidoc . --quiet --dry-run

# Generate and write docs, forcing overwrite even with uncommitted changes
cargo aidoc . --force

Configuration

The script looks for a cargo-aidoc.toml file in the root of the target crate. If it doesn't exist, a default one will be created.

Default cargo-aidoc.toml:

[llm]
# Configuration passed to mirascope.llm.call
# See mirascope documentation for options
provider = "openai"
model = "gpt-4o"
call_params = {} # e.g., {"temperature": 0.5}

[doc]
# Glob pattern relative to the crate root for source files
source = ["src/**/*.rs"]
# Types of items to document
item_types = ["fn", "struct", "enum", "union", "trait", "macro", "static"]

You can customize the LLM provider, model, call parameters, source file pattern, and the types of Rust items you want to document.

Dependencies

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

The MIT License (MIT) under Computer-Aided Programming Group at Purdue University, see LICENCE

Release files for cargo-aidoc 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cargo-aidoc 0.1.3
File Size Uploaded
cargo_aidoc-0.1.3.tar.gz 8.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cargo-aidoc 0.1.3
File Interpreter ABI Platform
cargo_aidoc-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 17.6 kB

Release files / cargo_aidoc-0.1.3.tar.gz

Download URL cargo_aidoc-0.1.3.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
50710577ade9a606b2d50e7ab2d20ab4fec76bc03f80cab2c8e6459010ccda01
BLAKE2b-256 checksum
How to use checksums
3f580580258e40676d1d975c3a65a0a79db4e1cd6f47099f4435540bb35080bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.14

Release files / cargo_aidoc-0.1.3-py3-none-any.whl

Download URL cargo_aidoc-0.1.3-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
910d7b7d67a3002f44408b8a97091324bc967bbb305825540ffbbf37d3b1ad27
BLAKE2b-256 checksum
How to use checksums
0a273986ee14a943315e15c17587f58672d4d7206ca23d63f9dcce4c5a7d8d1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.14

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page