Skip to content

try to add doc comments to functions #1207

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

0x53A
Copy link
Contributor

@0x53A 0x53A commented Jun 16, 2025

I'm attempting to add more documentation to the API and opened the PR relatively early to gather feedback.


Currently, there is no documentation on the autogenerated functions from the godot API:

Example:

https://godot-rust.github.io/docs/gdext/master/godot/classes/struct.Camera2D.html

image

This PR adds some boilerplate text, and a link to the godot online docs:

image


At minimum I'll need to properly detect properties by reading the field from the json (https://raw.githubusercontent.com/godot-rust/godot4-prebuilt/refs/heads/4.4/res/extension_api.json), in the rust code it's currently commented out:

// pub members: Option<Vec<Member>>,

This is relevant for link generation, and I'm trying to auto-detect it by the get_ / set_ prefixes, but there are godot methods with a get_ prefix, for example Camera2D.get_limit, which now falsely get detected as a property.


Additionally it would be great to verbatim include the documentation, and this is available in XML format here.

@GodotRust
Copy link

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

1 similar comment
@GodotRust

This comment was marked as duplicate.

@0x53A
Copy link
Contributor Author

0x53A commented Jun 16, 2025

Well, I noticed something weird:

the 4 properties limit_bottom, limit_left, limit_right, limit_top all refer to the same two methods: set_limit and get_limit.

image

(https://docs.godotengine.org/en/stable/classes/class_camera2d.html#class-camera2d-property-limit-left)


		<method name="set_limit">
			<return type="void" />
			<param index="0" name="margin" type="int" enum="Side" />
			<param index="1" name="limit" type="int" />
			<description>
				Sets the camera limit for the specified [enum Side]. See also [member limit_bottom], [member limit_top], [member limit_left], and [member limit_right].
			</description>
		</method>
	</methods>
	<members>
		<member name="limit_bottom" type="int" setter="set_limit" getter="get_limit" default="10000000">
			Bottom scroll limit in pixels. The camera stops moving when reaching this value, but [member offset] can push the view past the limit.
		</member>
		<member name="limit_left" type="int" setter="set_limit" getter="get_limit" default="-10000000">
			Left scroll limit in pixels. The camera stops moving when reaching this value, but [member offset] can push the view past the limit.
		</member>
		<member name="limit_right" type="int" setter="set_limit" getter="get_limit" default="10000000">
			Right scroll limit in pixels. The camera stops moving when reaching this value, but [member offset] can push the view past the limit.
		</member>
		<member name="limit_top" type="int" setter="set_limit" getter="get_limit" default="-10000000">
			Top scroll limit in pixels. The camera stops moving when reaching this value, but [member offset] can push the view past the limit.
		</member>

In the C++ implementation, they do pass the SIDE as the last parameter of the macro:

https://github.com/godotengine/godot/blob/46c495ca21f40f57a7fb9c7cde6143738f1652d4/scene/2d/camera_2d.cpp#L964-L967

	ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_left", PROPERTY_HINT_NONE, "suffix:px"), "set_limit", "get_limit", SIDE_LEFT);
	ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_top", PROPERTY_HINT_NONE, "suffix:px"), "set_limit", "get_limit", SIDE_TOP);
	ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_right", PROPERTY_HINT_NONE, "suffix:px"), "set_limit", "get_limit", SIDE_RIGHT);
	ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_bottom", PROPERTY_HINT_NONE, "suffix:px"), "set_limit", "get_limit", SIDE_BOTTOM);

So at least in some cases I'd need to keep the documentation for the function, even if it is part of a property.

@Bromeon
Copy link
Member

Bromeon commented Jun 16, 2025

Thanks for the contribution!


This PR adds some boilerplate text, and a link to the godot online docs:

To be honest I don't think the boilerplate is very useful. This reminds me of the "Javadoc best practice" 🙂

/**
 * Get the position.
 *
 * Returns the position of the object as a 2D vector.
 *
 * @return position of the object.
 */
Vector2 getPosition();

If we change docs, we should rather go the full mile and import the real docs from Godot. See also #584 (this extends to classes and utilitiy functions, not just builtin types).

This would also obviate the need for per-method links, and messing with properties. We still have the class link on the top of each page.


Additionally it would be great to verbatim include the documentation, and this is available in XML format here.

It's even better, this is now available in the JSON, when invoking Godot with --dump-extension-api-with-docs instead of --dump-extension-api. I'm not sure if this contains all the information necessary though, and it would require an update to the prebuilt library.

We could maybe start supporting it in api-custom as a first step.

@Bromeon Bromeon added feature Adds functionality to the library c: engine Godot classes (nodes, resources, ...) labels Jun 16, 2025
@0x53A
Copy link
Contributor Author

0x53A commented Jun 16, 2025

To be honest I don't think the boilerplate is very useful.

I agree! Depending on how complex ingesting the actual docs is, I would still see some value in relatively quickly adding the link to the online docs though.

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, ...) feature Adds functionality to the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants