-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Metadata V15: Expose pallet documentation #13452
Conversation
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
bot rebase |
Rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, nice UI tests!
Signed-off-by: Alexandru Vasile <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
/// pub struct Pallet<T>(_); | ||
/// ``` | ||
/// | ||
/// ### `pallet_doc` attribute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basti wrote
we probably should settle with having on #![doc = include_str!("../README.md")] at the top of lib.rs and then some special pallet_docs("../README.md") attribute for the frame macros (otherwise the docs would be duplicated in the crate).
Personally, I don't understand that by the documentation in this PR. Can you elaborate a bit why both doc
and pallet_doc
are needed in the examples or something.
It could be just me though... :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that makes sense! I've improved the documentation a bit to clarify the attributes.
From a discussion with @bkchr it would be beneficial to have:
- the ability to document the module individually and propagate that to the metadata (via doc attribute)
- the ability to only propagate documentation to the metadata only (via pallet_doc)
- for these cases developers may use
include_str!()
at the top of the file without having to duplicate the documentation itself pallet_doc
attribute gives developers enough control until we can deduce the file from which a macro is invoked, and not the compile time location at which the macro is declared (Tracking issue forproc_macro::Span
inspection APIs rust-lang/rust#54725)
- for these cases developers may use
Co-authored-by: Niklas Adolfsson <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
/// #[doc = include_str!("../README.md")] | ||
/// #[pallet_doc("../documentation1.md")] | ||
/// #[pallet_doc("../documentation2.md")] | ||
/// pub mod pallet {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you mention that the docs are above the module
and above the pallet attribute macro you are mentioning that the docs need to be above the struct Pallet
,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spotting this! I've picked the pub mod pallet
to be consistent between documentations and pushed the commit here 🙏
This pull request has been mentioned on Polkadot Forum. There might be relevant details there: https://forum.polkadot.network/t/polkadot-release-analysis-v0-9-40/2468/1 |
* frame/proc: Helpers to parse pallet documentation attributes Signed-off-by: Alexandru Vasile <[email protected]> * frame/proc: Expand pallet with runtime metadata documentation Signed-off-by: Alexandru Vasile <[email protected]> * frame/dispatch: Implement doc function getter for dispatch Signed-off-by: Alexandru Vasile <[email protected]> * frame/tests: Check exposed runtime metadata documentation Signed-off-by: Alexandru Vasile <[email protected]> * frame/tests: Add UI tests for `pallet_doc` attribute Signed-off-by: Alexandru Vasile <[email protected]> * frame/proc: Document pallet_doc attribute Signed-off-by: Alexandru Vasile <[email protected]> * frame/support: Use `derive_syn_parse` Signed-off-by: Alexandru Vasile <[email protected]> * Update frame/support/procedural/src/lib.rs Co-authored-by: Niklas Adolfsson <[email protected]> * frame/support: Improve documentation Signed-off-by: Alexandru Vasile <[email protected]> --------- Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: parity-processbot <> Co-authored-by: Niklas Adolfsson <[email protected]>
This pull request has been mentioned on Polkadot Forum. There might be relevant details there: https://forum.polkadot.network/t/stablising-v15-metadata/2819/1 |
* frame/proc: Helpers to parse pallet documentation attributes Signed-off-by: Alexandru Vasile <[email protected]> * frame/proc: Expand pallet with runtime metadata documentation Signed-off-by: Alexandru Vasile <[email protected]> * frame/dispatch: Implement doc function getter for dispatch Signed-off-by: Alexandru Vasile <[email protected]> * frame/tests: Check exposed runtime metadata documentation Signed-off-by: Alexandru Vasile <[email protected]> * frame/tests: Add UI tests for `pallet_doc` attribute Signed-off-by: Alexandru Vasile <[email protected]> * frame/proc: Document pallet_doc attribute Signed-off-by: Alexandru Vasile <[email protected]> * frame/support: Use `derive_syn_parse` Signed-off-by: Alexandru Vasile <[email protected]> * Update frame/support/procedural/src/lib.rs Co-authored-by: Niklas Adolfsson <[email protected]> * frame/support: Improve documentation Signed-off-by: Alexandru Vasile <[email protected]> --------- Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: parity-processbot <> Co-authored-by: Niklas Adolfsson <[email protected]>
This patch captures the pallet documentation declared on the pallet module.
The documentation added to this pallet is later on included in the runtime metadata.
The documentation can be defined in the following ways:
The runtime metadata for this pallet contains the following
///
)#[doc]
)#[doc]
withinclude_str!
)pallet_doc
)pallet_doc
)doc
attributeThe value of the
doc
attribute is included in the runtime metadata, as well asexpanded on the pallet module. The previous example is expanded to:
pallet_doc
attributeThe
pallet_doc
attribute can only be provided with one argument,which is the file path that holds the documentation to be added to the metadata.
Unlike the
doc
attribute, the documentation provided to theproc_macro
attribute isnot inserted at the beginning of the module.
Testing Done
Besides the unit-test and UI tests from this patch:
Part of #12939.
Closes paritytech/frame-metadata#47.
// CC @paritytech/tools-team