Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Metadata V15: Expose pallet documentation #13452

Merged
merged 10 commits into from
Mar 13, 2023
Merged

Conversation

lexnv
Copy link
Contributor

@lexnv lexnv commented Feb 23, 2023

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:

#[pallet::pallet]
/// Documentation for pallet 1
#[doc = "Documentation for pallet 2"]
#[doc = include_str!("../README.md")]
#[pallet_doc("../doc1.md")]
#[pallet_doc("../doc2.md")]
pub struct Pallet<T>(_);

The runtime metadata for this pallet contains the following

  • " Documentation for pallet 1" (captured from ///)
  • "Documentation for pallet 2" (captured from #[doc])
  • content of ../README.md (captured from #[doc] with include_str!)
  • content of "../doc1.md" (captured from pallet_doc)
  • content of "../doc1.md" (captured from pallet_doc)

doc attribute

The value of the doc attribute is included in the runtime metadata, as well as
expanded on the pallet module. The previous example is expanded to:

/// Documentation for pallet 1
/// Documentation for pallet 2
/// Content of README.md
pub struct Pallet<T>(_);

pallet_doc attribute

The 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 the proc_macro attribute is
not inserted at the beginning of the module.

Testing Done

Besides the unit-test and UI tests from this patch:

    index: 36,
    docs: [
        "# Assets Module\n\nA simple, secure module ...",
        " Hello",
    ],

Part of #12939.
Closes paritytech/frame-metadata#47.

// CC @paritytech/tools-team

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@lexnv lexnv added A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit B1-note_worthy Changes should be noted in the release notes T1-runtime This PR/Issue is related to the topic “runtime”. labels Feb 23, 2023
@lexnv lexnv self-assigned this Feb 23, 2023
@lexnv lexnv requested a review from bkchr March 3, 2023 17:05
@lexnv
Copy link
Contributor Author

lexnv commented Mar 6, 2023

bot rebase

@paritytech-processbot
Copy link

Rebased

Copy link
Contributor

@sam0x17 sam0x17 left a 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 <alexandru.vasile@parity.io>
Copy link
Contributor

@sam0x17 sam0x17 left a 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
Copy link
Member

@niklasad1 niklasad1 Mar 10, 2023

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... :)

Copy link
Contributor Author

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 for proc_macro::Span inspection APIs rust-lang/rust#54725)

lexnv and others added 2 commits March 13, 2023 14:20
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@lexnv lexnv merged commit 959c5b6 into master Mar 13, 2023
@lexnv lexnv deleted the lexnv/md15_pallet_docs_metadata branch March 13, 2023 19:02
/// #[doc = include_str!("../README.md")]
/// #[pallet_doc("../documentation1.md")]
/// #[pallet_doc("../documentation2.md")]
/// pub mod pallet {}
Copy link
Member

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,

Copy link
Contributor Author

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 🙏

@Polkadot-Forum
Copy link

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

ukint-vs pushed a commit to gear-tech/substrate that referenced this pull request Apr 10, 2023
* frame/proc: Helpers to parse pallet documentation attributes

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

* frame/proc: Expand pallet with runtime metadata documentation

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

* frame/dispatch: Implement doc function getter for dispatch

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

* frame/tests: Check exposed runtime metadata documentation

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

* frame/tests: Add UI tests for `pallet_doc` attribute

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

* frame/proc: Document pallet_doc attribute

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

* frame/support: Use `derive_syn_parse`

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

* Update frame/support/procedural/src/lib.rs

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* frame/support: Improve documentation

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

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: parity-processbot <>
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
@Polkadot-Forum
Copy link

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

nathanwhit pushed a commit to nathanwhit/substrate that referenced this pull request Jul 19, 2023
* frame/proc: Helpers to parse pallet documentation attributes

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

* frame/proc: Expand pallet with runtime metadata documentation

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

* frame/dispatch: Implement doc function getter for dispatch

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

* frame/tests: Check exposed runtime metadata documentation

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

* frame/tests: Add UI tests for `pallet_doc` attribute

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

* frame/proc: Document pallet_doc attribute

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

* frame/support: Use `derive_syn_parse`

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

* Update frame/support/procedural/src/lib.rs

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* frame/support: Improve documentation

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

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: parity-processbot <>
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit T1-runtime This PR/Issue is related to the topic “runtime”.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Accessing Pallet Documentation
5 participants