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

fix(proc macros): generate documentation for trait methods. #453

Merged
merged 9 commits into from
Sep 8, 2021

Conversation

niklasad1
Copy link
Member

@niklasad1 niklasad1 commented Sep 7, 2021

Closing #449

Note, we are not using the docs on the entire trait instead we are manually inserting documentation there but for that we need to parse the TraitItem for that so out-of-scope for this PR.

To elaborate if you do:

/// My import API but these comments are not used anywhere
#[rpc(client, server)]
pub trait MyApi {
	/// API.
	#[method(name = "api"]
	async fn api(&self) -> jsonrpsee::types::JsonRpcResult<()>;
}

Expands to

///Server trait implementation for the `Rpc` RPC API.
pub trait MyApiServer: Sized + Send + Sync + 'static
{
    /// API
    async fn api(&self) { ....}
}

///Client implementation for the `Rpc` RPC API.
pub trait RpcClient: jsonrpsee::types::traits::Client
{
    /// API
    async fn api(&self) { ....}
}

Copy link
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

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

lgtm!

proc-macros/src/helpers.rs Outdated Show resolved Hide resolved
proc-macros/src/rpc_macro.rs Outdated Show resolved Hide resolved
proc-macros/src/rpc_macro.rs Outdated Show resolved Hide resolved
proc-macros/src/rpc_macro.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@maciejhirsz maciejhirsz 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, just one nit.

proc-macros/src/helpers.rs Outdated Show resolved Hide resolved
/// Note that `doc comments` are expanded into `#[doc = "some comment"]`
/// Thus, if the attribute starts with `doc` => it's regarded as a doc comment.
pub(crate) fn extract_doc_comments(attrs: &[syn::Attribute]) -> TokenStream2 {
let docs = attrs.iter().filter(|attr| attr.path.is_ident("doc")).filter(|attr| match attr.parse_meta() {
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not super happy with the formatting of this one but it's better then previous version at least.....

Copy link
Contributor

Choose a reason for hiding this comment

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

Could have been .filter(|attr| attr.path.is_ident("doc") && match ... 🙈

Copy link
Member Author

@niklasad1 niklasad1 Sep 8, 2021

Choose a reason for hiding this comment

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

🥶 I can fix it in an follow up PR

@niklasad1 niklasad1 merged commit 089aa11 into master Sep 8, 2021
@niklasad1 niklasad1 deleted the na-proc-macros-generate-docs branch September 8, 2021 09:57
@niklasad1 niklasad1 mentioned this pull request Sep 8, 2021
niklasad1 added a commit that referenced this pull request Sep 8, 2021
* cleanup

* Update ws-server/src/tests.rs

* Update http-server/src/tests.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants