-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accessing Pallet Documentation #47
Comments
You mean the documentation of the crate itself? |
Correct |
We can not pull this into the metadata. The macros don't have access to this. |
The macros don't have access to this at the moment, but perhaps they could be given access? E.g. #[frame_support::pallet]
#[doc = include_str!("../README.md")]
pub mod pallet {
...
} If I'm not mistaken, this would both attach docs to the pallet module from rust's perspective as well as give the |
These docs would then be on top of the module and these docs could already be read right now by the macro. |
Does this mean that we have a path forward? |
No, because the docs are at the crate level or at the file level. These docs are never above the pallet module. We also just add this pallet module for shortcommings in rust proc macros. In general people would like more to have the other direction, aka less docs in the metadata and not more. |
I suspect that people don't want "less docs in the metadata" so much as they want "doc-less metadata". And this makes perfect sense – if you don't have a use for the docs, they're needless bloat. But if you are using the docs, you want to have as much of the docs as possible, and adding pallet-level docs will not add much bloat compared to the size of the type docs. If people would like to have doc-less metadata (which I think is definitely desirable), it should be an option – i.e. chains should expose metadata with and without docs. Those who do not want docs can request the metadata sans docs, but those who need the docs can request the full metadata. Having docs in the metadata is very important for external tools which consume the metadata to display to developers, be it a documentation site for chain apis, in language-level doc comments in codegen, etc.
Yes, the docs are at the crate level or at the file level right now. We can put these docs above the pallet module easily with #[doc = include_str!("../README.md")]
Then it shouldn't be a problem to add a doc comment to this pallet module to address another shortcoming in rust proc macros – that they can't access the crate's docs by default. |
After some discussion with @harrysolovay I'm fine to go forward with this. At least to find out how a possible solution could look like and if we may find out certain issues along the way. |
Substrate exposes code documentation at the crate level and/or at the file level (either by Considering the following pallets:
We would need a standardized way to handle pallet code documentation and pallet metadata documentation. Pallet Metadata DocumentationI'd like to propose that pallet metadata documentation is collected only from the pallet's module. #[frame_support::pallet]
#[doc = include_str!("../README.md")]
/// Maybe we need to describe another detail here.
#[doc = "Similar format"]
pub mod pallet {
...
} Pallet Code DocumentationDevelopers have the choice to place "internal" code documentation on Let me know what you think of it! // CC @kianenigma @bkchr |
IMO there should not exist 1000 ways to document your pallet. There should be one that then works for docs.rs and the metadata. There is also this issue in Substrate: paritytech/substrate#13299 which is about streamlining the pallet docs and to remove stuff like what kind of |
BTW, today I a crazy idea: https://github.com/livioribeiro/cargo-readme This is some tool to extract the crate docs as Readme, basically what we are trying to do here. But maybe too crazy. |
Thats pretty cool! It seems to extract the documentation from the We could probably achieve the same result with a few lines of code: let file = File::open("src/main.rs").expect("failed to read source");
let reader = BufReader::new(file);
let lines: Vec<_> = reader
.lines()
.filter_map(|line| {
line.ok()
.and_then(|line| line.strip_prefix("//!").map(|l| l.trim().to_string()))
})
.collect(); Coming back to this:
The first approach seems simpler ofhand, would love you hear your thoughts @bkchr 🙏 |
One thing that is currently missing in your thoughts is that we also support multiple pallets per crate. This is for example the case in Polkadot. So, we can not just put the So for now we probably still need to stick to the current approach of declaring the README manually. |
Cool! Thanks for the info! That being said, the initial ideas are implemented at: paritytech/substrate#13452. |
Pallet metadata does not contain associated documentation while the metadata of other types does. I'm guessing this is for the sake of reducing the size of the metadata... nevertheless: there does not seem to be a standard way for a developer to retrieve pallet documentation.
The text was updated successfully, but these errors were encountered: