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

Add a doc to point users to kwarg builders #876

Merged

Conversation

fpdotmonkey
Copy link
Contributor

A frequent issue that comes up with people that are first using the library is that they don't know about gdext's unique model for Gdscript's default function arguments. This gently points users to the builder functions.

Documenting every method this way is a little spammy since users only need to learn about this API once, but it's only one line, so I don't think it impacts scrolling distances much on the doc site.

@GodotRust
Copy link

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-876

@lilizoey lilizoey added quality-of-life No new functionality, but improves ergonomics/internals c: engine Godot classes (nodes, resources, ...) labels Aug 27, 2024
@lilizoey
Copy link
Member

Maybe we should also link the book? https://godot-rust.github.io/book/godot-api/functions.html?highlight=default#default-parameters
Maybe as just see also [the book](link)

Copy link
Member

@Bromeon Bromeon left a comment

Choose a reason for hiding this comment

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

Thanks, great idea! 🙂

Please also indent the attributes.

CI blocked by upstream godotengine/godot#96406.

#[doc = "To set the default parameters, use [`"]
#[doc = stringify!(Self::#extended_fn_name)]
#[doc = "`] and its builder methods. See"]
#[doc = " [the book](https://godot-rust.github.io/book/godot-api/functions.html?highlight=default#default-parameters) for"]
Copy link
Member

Choose a reason for hiding this comment

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

The ?highlight=default is distracting and shouldn't be part of the link.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -97,6 +97,11 @@ pub fn make_function_definition_with_defaults(
};

let functions = quote! {
#[doc = "To set the default parameters, use [`"]
#[doc = stringify!(Self::#extended_fn_name)]
Copy link
Member

Choose a reason for hiding this comment

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

This generates code containing a macro, which then again needs to be expanded by the compiler. Could you not create the entire doc-string at proc-macro time?

Then you could just have #[doc = #link_to_ex_function].

Copy link
Member

Choose a reason for hiding this comment

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

Any comment on this one? Why not generate the whole string at macro time and have a single #[doc] attribute? Would help readability and make it easier to change the text in the future than distributing it over 5 #[doc = ...] lines.

And who knows, maybe it helps with the rustfmt issue, too 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sorry, I should've commented. This is fixed in the version I pushed yesterday. Unfortunately, no help with the rustfmt issue.

Copy link
Member

Choose a reason for hiding this comment

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

I looked at the diff, but the current code is still

    #[doc = "To set the default parameters, use [`"]
    #[doc = #qualified_extended_fn_name_str]
    #[doc = "`] and its builder methods.  See"]
    #[doc = " [the book](https://godot-rust.github.io/book/godot-api/functions.html#default-parameters) for"]
    #[doc = " detailed usage instructions."]

So I was wondering why not a single #[doc] attribute, and do the concatenation outside, so the generated code sees only one string literal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah that's what you mean, ok. I'll see if I can do that this weekend.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@fpdotmonkey
Copy link
Contributor Author

Please also indent the attributes.

rustfmt won't allow that.

$ rustfmt --edition 2021 --check godot-codegen/src/generator/default_parameters.rs 
Diff in /home/fp/3rd/gdext/godot-codegen/src/generator/default_parameters.rs at line 98:
     };
 
     let functions = quote! {
-	#[doc = "To set the default parameters, use [`"]
-	#[doc = #qualified_extended_fn_name]
-	#[doc = "`] and its builder methods.  See"]
-	#[doc = " [the book](https://godot-rust.github.io/book/godot-api/functions.html#default-parameters) for"]
-	#[doc = " detailed usage instructions."]
+    #[doc = "To set the default parameters, use [`"]
+    #[doc = #qualified_extended_fn_name]
+    #[doc = "`] and its builder methods.  See"]
+    #[doc = " [the book](https://godot-rust.github.io/book/godot-api/functions.html#default-parameters) for"]
+    #[doc = " detailed usage instructions."]
         #[inline]
         #vis fn #simple_fn_name(
             #receiver_param

Possibly related to rust-lang/rustfmt#6233, but only in that it's incorrect formatting around macros.

@Bromeon
Copy link
Member

Bromeon commented Sep 7, 2024

Not sure if you've seen id, I added a comment here 🙂

A frequent issue that comes up with people that are first using the
library is that they don't know about gdext's unique model for
Gdscript's default function arguments.  This gently points users to the
builder functions.

Documenting every method this way is a little spammy since users only
need to learn about this API once, but it's only one line, so I don't
think it impacts scrolling distances much on the doc site.
@Bromeon Bromeon added this pull request to the merge queue Sep 14, 2024
Merged via the queue into godot-rust:master with commit e5d19c9 Sep 14, 2024
15 checks passed
@Bromeon
Copy link
Member

Bromeon commented Sep 14, 2024

Thank you! 🙂

@Bromeon Bromeon added documentation Improvements or additions to documentation and removed quality-of-life No new functionality, but improves ergonomics/internals labels Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: engine Godot classes (nodes, resources, ...) documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants