Skip to content

Commit 1d42660

Browse files
authored
AI-generate implementation documentation (#247)
* Scaffold initial implementation docs * Generate remaining impl docs * Use bullet points for source and tests sections
1 parent 09a9f6e commit 1d42660

163 files changed

Lines changed: 3557 additions & 107 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/macros/cgp-macro-core/CLAUDE.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,13 @@ into the existing stage rather than collapsing the pipeline.
7878

7979
**5. Custom keywords go through `define_keyword!` + `IsKeyword`** (see
8080
[src/macros/keyword.rs](src/macros/keyword.rs) and `types/keyword*.rs`).
81+
82+
**6. Keep inline docs brief and current as you go.** When you review a file — whether to change it
83+
or to write its [implementation document](../../../docs/implementation/README.md) — improve the
84+
inline docs in the same pass. Add a one-line `///` to any public struct, trait, or function that
85+
lacks one, saying what it is or does (for a pipeline stage, its role in the sequence); prefer naming
86+
the *why* or a corner case over restating the signature. Fix a doc that no longer matches the code,
87+
and clarify genuinely confusing code (for example, why `generic_params_to_path` keeps only type
88+
parameters) with a short comment. Keep them terse: delete a comment that only restates obvious code,
89+
and do not narrate line by line. Deep mechanics belong in the implementation document, not in a wall
90+
of inline prose — link to it rather than duplicating it.

crates/macros/cgp-macro-core/src/functions/delegated_impls/provider_trait.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use syn::{ImplItem, ItemTrait, Type};
33
use crate::functions::trait_items_to_delegated_impl_items;
44
use crate::parse_internal;
55

6+
/// Forward a provider trait's own items to `delegate_type`, reconstructing the
7+
/// trait path from the trait itself (for impls whose trait *is* the provider trait).
68
pub fn provider_trait_to_impl_items(
79
item_trait: &ItemTrait,
810
delegate_type: &Type,

crates/macros/cgp-macro-core/src/functions/delegated_impls/trait_items.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::functions::{
77
parse_internal, signature_to_delegated_impl_item_fn, trait_to_impl_item_type,
88
};
99

10+
/// Build impl items that forward each trait item (method, associated type, or
11+
/// const) to `delegate_type`, projecting types/consts through `provider_trait_path`.
1012
pub fn trait_items_to_delegated_impl_items(
1113
trait_items: &[TraitItem],
1214
delegate_type: &Type,

crates/macros/cgp-macro-core/src/functions/is_provider_params.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ use crate::exports::Life;
66
use crate::parse_internal;
77
use crate::types::generics::TypeGenerics;
88

9+
/// Convert a trait's generics into the `Params` tuple types of an `IsProviderFor`
10+
/// bound: type params pass through, lifetimes are lifted into `Life<'a>`.
11+
///
12+
/// Panics on a const generic parameter — see the const-generic limitation in
13+
/// docs/implementation/entrypoints/cgp_component.md.
914
pub fn parse_is_provider_params(generics: &Generics) -> syn::Result<Punctuated<Type, Comma>> {
1015
let params = TypeGenerics::try_from(generics)?.generics.params;
1116

crates/macros/cgp-macro-core/src/functions/parse_internal.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use syn::{Error, parse2};
88
use crate::functions::strip_macro_prelude;
99
pub use crate::macros::parse_internal;
1010

11+
/// Parse a token stream into a `syn` type `T`, attaching an error that names both
12+
/// `T` and the offending tokens (prelude prefix stripped) on failure. Usually
13+
/// invoked through the `parse_internal!` macro.
1114
pub fn parse_internal<T>(body: TokenStream) -> Result<T, Error>
1215
where
1316
T: Parse,

crates/macros/cgp-macro-core/src/macros/keyword.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// Declare a custom-keyword marker: a zero-sized struct plus its `IsKeyword` impl
2+
/// carrying the keyword's spelling, which the parsers peek against.
13
#[macro_export]
24
macro_rules! define_keyword {
35
( $struct_ident:ident, $value:literal ) => {

crates/macros/cgp-macro-core/src/macros/parse.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/// Quasi-quote tokens and parse them into an inferred `syn` type via the
2+
/// `parse_internal` function. Expands to a `?` expression, so it must be called
3+
/// inside a `syn::Result`-returning function.
14
#[macro_export]
25
macro_rules! parse_internal {
36
( $($body:tt)* ) => {

crates/macros/cgp-macro-core/src/types/cgp_component/args/component_args.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use syn::{Error, Ident};
55
use crate::types::cgp_component::CgpComponentRawArgs;
66
use crate::types::ident::IdentWithTypeGenerics;
77

8+
/// The `#[cgp_component]` attribute args with defaults applied: the context type
9+
/// identifier (`__Context__` by default), the required provider trait name, and
10+
/// the component marker name (`{Provider}Component` by default).
811
#[derive(Clone)]
912
pub struct CgpComponentArgs {
1013
pub context_ident: Ident,

crates/macros/cgp-macro-core/src/types/cgp_component/args/raw.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ use syn::{Error, Ident};
44

55
use crate::types::ident::IdentWithTypeGenerics;
66

7+
/// The attribute args exactly as written, before defaults are applied. Parses
8+
/// either a bare provider identifier or the `key: value` form; [`CgpComponentArgs`]
9+
/// resolves the defaults via `TryFrom`.
710
#[derive(Default)]
811
pub struct CgpComponentRawArgs {
912
pub context_ident: Option<Ident>,

crates/macros/cgp-macro-core/src/types/cgp_component/evaluated/item.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use crate::types::cgp_component::CgpComponentArgs;
55
use crate::types::empty_struct::EmptyStruct;
66
use crate::types::provider_impl::{ItemProviderImpl, ItemProviderImpls};
77

8+
/// Final pipeline stage: all derived items, plus the args and attributes needed
9+
/// to render the standard provider impls (`UseContext`, `RedirectLookup`, and the
10+
/// per-attribute `UseDelegate`/prefix impls).
811
pub struct EvaluatedCgpComponent {
912
pub component_struct: EmptyStruct,
1013
pub consumer_trait: ItemTrait,
@@ -16,6 +19,8 @@ pub struct EvaluatedCgpComponent {
1619
}
1720

1821
impl EvaluatedCgpComponent {
22+
/// Emit the five core items in fixed order (consumer trait, consumer impl,
23+
/// provider trait, provider impl, marker struct), then the provider impls.
1924
pub fn to_items(&self) -> syn::Result<Vec<Item>> {
2025
let mut items = vec![
2126
Item::Trait(self.consumer_trait.clone()),
@@ -55,6 +60,7 @@ impl EvaluatedCgpComponent {
5560
Ok(provider_impls)
5661
}
5762

63+
/// One `UseDelegate` provider impl per `#[derive_delegate]` attribute.
5864
pub fn to_use_delegate_impls(&self) -> syn::Result<ItemProviderImpls> {
5965
let provider_trait = &self.provider_trait;
6066
let component_type = self.args.component_name.to_type();
@@ -71,6 +77,7 @@ impl EvaluatedCgpComponent {
7177
Ok(provider_impls)
7278
}
7379

80+
/// One namespace prefix impl per `#[prefix]` attribute (from `#[cgp_namespace]`).
7481
pub fn to_prefix_impls(&self) -> syn::Result<Vec<ItemImpl>> {
7582
let component_name = &self.args.component_name;
7683
let mut provider_impls = Vec::new();

0 commit comments

Comments
 (0)