4 releases
Uses new Rust 2024
| 0.1.3 | May 26, 2025 |
|---|---|
| 0.1.2 | May 26, 2025 |
| 0.1.1 | May 25, 2025 |
| 0.1.0 | May 25, 2025 |
#126 in Procedural macros
31 downloads per month
65KB
1K
SLoC
getdoc: Rust Error Contextualizer
getdoc is a developer tool for Rust projects designed to improve the debugging process by providing relevant source code context directly alongside compiler errors and warnings, especially those originating from or implicating third-party crates.
Problem Solved
When a Rust project encounters compiler errors (e.g., trait bounds not satisfied, unresolved imports, type mismatches) that involve code from external dependencies, developers often need to:
- Identify the implicated third-party crate and specific code.
- Navigate to the crate's documentation (docs.rs) or its source code.
- Understand the relevant definitions, traits, or function signatures.
This process involves context switching and web searches, slowing down development. getdoc aims to minimize this by bringing the necessary information directly into a consolidated report.
Features
- Feature Analysis: Determines feature sets for
cargo checkby analyzingCargo.toml. By default, it checks a comprehensive set of combinations (default, no-default, all-features, individual features). When the--featurescommand-line flag is used, it performs focused checks relevant to the specified features. - Compiler Output Aggregation: Captures errors and warnings from
cargo check --message-format=json. - Third-Party Code Focus: Identifies diagnostics that involve code from dependencies (typically located in
~/.cargo/registryor~/.cargo/git). - Source Code Extraction: For each implicated third-party source file:
- Parses the Rust code using
syn. - Extracts relevant item definitions (functions, structs, enums, traits, impl blocks, associated items, type aliases, constants, extern crates, use statements).
- Includes documentation comments (
///,//!) associated with these items. - Displays error code explanations directly in the report.
- Parses the Rust code using
- Markdown Reporting: Generates a single
report.mdfile containing:- A list of compiler diagnostics, grouped by the feature set under which they occurred.
- For each implicated third-party source file:
- A list of the project's diagnostics that referenced this file.
- Extracted documentation and definitions from that file, with a hierarchical display for items within
implblocks.
How It Works
- Determine Feature Sets to Check: This is based on
Cargo.tomland the optional--featurescommand-line flag.- If the
--features <CONTEXT_FEATURES>flag is provided,getdocconstructs a focused list ofcargo checkarguments relevant to the<CONTEXT_FEATURES>(checking them with and without crate defaults, and checking crate defaults within the current environment). - Otherwise (no
--featuresflag), it readsCargo.tomlto find available features and constructs a comprehensive list of combinations (default, no-default, all-features, individual non-default features with no-default).
- If the
- Run Cargo Check: For each determined feature set, executes
cargo check --message-format=json. - Process Diagnostics:
- Parses the JSON output from
cargo check. - Identifies errors and warnings.
- Determines if any spans within a diagnostic point to third-party source files.
- Collects details about these "implicated files" and the diagnostics that reference them.
- Parses the JSON output from
- Extract from Implicated Files:
- For each unique third-party source file identified,
getdocreads and parses its content. - It extracts definitions and doc comments for various Rust items (structs, functions, impl blocks and their contents, etc.).
- For each unique third-party source file identified,
- Generate Report: Compiles all collected diagnostics and extracted source code information into
report.md.
Usage
-
Make sure you have Rust and Cargo installed.
-
Install
getdoc(e.g.,cargo install getdocorcargo install --path .if building from local source). -
Navigate to your Rust project's root directory (the one containing
Cargo.toml). -
Run
getdocfrom that directory:-
For a comprehensive analysis (default behavior):
getdocThis will check a broad set of feature combinations based on your
Cargo.toml. -
For a targeted analysis focusing on specific features: Use the
--featuresflag with a comma-separated list of feature names. This is useful when the calling environment (e.g., a CI matrix leg) is already configured for these specific features.# Example for a single context feature getdoc --features my_specific_feature # Example for multiple related context features getdoc --features my_feature,another_featuregetdocwill then run a focused set ofcargo checkcommands relevant tomy_specific_feature(andanother_feature).
-
-
After execution, a
report.mdfile will be generated in your project's root directory.
The tool prints progress to the console (e.g., [getdoc] Starting analysis..., [getdoc] Running cargo check ...).
Output
The report.md file will contain:
- A header with the report generation timestamp and an indication of the analysis mode (Comprehensive or Targeted, including specified features if any).
- A section for "Compiler Output (Errors and Warnings)", detailing issues per feature combination, including error code explanations where available.
- Sections for each implicated third-party file ("From File: ..."), showing:
- Which local diagnostics referenced this file.
- Extracted items (structs, functions, traits, impls, etc.) from that file, including their signatures and doc comments.
This allows you to see the error, the compiler's explanation, and the relevant parts of the third-party code all in one place.
Dependencies
~3–11MB
~111K SLoC