Skip to content
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

bug: cannot export individual pallet calls #9

Closed
liamaharon opened this issue Sep 20, 2023 · 2 comments
Closed

bug: cannot export individual pallet calls #9

liamaharon opened this issue Sep 20, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@liamaharon
Copy link

This does not work:

	#[pallet::call]
	impl<T: Config> Pallet<T> {
		#[pallet::call_index(0)]
		#[docify::export(set_value)]
		pub fn set_value(origin: OriginFor<T>, value: u32) -> DispatchResult {
			ensure_signed(origin)?;

			let previous = Value::<T>::get().map(|v| v.current);
			let new_struct = CurrentAndPreviousValue { current: value, previous };
			<Value<T>>::put(new_struct);

			Ok(())
		}
	}

When I try to use #![doc = docify::embed!("src/lib.rs", set_value)] in my docs, I get a compile error:

error: Could not find docify export item 'set_value' in '...'.
  --> substrate/frame/examples/storage-migrations/src/lib.rs:56:39
   |
56 | #![doc = docify::embed!("src/lib.rs", set_value)]
   |                                       ^^^^^^^^^

However, I am able to export all calls:

        #[docify::export(pallet_calls)]
	#[pallet::call]
	impl<T: Config> Pallet<T> {
		#[pallet::call_index(0)]
		pub fn set_value(origin: OriginFor<T>, value: u32) -> DispatchResult {
			ensure_signed(origin)?;

			let previous = Value::<T>::get().map(|v| v.current);
			let new_struct = CurrentAndPreviousValue { current: value, previous };
			<Value<T>>::put(new_struct);

			Ok(())
		}
	}

#![doc = docify::embed!("src/lib.rs", pallet_calls)] works

@sam0x17 sam0x17 self-assigned this Sep 20, 2023
@sam0x17 sam0x17 added the bug Something isn't working label Sep 20, 2023
@sam0x17
Copy link
Owner

sam0x17 commented Sep 20, 2023

It's all impl fns it looks like, this reproduces it:

trait SomeTrait {
    fn trait_impl_method();
}

pub struct Liam9;

impl SomeTrait for Liam9 {
    #[docify::export]
    fn trait_impl_method() {
        println!("foo!");
    }
}
error: Could not find docify export item 'trait_impl_method' in '/home/sam/workspace/docify/examples/samples.rs'.
  --> examples/integration.rs:66:47
   |
66 | #[doc = docify::embed!("examples/samples.rs", trait_impl_method)]

@sam0x17
Copy link
Owner

sam0x17 commented Sep 20, 2023

Yes indeed, the visitor pattern right now only visits syn::Items, not syn::ImplItems, so will add that. Will do TraitItem as well

sam0x17 added a commit that referenced this issue Sep 20, 2023
ggwpez pushed a commit to paritytech/polkadot-sdk that referenced this issue Sep 20, 2023
Upgrades to docify v0.2.4 which adds support for exporting trait and
impl items in addition to regular items. This fixes @liamaharon's
sam0x17/docify#9 issue.

See the release notes for more information:
https://github.com/sam0x17/docify/releases/tag/v0.2.4
bgallois pushed a commit to duniter/duniter-polkadot-sdk that referenced this issue Mar 25, 2024
Upgrades to docify v0.2.4 which adds support for exporting trait and
impl items in addition to regular items. This fixes @liamaharon's
sam0x17/docify#9 issue.

See the release notes for more information:
https://github.com/sam0x17/docify/releases/tag/v0.2.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants