-
-
Notifications
You must be signed in to change notification settings - Fork 218
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 doc comments not showing up if only some class members are documented #815
Fix doc comments not showing up if only some class members are documented #815
Conversation
92739b9
to
5a81f7f
Compare
fix'd – all the cases in minimal reproduction project has been covered. It is worth nothing that example included in test docs causes documentation generation to fail silently (might be simply a length limit). |
@@ -174,6 +174,8 @@ godot::sys::plugin_add!( | |||
register_methods_constants_fn: ::godot::private::ErasedRegisterFn { | |||
raw: ::godot::private::callbacks::register_user_methods_constants::<HasOtherConstants>, | |||
}, | |||
#[cfg(all(since_api = "4.3", feature = "docs"))] | |||
docs: None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isnt going to compile, itest doesnt have a docs feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well it doesnt change anything, because it can never be enabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, missed leftover – I removed it since itest probably won't be called with godot-core/docs
/godot/register-docs
anyway
.map(make_method_docs) | ||
.collect::<Option<String>>()?; | ||
.filter_map(make_method_docs) | ||
.collect::<String>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
theres a new problem here-- i implemented the option stuff so as to save space when no documentation is provided for a function, but now you just have empty documentation. you need to check if the number of documented items is 0 and return none to save space here
else you're reverting a feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, fixed – method won't generate TokenStream in question if there is no need to do so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its not when the methods
are empty its when the methods have no documentation at all, i.e methods.iter().filter(has_docs).count() == 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you see when
impl X {
#[func] fn y(…) { }
}
we dont want to have a <methods>
block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing – right now (on master) if no documentation for methods are present, the generated xml contains methods tag <methods></methods>
with no children present, and same goes for signals and constants. I aimed to preserve this behaviour. I'll just check with test project if Godot has no issues with missing "methods" block in case if there is some documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont remember why i put the Option
s in at all then...
But if its working fine right now, you should be able to make the function just return Some, and thus remove the function from existence as it was a IIFE moved out (makeshift try
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've taken a bit more direct approach – I've decided to keep all the declarations as options and just handle them accordingly while generating given docs block.
(it is kinda a requirement if we want to document only few out of four blocks (the blocks in question being virtual methods, methods, signals or constants))
godot-core/src/docs.rs
Outdated
pub methods: &'static str, | ||
pub signals: &'static str, | ||
pub constants: &'static str, | ||
pub methods: Option<&'static str>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was previously done as Option<InherentImplDocs>
, please change the docs
fields to be InherentImplDocs
etc, as right now the type is Option<[Option<&'static str>; 3]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved generation of signal & constant blocks to compile time, thus now InherentImplDocs holds 2x &'static str & one Option<&'static str>.
godot-macros/src/docs.rs
Outdated
virtual_methods | ||
.is_empty() | ||
.not() | ||
.then(|| quote! { virtual_method_docs: #virtual_methods.into(), }) | ||
.unwrap_or_else(|| quote! { virtual_method_docs: None, }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you obfuscate the match?
virtual_methods | |
.is_empty() | |
.not() | |
.then(|| quote! { virtual_method_docs: #virtual_methods.into(), }) | |
.unwrap_or_else(|| quote! { virtual_method_docs: None, }) | |
match virtual_methods { | |
"" => quote! { virtual_method_docs: None, }, | |
_ => quote! { virtual_method_docs: #virtual_methods.into(), } | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you applying my suggestion weirdly? you seem to really want to use is_empty
godot-macros/src/docs.rs
Outdated
if methods.is_empty() && signals.is_empty() && constants.is_empty() { | ||
return None; | ||
} | ||
let to_tokenstream = |s: String| -> TokenStream { | ||
s.is_empty() | ||
.not() | ||
.then(|| quote!(Some(#s))) | ||
.unwrap_or(quote! {None}) | ||
}; | ||
let (methods, signals, constants) = ( | ||
to_tokenstream(methods), | ||
to_tokenstream(signals), | ||
to_tokenstream(constants), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you doing this s.is_empty().not().then().unwrap_or_else()
thing?
if methods.is_empty() && signals.is_empty() && constants.is_empty() { | |
return None; | |
} | |
let to_tokenstream = |s: String| -> TokenStream { | |
s.is_empty() | |
.not() | |
.then(|| quote!(Some(#s))) | |
.unwrap_or(quote! {None}) | |
}; | |
let (methods, signals, constants) = ( | |
to_tokenstream(methods), | |
to_tokenstream(signals), | |
to_tokenstream(constants), | |
); | |
let to_tokenstream = |s| match s { | |
"" => quote! { Some(#s) }, | |
_ => quote! { None }, | |
}; | |
let (methods, signals, constants) = ( | |
to_tokenstream(methods), | |
to_tokenstream(signals), | |
to_tokenstream(constants), | |
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
godot-core/src/docs.rs
Outdated
fn block_docstring_or_empty(block: Option<&'static str>, tag: &'static str) -> String { | ||
match block { | ||
Some(s) => format!("<{tag}>{s}</{tag}>"), | ||
_ => "".to_string(), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any chance you could move the tags into the block at macro time instead?
fn block_docstring_or_empty(block: Option<&'static str>, tag: &'static str) -> String { | |
match block { | |
Some(s) => format!("<{tag}>{s}</{tag}>"), | |
_ => "".to_string(), | |
} | |
} | |
fn block_docstring_or_empty(block: Option<&'static str>, tag: &'static str) -> String { | |
block.map(|s| format!("<{tag}>{s}</{tag}>")).unwrap_or_default() | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is an option for signals & constants – methods&virtual methods need to be formatted during runtime 🤔
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-815 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
There are some Clippy issues.
godot-core/src/docs.rs
Outdated
let methods_block: String = match methods.is_some() || virtual_methods.is_some() { | ||
true => format!("<methods>{m}{vm}</methods>", m=methods.unwrap_or_default(), vm=virtual_methods.unwrap_or_default()), | ||
_ => "".to_string() | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use if
instead of match
Also, String::new()
instead of "".to_string()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
godot-core/src/init/mod.rs
Outdated
unsafe { | ||
crate::docs::register(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call to crate::docs::register();
is unsafe* and I can't compile test project without explicitly marking this call as unsafe 🤔 .
test project:
[dependencies]
godot = { path = "../../gdext/godot", features = ["custom-godot", "register-docs"] }
irwin@toster:~/apps/godot/opensource-contr/missing_docs/bug-repro-godot-rust-docs-master/docstest$ cargo build
Compiling godot-core v0.1.3 (/home/irwin/apps/godot/opensource-contr/missing_docs/gdext/godot-core)
error: call to unsafe function `docs::register` is unsafe and requires unsafe block (error E0133)
--> /home/irwin/apps/godot/opensource-contr/missing_docs/gdext/godot-core/src/init/mod.rs:147:17
|
147 | crate::docs::register();
| ^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
= note: consult the function's documentation for information on how to avoid undefined behavior
note: an unsafe function restricts its caller, but its body is safe by default
--> /home/irwin/apps/godot/opensource-contr/missing_docs/gdext/godot-core/src/init/mod.rs:132:1
|
132 | unsafe fn gdext_on_level_init(level: InitLevel) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the lint level is defined here
--> /home/irwin/apps/godot/opensource-contr/missing_docs/gdext/godot-core/src/init/mod.rs:131:8
|
131 | #[deny(unsafe_op_in_unsafe_fn)]
| ^^^^^^^^^^^^^^^^^^^^^^
error: could not compile `godot-core` (lib) due to 1 previous error
cargo test in godot
with proper flags set for itself and godot-core
:
/missing_docs/gdext/godot$ cargo test --features register-docs,api-custom,godot-core/docs,godot-core/api-custom -- --nocapture
Compiling godot-macros v0.1.3 (/home/irwin/apps/godot/opensource-contr/missing_docs/gdext/godot-macros)
Compiling godot-core v0.1.3 (/home/irwin/apps/godot/opensource-contr/missing_docs/gdext/godot-core)
error: call to unsafe function `docs::register` is unsafe and requires unsafe block (error E0133)
--> godot-core/src/init/mod.rs:147:13
|
147 | crate::docs::register();
| ^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
= note: for more information, see issue #71668 <https://github.com/rust-lang/rust/issues/71668>
= note: consult the function's documentation for information on how to avoid undefined behavior
note: an unsafe function restricts its caller, but its body is safe by default
--> godot-core/src/init/mod.rs:132:1
|
132 | unsafe fn gdext_on_level_init(level: InitLevel) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the lint level is defined here
--> godot-core/src/init/mod.rs:131:8
|
131 | #[deny(unsafe_op_in_unsafe_fn)]
| ^^^^^^^^^^^^^^^^^^^^^^
error: could not compile `godot-core` (lib) due to 1 previous error
- safety: must be called from the same thread that bindings are initialized from & bindings must be initialized beforehand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somebody must have put that deny in there and forgotten to check the #[cfg]d out things i suppose...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bend-n it seems so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good remark, I'll make sure this feature is enabled in at least one CI run.
For now, you can add the unsafe
block and prepend it with a safety assertion line:
// SAFETY: binding has been initialized at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: #819
I can later rebase this PR onto master
, to make sure the CI passes.
godot-macros/src/docs.rs
Outdated
let to_tagged = |s: String, tag: &str| match s.is_empty() { | ||
true => s, | ||
_ => format!("<{tag}>{s}</{tag}>"), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bromeon what do you think of
match x {
"" => …,
_ => …,
}
(was my original suggestion)
godot-macros/src/docs.rs
Outdated
let constants_block = to_tagged( | ||
constants | ||
.iter() | ||
.map(|ConstDefinition { raw_constant: x }| x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.map(|ConstDefinition { raw_constant: x }| x) | |
.map(|ConstDefinition { raw_constant }| raw_constant) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
godot-macros/src/docs.rs
Outdated
let methods = match methods.is_empty() { | ||
true => quote! { None }, | ||
_ => quote! {#methods.into()}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
godot-macros/src/docs.rs
Outdated
}, | ||
.filter_map(make_virtual_method_docs) | ||
.collect::<String>(); | ||
match virtual_methods.is_empty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please empty line before, to separate complex multi-line statements.
Again, if
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if'ed and multi-lined
(At least some) clippy issues are independent of this PR, I'll fix them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Could you
- include the missing commits with the amendments [edit: seems resolved]
- rebase onto master
- squash the commits, in line with this?
godot-core/src/init/mod.rs
Outdated
unsafe { | ||
crate::docs::register(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good remark, I'll make sure this feature is enabled in at least one CI run.
For now, you can add the unsafe
block and prepend it with a safety assertion line:
// SAFETY: binding has been initialized at this point.
godot-macros/src/docs.rs
Outdated
let to_tagged = |s: String, tag: &str| match s.is_empty() { | ||
true => s, | ||
_ => format!("<{tag}>{s}</{tag}>"), | ||
}; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
4ff001e
to
1ba8157
Compare
1ba8157
to
8c89daf
Compare
Fixed the formatting and the commit message. Please don't refer to issues via link or # in commit message, because this creates a ton of spam on the tickets as you iterate: There are still a few more things to do but we're getting closer, will add another comment 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks mostly good, but there's still one CI problem to be addressed.
To me it's still not quite clear why the handling of methods, signals and constants is different: some declared as Option<&'static str>
, others as &'static str
; some evaluated XML tags before others.
You mentioned this in multiple comments, but I didn't see why this is done. What's the rationale? Can we not do the processing for different symbols at the same stage?
@Bromeon initially I was generating all the required xml during initialization. I was asked by @bend-n #815 (comment) to do so at compile time – but I don't know[1] how to deal with two separate method blocks (one coming from inherent impl ( I can revert to generating all the docs blocks on runtime/during plugin registration in [1] there are some ways to get around that – for example enum_dispatch uses "cache" https://gitlab.com/antonok/enum_dispatch/-/blob/master/src/cache.rs, but it is certainly over-engineered solution |
im talking about the tags part: i.e, instead of storing |
I can revert to initial solution then |
Ah, that makes sense. I would actually even argue not too much should be processed at compile time, because compile times in Rust are already slow. I'm not sure if one would feel much impact during load time (and it's not like released games need this feature, it's mostly during development and for plugins). So I think you can leave this for now -- please just add a comment above the plugin declarations that explains this design rationale. 👍 |
607912e
to
c62c448
Compare
godot-core/src/docs.rs
Outdated
@@ -7,6 +7,7 @@ | |||
use crate::registry::plugin::PluginItem; | |||
use std::collections::HashMap; | |||
|
|||
#[doc(hidden)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? If I check latest API docs, I don't find the symbol.
If it's indeed necessary, attributes should come after the ///
comment block.
godot-core/src/docs.rs
Outdated
/// Documentation for signals and constants is being processed on compile time | ||
/// and can take a form of an already formatted xml `<block><doc></doc>…</block>` or an | ||
/// empty string if no such attribute has been documented. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Documentation for signals and constants is being processed on compile time | |
/// and can take a form of an already formatted xml `<block><doc></doc>…</block>` or an | |
/// empty string if no such attribute has been documented. | |
/// Documentation for signals and constants is being processed at compile time | |
/// and can take the form of an already formatted XML `<block><doc></doc>…</block>`, or an | |
/// empty string if no such attribute has been documented. |
godot-core/src/docs.rs
Outdated
/// Since documentation for methods comes from two different sources | ||
/// – Inherent Implementation (`methods`) and IGodotType trait implementation (`virtual_method_docs`) – | ||
/// it is undesirable to merge these on compile time, and they are being kept as an optional strings of not-yet-parented xml tags | ||
/// (or nothing if no method has been documented). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Since documentation for methods comes from two different sources | |
/// – Inherent Implementation (`methods`) and IGodotType trait implementation (`virtual_method_docs`) – | |
/// it is undesirable to merge these on compile time, and they are being kept as an optional strings of not-yet-parented xml tags | |
/// (or nothing if no method has been documented). | |
/// Since documentation for methods comes from two different sources | |
/// -– inherent Implementation (`methods`) and I* trait implementation (`virtual_method_docs`) –- | |
/// it is undesirable to merge them at compile time. Instead, they are kept as optional strings of not-yet-parented XML tags | |
/// (or nothing if no method has been documented). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a -– (…) –-
if I can ask?
godot-core/src/docs.rs
Outdated
let methods_block: String = if methods.is_some() || virtual_methods.is_some() { format!("<methods>{m}{vm}</methods>", m=methods.unwrap_or_default(), vm=virtual_methods.unwrap_or_default()) } else { String::new()}; | ||
|
||
let brief = description.split_once("[br]").map(|(x, _)| x).unwrap_or_default(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the formatting of this in my commit, but you reverted it now. Please restore.
godot-macros/src/docs.rs
Outdated
let methods = if methods.is_empty() { | ||
quote! { None } | ||
} else { | ||
quote! {#methods.into()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quote! {#methods.into()} | |
quote! { #methods.into() } |
Also, what does the .into()
do here? Is it possible to make the conversion more explicit? Since this is non-local generated code, things can be quite hard to understand otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The into is for T => Some(T)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's write Some(...)
then. 10 times clearer.
That's one thing I truly hate about From
, it sometimes encourages obfuscation with zero benefits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change it to { Some(…) }
, I aimed to keep it consistent with earlier version
godot/tests/docs.rs
Outdated
#[signal] | ||
/// some user signal | ||
/// | ||
/// some multiline doc | ||
fn documented_signal(p: Vector3, w: f64); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here, would be good to have Rustdoc before attributes.
We don't need to fix it everywhere (it may be good to have one other case just for testing), but for lines that are added or changed already.
d3338d0
to
28c4513
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patience, only few things left -- but you should be able to apply them directly 🙂
godot-macros/src/docs.rs
Outdated
if virtual_methods.is_empty() { | ||
quote! { virtual_method_docs: None, } | ||
} else { | ||
quote! { virtual_method_docs: #virtual_methods.into(), } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quote! { virtual_method_docs: #virtual_methods.into(), } | |
quote! { virtual_method_docs: Some(#virtual_methods), } |
godot-core/src/docs.rs
Outdated
"<methods>{m}{vm}</methods>", | ||
m=methods.unwrap_or_default(), | ||
vm=virtual_methods.unwrap_or_default()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"<methods>{m}{vm}</methods>", | |
m=methods.unwrap_or_default(), | |
vm=virtual_methods.unwrap_or_default()) | |
"<methods>{m}{vm}</methods>", | |
m = methods.unwrap_or_default(), | |
vm = virtual_methods.unwrap_or_default()) |
I missed this, sorry.
godot-core/src/docs.rs
Outdated
@@ -23,40 +23,56 @@ pub struct StructDocs { | |||
pub members: &'static str, | |||
} | |||
|
|||
/// Created for documentation on | |||
/// Keeps documentation for Inherent Implementation such as: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Keeps documentation for Inherent Implementation such as: | |
/// Keeps documentation for inherent `impl` blocks, such as: |
godot-core/src/docs.rs
Outdated
/// #[signal] | ||
/// /// this signal signals | ||
/// fn documented_signal(p: Vector3, w: f64); | ||
/// #[constant] | ||
/// /// this constant consts | ||
/// const CON: i64 = 42; | ||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// #[signal] | |
/// /// this signal signals | |
/// fn documented_signal(p: Vector3, w: f64); | |
/// #[constant] | |
/// /// this constant consts | |
/// const CON: i64 = 42; | |
/// | |
/// #[signal] | |
/// /// this signal signals | |
/// fn documented_signal(p: Vector3, w: f64); | |
/// | |
/// #[constant] | |
/// /// this constant consts | |
/// const CON: i64 = 42; |
(I just moved the empty line from the end to between them, no clue why the diff is so weird)
godot-core/src/docs.rs
Outdated
/// Since documentation for methods comes from two different sources | ||
/// -– inherent Implementation (`methods`) and I* trait implementation (`virtual_method_docs`) –- | ||
/// it is undesirable to merge them at compile time. Instead, they are being kept as an optional | ||
/// strings of not-yet-parented XML tags | ||
/// (or nothing if no method has been documented). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Since documentation for methods comes from two different sources | |
/// -– inherent Implementation (`methods`) and I* trait implementation (`virtual_method_docs`) –- | |
/// it is undesirable to merge them at compile time. Instead, they are being kept as an optional | |
/// strings of not-yet-parented XML tags | |
/// (or nothing if no method has been documented). | |
/// Since documentation for methods comes from two different sources | |
/// -- inherent implementations (`methods`) and `I*` trait implementations (`virtual_method_docs`) -- | |
/// it is undesirable to merge them at compile time. Instead, they are being kept as an optional | |
/// strings of not-yet-parented XML tags (or nothing if no method has been documented). |
28c4513
to
17b4880
Compare
Thanks a lot! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these options seem slightly pointless, as what you seem to be doing is
let thing = x.is_empty().then(String::default).unwrap_or(x);
// later
if thing.is_some() && … {
thing.unwrap_or_default()
}
Which could be done as
let thing = x;
if !thing.is_empty() && !… {
thing
}
godot-macros/src/docs.rs
Outdated
if virtual_methods.is_empty() { | ||
quote! { virtual_method_docs: None, } | ||
} else { | ||
quote! { virtual_method_docs: Some(#virtual_methods), } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one of the options in question:
let methods_block = if methods.is_some() || virtual_methods.is_some() {
format!(
"<methods>{m}{vm}</methods>",
m = methods.unwrap_or_default(),
vm = virtual_methods.unwrap_or_default())
} else {
String::new()
};
can that be changed to just
(virtual_methods.is_empty() && methods.is_empty())
.then(String::default)
.unwrap_or_else(|| format!("<methods>{methods}{virtual_methods}</methods>"))
and do this here: (and in the make method docs function)
if virtual_methods.is_empty() { | |
quote! { virtual_method_docs: None, } | |
} else { | |
quote! { virtual_method_docs: Some(#virtual_methods), } | |
} | |
quote! { virtual_method_docs: #virtual_methods } |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks a lot! It actually works fine and looks like the cleanest and the least messy solution
Good that CI failed then 😁 there's an unrelated |
17b4880
to
6b46978
Compare
…s are documented - Extend docs test case to feature some undocumented members of godot instances - Change map&unwrap in docs.rs to filter_map (allow to document only subset of all the properties of a given class) - Generate documentation blocks for signals & constants on compile-time
6b46978
to
87fa9ba
Compare
closes #810
Add "docs" feature to plugin in constant_tests