Propagate documentation to runtime API (#511)

* codegen: Propagate documentation for Constants

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* subxt: Update polkadot.rs

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Propagate documentation for `CompositeDef` wrapper

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* subxt: Update polkadot.rs

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Propagate docs for enum variant of `CompositeDef` wrapper

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* subxt: Update polkadot.rs

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Propagate docs for Storage entries

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* subxt: Update polkadot.rs

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Move docs from internal structs to methods of StorageApi

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Propagate the same docs for storage iter variants

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Move docs from call structs to methods of TransactionApi

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* subxt: Update polkadot.rs

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2022-04-21 11:06:17 +03:00
committed by GitHub
parent e0439c91ab
commit 698f0242f3
7 changed files with 7978 additions and 228 deletions
+15 -1
View File
@@ -45,6 +45,8 @@ pub struct CompositeDef {
pub kind: CompositeDefKind,
/// The fields of the type, which are either all named or all unnamed.
pub fields: CompositeDefFields,
/// Documentation of the composite type as presented in metadata.
pub docs: Option<TokenStream>,
}
impl CompositeDef {
@@ -55,6 +57,7 @@ impl CompositeDef {
fields_def: CompositeDefFields,
field_visibility: Option<syn::Visibility>,
type_gen: &TypeGenerator,
docs: &[String],
) -> Self {
let mut derives = type_gen.derives().clone();
let fields: Vec<_> = fields_def.field_types().collect();
@@ -85,6 +88,7 @@ impl CompositeDef {
}
let name = format_ident!("{}", ident);
let docs_token = Some(quote! { #( #[doc = #docs ] )* });
Self {
name,
@@ -94,16 +98,23 @@ impl CompositeDef {
field_visibility,
},
fields: fields_def,
docs: docs_token,
}
}
/// Construct a definition which will generate code for an `enum` variant.
pub fn enum_variant_def(ident: &str, fields: CompositeDefFields) -> Self {
pub fn enum_variant_def(
ident: &str,
fields: CompositeDefFields,
docs: &[String],
) -> Self {
let name = format_ident!("{}", ident);
let docs_token = Some(quote! { #( #[doc = #docs ] )* });
Self {
name,
kind: CompositeDefKind::EnumVariant,
fields,
docs: docs_token,
}
}
}
@@ -111,6 +122,7 @@ impl CompositeDef {
impl quote::ToTokens for CompositeDef {
fn to_tokens(&self, tokens: &mut TokenStream) {
let name = &self.name;
let docs = &self.docs;
let decl = match &self.kind {
CompositeDefKind::Struct {
@@ -130,6 +142,7 @@ impl quote::ToTokens for CompositeDef {
quote! {
#derives
#docs
pub struct #name #type_params #fields #trailing_semicolon
}
}
@@ -137,6 +150,7 @@ impl quote::ToTokens for CompositeDef {
let fields = self.fields.to_enum_variant_field_tokens();
quote! {
#docs
#name #fields
}
}
+2 -1
View File
@@ -90,6 +90,7 @@ impl<'a> TypeDefGen<'a> {
fields,
Some(parse_quote!(pub)),
type_gen,
ty.docs(),
);
TypeDefGenKind::Struct(composite_def)
}
@@ -107,7 +108,7 @@ impl<'a> TypeDefGen<'a> {
);
type_params.update_unused(fields.field_types());
let variant_def =
CompositeDef::enum_variant_def(v.name(), fields);
CompositeDef::enum_variant_def(v.name(), fields, v.docs());
(v.index(), variant_def)
})
.collect();