This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Pallet dispatchable+storage doc module. #13341
Merged
Merged
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
92ba294
doc-only pallet
kianenigma 301547b
cargo fmt
sam0x17 df6f60f
generics fix for dispatchables
sam0x17 6e77074
use a module instead
sam0x17 ad09c26
add doc comment warning that the dispatchable functions are generated
sam0x17 0701431
clean up
sam0x17 725bed1
fix typo
sam0x17 3bd7e4e
hide Instance4-Instance16 from `pallet` module docs
sam0x17 ad4bc3f
revamp Instance1-16 comment
sam0x17 2d91eb3
Document storage types
ggwpez 4b10fe0
fmt
ggwpez 09ec374
remove unused variables
sam0x17 4cf61b2
crate::Call => Call
sam0x17 15a6536
fix indentation
sam0x17 0edcb1b
remove unneeded block
sam0x17 329b8d2
don't need a Vec
sam0x17 70dd550
add "doc only" to coment
sam0x17 9a4d2d0
crate::Call => Call
sam0x17 7c4f2b4
cargo fmt
sam0x17 3da9291
Merge remote-tracking branch 'origin/master' into doc-macro
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // This file is part of Substrate. | ||
|
|
||
| // Copyright (C) 2023 Parity Technologies (UK) Ltd. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| use proc_macro2::Span; | ||
|
|
||
| use crate::pallet::Def; | ||
|
|
||
| pub fn expand_doc_only(def: &mut Def) -> proc_macro2::TokenStream { | ||
| let storage_names = &def.storages.iter().map(|storage| &storage.ident).collect::<Vec<_>>(); | ||
| let storage_docs = &def.storages.iter().map(|storage| &storage.docs).collect::<Vec<_>>(); | ||
| let dispatchables = { | ||
sam0x17 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if let Some(call_def) = &def.call { | ||
| let type_impl_generics = def.type_impl_generics(Span::call_site()); | ||
| call_def | ||
| .methods | ||
| .iter() | ||
| .map(|method| { | ||
| let name = &method.name; | ||
| let args = &method | ||
| .args | ||
| .iter() | ||
| .map(|(_, arg_name, arg_type)| quote::quote!( #arg_name: #arg_type, )) | ||
| .collect::<proc_macro2::TokenStream>(); | ||
| let docs = &method.docs; | ||
| let line_2 = format!( | ||
| " designed to document the [`{}`][`crate::Call::{}`] variant of", | ||
sam0x17 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name, name | ||
| ); | ||
| quote::quote!( | ||
| #( #[doc = #docs] )* | ||
| /// | ||
| /// --- | ||
| /// | ||
| /// NOTE: This function is an automatically generated, uncallable stub | ||
sam0x17 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #[ doc = #line_2 ] | ||
| /// the pallet [`Call`](`crate::Call`) enum. You should not attempt to | ||
sam0x17 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// call this function directly. | ||
| pub fn #name<#type_impl_generics>(#args) { unreachable!(); } | ||
| ) | ||
| }) | ||
| .collect::<proc_macro2::TokenStream>() | ||
| } else { | ||
| quote::quote!() | ||
| } | ||
| }; | ||
sam0x17 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| quote::quote!( | ||
| /// Auto-generated docs-only module listing all defined storage types for this pallet. | ||
| /// Note that members of this module cannot be used directly and are only provided for | ||
| /// documentation purposes. | ||
| #[cfg(doc)] | ||
| pub mod storage_types { | ||
| use super::*; | ||
| #( | ||
| #( #[doc = #storage_docs] )* | ||
| pub struct #storage_names(); | ||
| )* | ||
| } | ||
|
|
||
| /// Auto-generated docs-only module listing all defined dispatchables for this pallet. | ||
| /// Note that members of this module cannot be used directly and are only provided for | ||
| /// documentation purposes. | ||
| #[cfg(doc)] | ||
| pub mod dispatchables { | ||
| use super::*; | ||
| #dispatchables | ||
| } | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.