Expand description
Error-catalog extractor: build an LLM-facing catalog of every diagnostic emitted by the workspace, straight from rustdoc JSON.
§Consumer contract (zero coupling)
Consumer crates need no dependency on cargo-aidoc. To have a
struct or enum picked up as an error entry, the crate simply:
- Derives
miette::Diagnosticon the type (already the de facto Rust standard for structured diagnostics). - Passes
code(...)inside#[diagnostic(...)].help(...)andurl(...)are optional but recommended — they land verbatim in the catalog output. - Optionally embeds fenced code blocks in the type’s doc comment
with a
code=<CODE>tag in the info-string, e.g.```ebp,code=EBP001or```ebp,code=EBP001,fix. Any fence whose info-string containscode=<this-entry's-code>is collected as a snippet under that entry.
This mirrors the docs.rs bridge model: cargo-aidoc is the reader,
consumers only ever emit information that already lives in their
rustdoc JSON. A future Layer 2 (aidoc-attrs) can add opt-in
#[aidoc::...] attributes gated behind #[cfg_attr(aidoc, ...)]
for cases miette doesn’t cover, without changing this contract.
§Extraction pipeline
extract walks every crate in the workspace, and for each rustdoc
item whose attrs contain a #[diagnostic(...)] line, produces one
ErrorEntry. Entries are sorted by their code for deterministic
output.
The attribute parser (parse_diagnostic_attr) accepts the exact
literal form rustdoc emits — including the \n that rustdoc inserts
after commas inside the attribute — but is intentionally a
hand-rolled string reader, not a proc-macro / syn parser. The
surface area we care about is small (code(NAME) / help("...") /
url("...")), and pulling in syn at this layer would drag in a
large dependency tree for very little payoff.
§What is covered
- Struct-level
#[diagnostic(code(...), ...)]— one entry per struct. - Enum-level
#[diagnostic(code(...), ...)]— one entry per enum (rare; miette allows at most one code per enum). - Per-variant
#[diagnostic(code(...), ...)]on enum variants — one entry per catalogued variant. This is the dominantthiserror + mietteshape and is what most real crates use; seetry_build_entryand the walk driven bywalk_enum_variants.
§Not covered by MVP
- Variant-level
source_code/label/relatedmetadata from miette is intentionally not surfaced yet — those are runtime-facing, not spec-facing. - Non-miette diagnostic frameworks (bevy_error, custom derives)
would need their own attr shape; the extractor is written so
another parser can be added alongside
parse_diagnostic_attrwithout touching the walk.
Structs§
- Error
Entry - One catalogued diagnostic: everything cargo-aidoc knows about a single error code, sourced from a single item in the workspace.
- Snippet
- A fenced code block extracted from an error’s doc comment.
Functions§
- extract
- Walk the workspace and produce every catalogued diagnostic.