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

Improve documentation for fast-unstake pallet #14101

Merged
merged 41 commits into from
May 29, 2023

Conversation

kianenigma
Copy link
Contributor

@kianenigma kianenigma commented May 9, 2023

This is my effort to try and improve the documentation of a single pallet, in order to identify some patters that we can try and enforce across all pallets. Most of my efforts was around making the experience of navigating the rust-docs better.

Should close #13299 with collaboration with @ggwpez
relates to paritytech/polkadot-sdk-docs#1
Should go hand-in-hand with #13987 which is improving some macros to improve storage docs.

Some of the things that I have done in macros:

  • Add an auto-generated doc inside mod pallet that tells you where you should go. This can also live in the top level file, perhaps, but then we have to repeat it all the time.
  • Call docs now point to the right Pallet function.
  • everything in mod dispatchables also points to Pallet. Both of these is to establish the fact that the "real thing" is the method defined on Pallet.
  • For storage types, similar rule holds in mod storage_types, but if the storage is private, we copy-paste the doc over.
  • Similarly, for getters, if the storage is public, we link to it, else, we copy-paste the doc over.
  • Showcase how to write at least a few tests that go into the top level doc of a pallet.
  • Inject a doc-line to each storage type, showcasing its type and keys and so on.
  • showcase a new frame_support::testing_prelude that can be used.
Screenshot 2023-05-11 at 21 09 17 Screenshot 2023-05-11 at 21 09 06 Screenshot 2023-05-11 at 21 08 53

@kianenigma kianenigma marked this pull request as ready for review May 9, 2023 10:42
@kianenigma kianenigma requested review from a team, sam0x17 and ggwpez May 9, 2023 10:42
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.

This looks great, let me push out another version of docify that uses the original span locations so we get exact source text and then should be good RE your issue you showed me of comments not copying over. Will also remove the need for prettyplease dependency

@liamaharon liamaharon self-requested a review May 9, 2023 15:31
frame/fast-unstake/src/lib.rs Show resolved Hide resolved
frame/fast-unstake/src/lib.rs Outdated Show resolved Hide resolved
frame/fast-unstake/src/lib.rs Outdated Show resolved Hide resolved
frame/fast-unstake/src/lib.rs Show resolved Hide resolved
@liamaharon liamaharon removed their request for review May 10, 2023 06:38
@kianenigma kianenigma requested a review from a team May 10, 2023 08:21
frame/fast-unstake/src/lib.rs Outdated Show resolved Hide resolved
frame/fast-unstake/src/lib.rs Outdated Show resolved Hide resolved
frame/fast-unstake/src/lib.rs Outdated Show resolved Hide resolved
frame/support/procedural/src/pallet/expand/mod.rs Outdated Show resolved Hide resolved
frame/support/procedural/src/pallet/expand/storage.rs Outdated Show resolved Hide resolved
kianenigma and others added 5 commits May 10, 2023 10:59
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
…/substrate into kiz-improve-fast-unstake-dcos
kianenigma and others added 2 commits May 10, 2023 19:24
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
@paritytech-ci paritytech-ci requested a review from a team May 23, 2023 08:29
@sam0x17
Copy link
Contributor

sam0x17 commented May 23, 2023

btw, also planning on doing a thing eventually that by default will make it so you don't have to write #[docify::export] unless you need to specify a disambiguation name. This will also coincide with me properly resolving module paths within a file, so you'll be able to do docify::embed!("my/path.rs", some::path::to::MyItem) and it will resolve correctly. It just means I will have to modify my visitor pattern to be aware of what submodules it is in within a file

The main components of this pallet are:
- [`Pallet`], which implements all of the dispatchable extrinsics of the pallet, among
other public functions.
- The subset of the functions that are dispatchable can be identified either in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- The subset of the functions that are dispatchable can be identified either in
- The subset of the functions that are dispatchable can be identified either in

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be an indented list, why are you suggesting otherwise?

frame/support/procedural/src/pallet/expand/doc_only.rs Outdated Show resolved Hide resolved
frame/support/procedural/src/pallet/expand/config.rs Outdated Show resolved Hide resolved
frame/support/procedural/src/pallet/expand/config.rs Outdated Show resolved Hide resolved
//!
//! ## Overview
//!
//! This pallet that's designed to JUST do the following:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! This pallet that's designed to JUST do the following:
//! This pallet is designed to JUST do the following:

Although TBH I'm not sure what purpose this line serves, can it be removed?

Also, since we are improving the docs: I feel like the text that follows could use some structure, e.g. subsections or bullet points. Right now it seems (to me) like an unapproachable wall of text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find your comment about this sentence fair, but not the rest. It is organized into a series of paragraphs and is following a logical chain. Perhaps if you describe further which part of it is unapprochable, I can improve.

Nonetheless though, this is in realm of subjective measures harder to align on. I don't think we can ever make everyone write docs that are understandable to everyone. Simply things like different ways of thinking and language levels will make that impossible.

What we want to ensure is at least following the structure mentioned in #14115, and doing your best.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, it was indeed a subjective impression I got as someone new to this pallet. Reading my post again it sounds more critical than I intended it to be, sorry. 🙈 To be concrete, I would suggest adding subsections like e.g. "Registration" and "Checking". Feel free to ignore if you think that's unnecessary. The new docs are already awesome as is!

kianenigma and others added 5 commits May 28, 2023 10:40
Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>
Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>
Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>
…/substrate into kiz-improve-fast-unstake-dcos
@sam0x17
Copy link
Contributor

sam0x17 commented May 28, 2023

docify 0.1.11 should fix the termcolor issue

@kianenigma
Copy link
Contributor Author

bot rebase

@paritytech-processbot
Copy link

Rebased

@kianenigma
Copy link
Contributor Author

bot merge

@paritytech-processbot
Copy link

Waiting for commit status.

@paritytech-processbot
Copy link

Merge cancelled due to error. Error: Statuses failed for 351ee05

@@ -1520,6 +1520,17 @@ pub mod tests {
}
}

/// Prelude to be used for pallet testing, for ease of use.
#[cfg(feature = "std")]
pub mod testing_prelude {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to use the same naming in #13454?

@kianenigma
Copy link
Contributor Author

bot merge

@paritytech-processbot paritytech-processbot bot merged commit e5670d2 into master May 29, 2023
@paritytech-processbot paritytech-processbot bot deleted the kiz-improve-fast-unstake-dcos branch May 29, 2023 17:44
nathanwhit pushed a commit to nathanwhit/substrate that referenced this pull request Jul 19, 2023
* improve documentation of fast-unstake pallet

* using Sam's crate now

* fix

* remove stuff not needed

* Some updates

* use new prelude.

* update

* some other fancy docs

* Update frame/fast-unstake/src/lib.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update frame/support/procedural/src/pallet/expand/mod.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* update

* Update frame/fast-unstake/src/lib.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* update

* fix no_std issue by updating to latest version of docify

* get things compiling by adding a use for StakingInterface

* fix docify paths to their proper values, still not working because bug

* embed working 🎉

* update syn

* upgrade to docify v0.1.10 for some fixes

* Apply suggestions from code review

Co-authored-by: Juan <juangirini@gmail.com>
Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>

* improve docs

* Update frame/support/procedural/src/pallet/expand/doc_only.rs

Co-authored-by: Juan <juangirini@gmail.com>

* fmt

* fix

* Update frame/support/procedural/src/pallet/expand/doc_only.rs

Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>

* Update frame/support/procedural/src/pallet/expand/config.rs

Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>

* Update frame/support/procedural/src/pallet/expand/config.rs

Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>

* remove redundant

* update docify rev

* update.

* update.

* update lock file

---------

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: Sam Johnson <sam@durosoft.com>
Co-authored-by: Juan <juangirini@gmail.com>
Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>
Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>
Co-authored-by: parity-processbot <>
@@ -310,6 +311,65 @@ pub fn process_generics(def: &mut Def) -> syn::Result<Vec<ResultOnEmptyStructMet
Ok(on_empty_struct_metadata)
}

fn augment_final_docs(def: &mut Def) {
Copy link
Member

@ggwpez ggwpez Aug 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kianenigma this actually prevents #[deny(missing_docs)] from working correctly for storage items, since they now always have a default doc comment.
We could only do this if there is already a comment, or always emit a warning when there is not doc. WDYT?

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. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

☂️ Formalize Pallet and Call docs
9 participants