codegen: resolve AIP-192 cross-references to intra-doc links (#26)#94
Conversation
Doc comments in generated Rust code now translate AIP-192 cross-references ([Book][google.example.v1.Book], [Book][], [Genre.GENRE_SCI_FI]) into rustdoc intra-doc links. Unknown or extern-crate references fall back silently to escaped literals. Keyword segments in proto package names (e.g. google.type) are escaped with r# so the links are valid under -D rustdoc::broken_intra_doc_links. Closes anthropics#26
|
All contributors have signed the CLA ✍️ ✅ |
|
[claude code] Thanks for taking this on - the overall design here is right, and the conservative escape-fallback contract is exactly what #26 asked for. The keyword-segment escaping ( Two changes before merge, plus some smaller polish items below. 1. Drop
|
- Drop Type.member resolution from resolve_proto_ref; member refs fall back to escaped literals until member existence can be verified against descriptor info. Removes test_resolve_proto_ref_enum_value and test_resolve_proto_ref_field; adds negative test asserting member refs return None. - Fix doubled doc comment on escape_angle_brackets. - Pass enclosing proto_fqn (not element FQN) as scope_fqn at all call sites in message.rs, enumeration.rs, oneof.rs, and view.rs. - Clarify is_extern_path doc comment with the actual crate::crate::... mangling reason; restore context.rs cross-reference. - Update doc_attrs_resolved and resolve_proto_ref doc comments to reflect the enclosing-type scope_fqn contract. - Update CHANGELOG to say type-level refs only.
|
All items addressed, ready for re-review. |
iainmcgin
left a comment
There was a problem hiding this comment.
[claude code] All four flagged items addressed in 762dc4dc:
- ✅
Type.memberresolution dropped fromresolve_proto_ref; the two member-ref tests replaced with a negative test pinning the new behaviour. CHANGELOG scoped to type-level refs only. - ✅ Doubled doc comment on
escape_angle_bracketsfixed. - ✅
scope_fqnis now the enclosing-type FQN at all four call sites;doc_attrs_resolved/resolve_proto_refdocs updated to state the contract. - ✅
is_extern_pathdoc comment now explains the actualcrate::crate::...mangling reason.
Verified locally on the PR head: cargo test -p buffa-codegen passes (346 tests), task gen-wkt-types produces no diff, RUSTDOCFLAGS=-D warnings cargo doc -p buffa-types builds clean, clippy clean.
The four advisory items (extra find_ref_link cases, direct escape_angle_brackets tests, shared is_extern_path helper, implied-form display shortening) weren't taken — that's fine, they were marked optional. Happy to see those as follow-ups if you're interested.
Thanks for the quick turnaround — merging.
Closes #26.
Proto comments often reference other types using AIP-192 syntax —
[Book][google.example.v1.Book],[Book][],[Genre.GENRE_SCI_FI]— butthe generated Rust doc comments were emitting escaped literals instead of
rustdoc intra-doc links, making the cross-references unclickable.
Problem
doc_attrspassed comment text through a sanitizer that escaped[and]uniformly. There was no awareness of AIP-192 reference syntax, so
[Book][google.example.v1.Book]became\[Book\]\[google.example.v1.Book\]in the output — a dead literal rather than a navigable link.
Fix
The sanitizer now recognises
[display][ref]and[display][]patterns andattempts to resolve them against the codegen type map (the same
HashMap<String, String>that maps proto FQNs to Rust paths). Resolutionwalks proto lexical scoping: it tries the fully-qualified key first, then
strips scope segments one at a time. A successful hit emits
[display](crate::rust::path); an unresolvable or extern-crate ref fallsback silently to the escaped literal so downstream
-D warningsbuilds arenot broken.
Rust keyword segments in proto package names (e.g.
google.type) are escapedwith
r#before the path is embedded in the doc string, so[LatLng](crate::google::r#type::LatLng)is emitted rather than the invalidcrate::google::type::LatLng.Inline Markdown links
[text](url)and backtick code spans are leftuntouched.
<and>in display text are escaped outside code spans tosatisfy
rustdoc::invalid_html_tags.Call sites in
message.rs,enumeration.rs,view.rs, andoneof.rswereupdated to pass
scope_fqnand the type map through to the newdoc_attrs_resolved/doc_attrs_with_tag_resolvedfunctions.Tests
Unit tests in
buffa-codegen/src/tests/comments.rscover fully-qualifiedresolution, implied-form
[Book][], unresolvable fallback, extern-cratesuppression, keyword-segment escaping, and angle-bracket handling inside
backtick spans. The
resolve_type_fqnandresolve_proto_refhelpers havededicated unit tests for scope-walking, enum-value member refs, and
crate::-prefixed extern paths.Regenerated
buffa-types/src/generated/google.protobuf.any.rsand its view variant wereregenerated. The
Durationcross-reference inAny's doc comment nowresolves to
[google.protobuf.Duration](crate::google::protobuf::Duration).