Skip to content

Commit

Permalink
Merge pull request #78990 from RedMser/class-reference-keywords
Browse files Browse the repository at this point in the history
Add search keywords to the class reference
  • Loading branch information
akien-mga committed Feb 12, 2024
2 parents 2b36dcf + 5911a12 commit 62fcc7e
Show file tree
Hide file tree
Showing 18 changed files with 175 additions and 41 deletions.
45 changes: 45 additions & 0 deletions core/doc_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class DocData {
bool is_experimental = false;
Vector<ArgumentDoc> arguments;
Vector<int> errors_returned;
String keywords;
bool operator<(const MethodDoc &p_method) const {
if (name == p_method.name) {
// Must be an operator or a constructor since there is no other overloading
Expand Down Expand Up @@ -195,6 +196,10 @@ class DocData {
doc.errors_returned.push_back(errors_returned[i]);
}

if (p_dict.has("keywords")) {
doc.keywords = p_dict["keywords"];
}

return doc;
}
static Dictionary to_dict(const MethodDoc &p_doc) {
Expand Down Expand Up @@ -225,6 +230,10 @@ class DocData {

dict["is_experimental"] = p_doc.is_experimental;

if (!p_doc.keywords.is_empty()) {
dict["keywords"] = p_doc.keywords;
}

if (!p_doc.arguments.is_empty()) {
Array arguments;
for (int i = 0; i < p_doc.arguments.size(); i++) {
Expand Down Expand Up @@ -254,6 +263,7 @@ class DocData {
String description;
bool is_deprecated = false;
bool is_experimental = false;
String keywords;
bool operator<(const ConstantDoc &p_const) const {
return name < p_const.name;
}
Expand Down Expand Up @@ -291,6 +301,10 @@ class DocData {
doc.is_experimental = p_dict["is_experimental"];
}

if (p_dict.has("keywords")) {
doc.keywords = p_dict["keywords"];
}

return doc;
}
static Dictionary to_dict(const ConstantDoc &p_doc) {
Expand Down Expand Up @@ -319,6 +333,10 @@ class DocData {

dict["is_experimental"] = p_doc.is_experimental;

if (!p_doc.keywords.is_empty()) {
dict["keywords"] = p_doc.keywords;
}

return dict;
}
};
Expand All @@ -335,6 +353,7 @@ class DocData {
String overrides;
bool is_deprecated = false;
bool is_experimental = false;
String keywords;
bool operator<(const PropertyDoc &p_prop) const {
return name.naturalcasecmp_to(p_prop.name) < 0;
}
Expand Down Expand Up @@ -388,6 +407,10 @@ class DocData {
doc.is_experimental = p_dict["is_experimental"];
}

if (p_dict.has("keywords")) {
doc.keywords = p_dict["keywords"];
}

return doc;
}
static Dictionary to_dict(const PropertyDoc &p_doc) {
Expand Down Expand Up @@ -432,6 +455,10 @@ class DocData {

dict["is_experimental"] = p_doc.is_experimental;

if (!p_doc.keywords.is_empty()) {
dict["keywords"] = p_doc.keywords;
}

return dict;
}
};
Expand All @@ -442,6 +469,7 @@ class DocData {
String data_type;
String description;
String default_value;
String keywords;
bool operator<(const ThemeItemDoc &p_theme_item) const {
// First sort by the data type, then by name.
if (data_type == p_theme_item.data_type) {
Expand Down Expand Up @@ -472,6 +500,10 @@ class DocData {
doc.default_value = p_dict["default_value"];
}

if (p_dict.has("keywords")) {
doc.keywords = p_dict["keywords"];
}

return doc;
}
static Dictionary to_dict(const ThemeItemDoc &p_doc) {
Expand All @@ -497,6 +529,10 @@ class DocData {
dict["default_value"] = p_doc.default_value;
}

if (!p_doc.keywords.is_empty()) {
dict["keywords"] = p_doc.keywords;
}

return dict;
}
};
Expand Down Expand Up @@ -573,6 +609,7 @@ class DocData {
String inherits;
String brief_description;
String description;
String keywords;
Vector<TutorialDoc> tutorials;
Vector<MethodDoc> constructors;
Vector<MethodDoc> methods;
Expand Down Expand Up @@ -609,6 +646,10 @@ class DocData {
doc.description = p_dict["description"];
}

if (p_dict.has("keywords")) {
doc.keywords = p_dict["keywords"];
}

Array tutorials;
if (p_dict.has("tutorials")) {
tutorials = p_dict["tutorials"];
Expand Down Expand Up @@ -816,6 +857,10 @@ class DocData {
dict["script_path"] = p_doc.script_path;
}

if (!p_doc.keywords.is_empty()) {
dict["keywords"] = p_doc.keywords;
}

return dict;
}
};
Expand Down
7 changes: 7 additions & 0 deletions doc/class.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<xs:attribute type="xs:string" name="qualifiers" use="optional" />
<xs:attribute type="xs:boolean" name="is_deprecated" use="optional" />
<xs:attribute type="xs:boolean" name="is_experimental" use="optional" />
<xs:attribute type="xs:string" name="keywords" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
Expand All @@ -123,6 +124,7 @@
<xs:attribute type="xs:string" name="default" use="optional" />
<xs:attribute type="xs:boolean" name="is_deprecated" use="optional" />
<xs:attribute type="xs:boolean" name="is_experimental" use="optional" />
<xs:attribute type="xs:string" name="keywords" use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand All @@ -144,6 +146,7 @@
<xs:attribute type="xs:byte" name="index" />
<xs:attribute type="xs:string" name="name" />
<xs:attribute type="xs:string" name="type" />
<xs:attribute type="xs:string" name="keywords" use="optional" />
</xs:complexType>
</xs:element>
<xs:element type="xs:string" name="description" />
Expand All @@ -169,6 +172,7 @@
<xs:attribute type="xs:boolean" name="is_bitfield" use="optional" />
<xs:attribute type="xs:boolean" name="is_deprecated" use="optional" />
<xs:attribute type="xs:boolean" name="is_experimental" use="optional" />
<xs:attribute type="xs:string" name="keywords" use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand Down Expand Up @@ -209,6 +213,7 @@
</xs:sequence>
<xs:attribute type="xs:string" name="name" use="optional" />
<xs:attribute type="xs:string" name="qualifiers" use="optional" />
<xs:attribute type="xs:string" name="keywords" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
Expand All @@ -225,6 +230,7 @@
<xs:attribute type="xs:string" name="data_type" />
<xs:attribute type="xs:string" name="type" />
<xs:attribute type="xs:string" name="default" use="optional" />
<xs:attribute type="xs:string" name="keywords" use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand Down Expand Up @@ -275,6 +281,7 @@
<xs:attribute type="xs:string" name="inherits" />
<xs:attribute type="xs:boolean" name="is_deprecated" use="optional" />
<xs:attribute type="xs:boolean" name="is_experimental" use="optional" />
<xs:attribute type="xs:string" name="keywords" use="optional" />
</xs:complexType>
</xs:element>
</xs:schema>
2 changes: 1 addition & 1 deletion doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@
[b]Note:[/b] This function is called automatically when the project is run. If you need to fix the seed to have consistent, reproducible results, use [method seed] to initialize the random number generator.
</description>
</method>
<method name="remap">
<method name="remap" keywords="range, lerp">
<return type="float" />
<param index="0" name="value" type="float" />
<param index="1" name="istart" type="float" />
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Area2D.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="Area2D" inherits="CollisionObject2D" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<class name="Area2D" inherits="CollisionObject2D" keywords="trigger" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
A region of 2D space that detects other [CollisionObject2D]s entering or exiting it.
</brief_description>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Area3D.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="Area3D" inherits="CollisionObject3D" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<class name="Area3D" inherits="CollisionObject3D" keywords="trigger" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
A region of 3D space that detects other [CollisionObject3D]s entering or exiting it.
</brief_description>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@
Returns the script associated with a typed array tied to a class name.
</description>
</method>
<method name="has" qualifiers="const">
<method name="has" qualifiers="const" keywords="includes, contains">
<return type="bool" />
<param index="0" name="value" type="Variant" />
<description>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/DirAccess.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="DirAccess" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<class name="DirAccess" inherits="RefCounted" keywords="directory, path, folder" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Provides methods for managing directories and their content.
</brief_description>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/InputEventMouseButton.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="InputEventMouseButton" inherits="InputEventMouse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<class name="InputEventMouseButton" inherits="InputEventMouse" keywords="click, press" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Represents a mouse button being pressed or released.
</brief_description>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Node.xml
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@
Calls [method Object.notification] with [param what] on this node and all of its children, recursively.
</description>
</method>
<method name="queue_free">
<method name="queue_free" keywords="delete, remove, kill, die">
<return type="void" />
<description>
Queues this node to be deleted at the end of the current frame. When deleted, all of its children are deleted as well, and all references to the node and its children become invalid.
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Object.xml
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@
[b]Note:[/b] In C#, [param signal] must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the [code]SignalName[/code] class to avoid allocating a new [StringName] on each call.
</description>
</method>
<method name="free">
<method name="free" keywords="delete, remove, kill, die">
<return type="void" />
<description>
Deletes the object from memory. Pre-existing references to the object become invalid, and any attempt to access them will result in a run-time error. Checking the references with [method @GlobalScope.is_instance_valid] will return [code]false[/code].
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/PackedScene.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
Returns the [SceneState] representing the scene file contents.
</description>
</method>
<method name="instantiate" qualifiers="const">
<method name="instantiate" qualifiers="const" keywords="create, make, spawn, new">
<return type="Node" />
<param index="0" name="edit_state" type="int" enum="PackedScene.GenEditState" default="0" />
<description>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/PhysicalBone2D.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="PhysicalBone2D" inherits="RigidBody2D" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<class name="PhysicalBone2D" inherits="RigidBody2D" keywords="ragdoll" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
A [RigidBody2D]-derived node used to make [Bone2D]s in a [Skeleton2D] react to physics.
</brief_description>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/PhysicalBone3D.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="PhysicalBone3D" inherits="PhysicsBody3D" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<class name="PhysicalBone3D" inherits="PhysicsBody3D" keywords="ragdoll" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
A physics body used to make bones in a [Skeleton3D] react to physics.
</brief_description>
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/String.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</constructor>
</constructors>
<methods>
<method name="begins_with" qualifiers="const">
<method name="begins_with" qualifiers="const" keywords="starts_with">
<return type="bool" />
<param index="0" name="text" type="String" />
<description>
Expand Down Expand Up @@ -126,7 +126,7 @@
[/codeblock]
</description>
</method>
<method name="contains" qualifiers="const">
<method name="contains" qualifiers="const" keywords="includes, has">
<return type="bool" />
<param index="0" name="what" type="String" />
<description>
Expand Down
9 changes: 9 additions & 0 deletions doc/tools/make_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ def parse_class(self, class_root: ET.Element, filepath: str) -> None:
if desc is not None and desc.text:
class_def.description = desc.text

keywords = class_root.get("keywords")
if keywords is not None:
class_def.keywords = keywords

properties = class_root.find("members")
if properties is not None:
for property in properties:
Expand Down Expand Up @@ -564,6 +568,7 @@ def __init__(self, name: str) -> None:
self.brief_description: Optional[str] = None
self.description: Optional[str] = None
self.tutorials: List[Tuple[str, str]] = []
self.keywords: Optional[str] = None

# Used to match the class with XML source for output filtering purposes.
self.filepath: str = ""
Expand Down Expand Up @@ -866,6 +871,10 @@ def make_rst_class(class_def: ClassDef, state: State, dry_run: bool, output_dir:
# Remove the "Edit on Github" button from the online docs page.
f.write(":github_url: hide\n\n")

# Add keywords metadata.
if class_def.keywords is not None and class_def.keywords != "":
f.write(f".. meta::\n\t:keywords: {class_def.keywords}\n\n")

# Warn contributors not to edit this file directly.
# Also provide links to the source files for reference.

Expand Down
Loading

0 comments on commit 62fcc7e

Please sign in to comment.