Skip to main content

`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.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cargo_aidoc-0.1.3.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cargo_aidoc-0.1.3-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file cargo_aidoc-0.1.3.tar.gz.

File metadata

  • Download URL: cargo_aidoc-0.1.3.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for cargo_aidoc-0.1.3.tar.gz
Algorithm Hash digest
SHA256 50710577ade9a606b2d50e7ab2d20ab4fec76bc03f80cab2c8e6459010ccda01
MD5 8a3ac493b30735f4f3b1c26a36c50eb4
BLAKE2b-256 3f580580258e40676d1d975c3a65a0a79db4e1cd6f47099f4435540bb35080bb

See more details on using hashes here.

File details

Details for the file cargo_aidoc-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for cargo_aidoc-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 910d7b7d67a3002f44408b8a97091324bc967bbb305825540ffbbf37d3b1ad27
MD5 22233f9328f401a103235ea8a24fc6b9
BLAKE2b-256 0a273986ee14a943315e15c17587f58672d4d7206ca23d63f9dcce4c5a7d8d1c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page