-
-
Notifications
You must be signed in to change notification settings - Fork 575
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
Allow submitting documentation to the Godot editor #1374
Conversation
9588567
to
46e595a
Compare
Alright, I've figured out a reasonably nice way for developers to use this functionality, that is as simple and automatic as I could make it. So, I'm taking this out of draft - it's ready for review! The one main thing I still need to figure out is handling CMake support, but I don't think that'll be too hard. Feedback on the overall approach would be appreciated! |
Hi @dsnopek, what about being able to read documentation for existing classes? For example, a custom extension/plug-in that may want to display the description associated with a specific Godot native, extension contributed, or script contributed class as part of their UI? |
I don't think Godot gives us an API to read documentation, unfortunately. That would be something to propose for Godot, before we could do anything in godot-cpp. If it was through classes bound in Your PR godotengine/godot#90189 is probably the closest thing that exists presently, allowing editor plugins to show particular documentation to the user, but not actually read its content. |
Tested this PR and the upstream godot one on my Threen extension: It works great, and out of the box! The instructions in the PR were clear. Some minor issues / potential future work I noticed:
|
Source compatibilityShould we consider the use case of maintaining an extension that may want to make use of this new feature for builds using 4.3+ as baseline, while still keeping the possibility to build for older Godot versions when targeting an older godot-cpp commit? This may require adding an API in the godot-cpp env like diff --git a/SConstruct b/SConstruct
index 4f19de1..781fc98 100644
--- a/SConstruct
+++ b/SConstruct
@@ -7,9 +7,10 @@ env = SConscript("godot-cpp/SConstruct")
env.Append(CPPPATH=["src/"])
sources = Glob("src/*.cpp")
-if env["target"] in ["editor", "template_debug"]:
- doc_data = env.GodotCPPDocData("src/gen/doc_data.gen.cpp", source=Glob("doc_classes/*.xml"))
- sources.append(doc_data)
+if env.has_feature("doc_data"):
+ if env["target"] in ["editor", "template_debug"]:
+ doc_data = env.GodotCPPDocData("src/gen/doc_data.gen.cpp", source=Glob("doc_classes/*.xml"))
+ sources.append(doc_data)
if env["platform"] == "macos":
platlibname = "{}.{}.{}".format(libname, env["platform"], env["target"]) Of course this wouldn't work right now for versions of godot-cpp before adding this Another approach that's already usable for this specific feature is simply a diff --git a/SConstruct b/SConstruct
index 4f19de1..e18ff0e 100644
--- a/SConstruct
+++ b/SConstruct
@@ -8,8 +8,11 @@ env.Append(CPPPATH=["src/"])
sources = Glob("src/*.cpp")
if env["target"] in ["editor", "template_debug"]:
- doc_data = env.GodotCPPDocData("src/gen/doc_data.gen.cpp", source=Glob("doc_classes/*.xml"))
- sources.append(doc_data)
+ try:
+ doc_data = env.GodotCPPDocData("src/gen/doc_data.gen.cpp", source=Glob("doc_classes/*.xml"))
+ sources.append(doc_data)
+ except AttributeError:
+ print("Not including class reference as we're targeting a pre-4.3 baseline.")
if env["platform"] == "macos":
platlibname = "{}.{}.{}".format(libname, env["platform"], env["target"]) |
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.
Code looks good, and I tested the feature which works great.
@akien-mga Thanks for doing such extensive testing and review!
I also encountered this (but only two times), and I also suspect something with the doc cache. This needs more investigation, but I don't think the problem is on the godot-cpp side, so I think it's out-of-scope for this PR.
This turned out to be a godot-cpp bug: I've added a fix for this in my latest push!
Maybe we can recommend the As far as "recommending" the approach, I considered putting it into |
Tested and confirmed the fix, I got three methods in Threen with the
Sounds good yeah.
Yes I think we could add this to godot-cpp-template. |
Thanks! |
Hi @dsnopek, tested this with Cmake and it works like a champ, thanks! 👍 However, I am finding that method and member details are not being rendered, although contributed.
|
Ah, I forgot to add CMake support :-/ I think it'd be a matter of splitting the
Yeah, that sounds like it's not working. :-) Godot will make "fake" docs for GDExtension classes that don't have XML docs, that just show all the methods and members, but without the descriptions, which is what it sounds like you're seeing. |
I started draft PR #1499, which has the refactoring required to add CMake support. I still need to figure out how to add it to CMake, though. |
I realize this is probably not the best place to ask this, however I'm at this point first trying to make sure I'm using it correctly. The thing is, no matter what, when attempting to use What I have attempted:
I have repeated all of the previous commands after also copying the extension binaries to the root of the demo project. I also attempted to run all of those commands in an empty project containing only the extension binary. All attempts have resulted in the crash, both on Windows and Linux. At this point I'm wishing I'm not using it correctly! That said, if I'm indeed using it correctly them I will open a bug report in the core Godot repository and if necessary compile Godot with debug symbols to get a proper stack trace report. By the way, I have attempted this in beta 1 and beta 2 of Godot 4.3 |
OK! I have found out the culprit and it was indeed on my end! I have a singleton in my extension that attaches a node into the tree root as soon as a function that requires said node is called. In other words, I'm "lazy loading" that Node. However I forgot to verify the validity of the root. Now doc generation works. Yet, before the fix:
I realize the tree root might not be created at all during doc generation, but this puzzle me a little bit. Do the extension functions get called during this doc (and mono-glue) generation process? |
Yes, GDExtensions are still initialized and all their classes registered when generating documentation, otherwise Godot wouldn't know that the classes from the GDExtensions exist, and couldn't generate documentation for them. I'm less familiar with the mono-glue generation, but it sounds like GDExtensions are initialized in that case as well. |
Ahh, sorry! I poorly formulated my question! Initialization I knew it did. My question was related to the functions registered in the
I'm not familiar with mono-glue at all. I just wanted to allow C# projects to also use my extension. However the set of errors I have encountered seem completely different and I will probably open a dedicated issue for that. From my limited knowledge and testing it seems mono-glue thing is generating a package for the entire engine, without having any way to tell it "hey, I want only the GDExtension stuff". Yet, I still need to perform some more tests here, so yeah... Thank you very much the answer! |
It shouldn't call any of the property setters, but it will make one instance of every class and call all of their property getters, in order to figure out the default value of every property. So, if your GDExtension is accessing the tree root in one of the constructors or property getters, then that would be called. |
Oh! Ok! Now everything makes sense! Thank you very much! |
Hi @dsnopek, I know for the inspector, it uses the |
I believe this is done by ClassDB::class_get_property_default_value(), which appears to just be calling Just skimming through that code, it doesn't look like |
Ah, I was referring to code in the Inspector. If I recall correctly, if you don't implement the What I am curious (I don't have the code in front of me) is why this method doesn't attempt to do the same? |
I don't know! However this works is how it has worked for quite a long time, and isn't something we changed for GDExtension - this is the same behavior modules have also had. |
Godot PR godotengine/godot#83747 added support for submitting documentation to the Godot editor from a GDExtension.
This PR aims to give godot-cpp users a way to use that, ideally, in much the same way as documentation is provided by modules.
Here's how it works:
--gdextension-docs
with--doctool
godot#91518, developers can rungodot --doctool ../ --gdextension-docs
in their demo project (assuming the project is in a directory below their top-level extension code) which will generate adoc_classes/
directorydoc_classes/
directorySConstruct
:When the GDExtension is loaded into the editor, it will automatically submit the documentation XML.
I'm not totally sure how to add this in CMake, but I think we can do it in a similar way to how we run
binding_generator.py
from CMake. I'd really appreciate any help with that!Original description
I'm not entirely sure how we should expose this to developers. What I have here presently, is mostly about being able to test that the functionality from the Godot PR works. This could certainly use some design help for how to expose the build-system part (both for SCons and cmake) as well as how the developer should trigger the registration.We'll also probably need some tooling somewhere, to assist in generating the XML files for extension classes. It looks likegodot --doctool
doesn't include extension classes, so we'll either need to modify it so that it does, or come up with some other process.