Browse Source

Merge pull request #67217 from touilleMan/gdextension-implement-get_documentation

Implement ScriptExtension::get_documentation
Rémi Verschelde 2 years ago
parent
commit
6e7c6e50d8
2 changed files with 344 additions and 1 deletions
  1. 340 0
      core/doc_data.h
  2. 4 1
      core/object/script_language_extension.h

+ 340 - 0
core/doc_data.h

@@ -57,6 +57,27 @@ public:
 			}
 			}
 			return name < p_arg.name;
 			return name < p_arg.name;
 		}
 		}
+		static ArgumentDoc from_dict(const Dictionary &p_dict) {
+			ArgumentDoc doc;
+
+			if (p_dict.has("name")) {
+				doc.name = p_dict["name"];
+			}
+
+			if (p_dict.has("type")) {
+				doc.type = p_dict["type"];
+			}
+
+			if (p_dict.has("enumeration")) {
+				doc.enumeration = p_dict["enumeration"];
+			}
+
+			if (p_dict.has("default_value")) {
+				doc.default_value = p_dict["default_value"];
+			}
+
+			return doc;
+		}
 	};
 	};
 
 
 	struct MethodDoc {
 	struct MethodDoc {
@@ -97,6 +118,55 @@ public:
 			}
 			}
 			return name < p_method.name;
 			return name < p_method.name;
 		}
 		}
+		static MethodDoc from_dict(const Dictionary &p_dict) {
+			MethodDoc doc;
+
+			if (p_dict.has("name")) {
+				doc.name = p_dict["name"];
+			}
+
+			if (p_dict.has("return_type")) {
+				doc.return_type = p_dict["return_type"];
+			}
+
+			if (p_dict.has("return_enum")) {
+				doc.return_enum = p_dict["return_enum"];
+			}
+
+			if (p_dict.has("qualifiers")) {
+				doc.qualifiers = p_dict["qualifiers"];
+			}
+
+			if (p_dict.has("description")) {
+				doc.description = p_dict["description"];
+			}
+
+			if (p_dict.has("is_deprecated")) {
+				doc.is_deprecated = p_dict["is_deprecated"];
+			}
+
+			if (p_dict.has("is_experimental")) {
+				doc.is_experimental = p_dict["is_experimental"];
+			}
+
+			Array arguments;
+			if (p_dict.has("arguments")) {
+				arguments = p_dict["arguments"];
+			}
+			for (int i = 0; i < arguments.size(); i++) {
+				doc.arguments.push_back(ArgumentDoc::from_dict(arguments[i]));
+			}
+
+			Array errors_returned;
+			if (p_dict.has("errors_returned")) {
+				errors_returned = p_dict["errors_returned"];
+			}
+			for (int i = 0; i < errors_returned.size(); i++) {
+				doc.errors_returned.push_back(errors_returned[i]);
+			}
+
+			return doc;
+		}
 	};
 	};
 
 
 	struct ConstantDoc {
 	struct ConstantDoc {
@@ -111,6 +181,43 @@ public:
 		bool operator<(const ConstantDoc &p_const) const {
 		bool operator<(const ConstantDoc &p_const) const {
 			return name < p_const.name;
 			return name < p_const.name;
 		}
 		}
+		static ConstantDoc from_dict(const Dictionary &p_dict) {
+			ConstantDoc doc;
+
+			if (p_dict.has("name")) {
+				doc.name = p_dict["name"];
+			}
+
+			if (p_dict.has("value")) {
+				doc.value = p_dict["value"];
+			}
+
+			if (p_dict.has("is_value_valid")) {
+				doc.is_value_valid = p_dict["is_value_valid"];
+			}
+
+			if (p_dict.has("enumeration")) {
+				doc.enumeration = p_dict["enumeration"];
+			}
+
+			if (p_dict.has("is_bitfield")) {
+				doc.is_bitfield = p_dict["is_bitfield"];
+			}
+
+			if (p_dict.has("description")) {
+				doc.description = p_dict["description"];
+			}
+
+			if (p_dict.has("is_deprecated")) {
+				doc.is_deprecated = p_dict["is_deprecated"];
+			}
+
+			if (p_dict.has("is_experimental")) {
+				doc.is_experimental = p_dict["is_experimental"];
+			}
+
+			return doc;
+		}
 	};
 	};
 
 
 	struct EnumDoc {
 	struct EnumDoc {
@@ -118,6 +225,31 @@ public:
 		bool is_bitfield = false;
 		bool is_bitfield = false;
 		String description;
 		String description;
 		Vector<DocData::ConstantDoc> values;
 		Vector<DocData::ConstantDoc> values;
+		static EnumDoc from_dict(const Dictionary &p_dict) {
+			EnumDoc doc;
+
+			if (p_dict.has("name")) {
+				doc.name = p_dict["name"];
+			}
+
+			if (p_dict.has("is_bitfield")) {
+				doc.is_bitfield = p_dict["is_bitfield"];
+			}
+
+			if (p_dict.has("description")) {
+				doc.description = p_dict["description"];
+			}
+
+			Array values;
+			if (p_dict.has("values")) {
+				values = p_dict["values"];
+			}
+			for (int i = 0; i < values.size(); i++) {
+				doc.values.push_back(ConstantDoc::from_dict(values[i]));
+			}
+
+			return doc;
+		}
 	};
 	};
 
 
 	struct PropertyDoc {
 	struct PropertyDoc {
@@ -134,6 +266,55 @@ public:
 		bool operator<(const PropertyDoc &p_prop) const {
 		bool operator<(const PropertyDoc &p_prop) const {
 			return name < p_prop.name;
 			return name < p_prop.name;
 		}
 		}
+		static PropertyDoc from_dict(const Dictionary &p_dict) {
+			PropertyDoc doc;
+
+			if (p_dict.has("name")) {
+				doc.name = p_dict["name"];
+			}
+
+			if (p_dict.has("type")) {
+				doc.type = p_dict["type"];
+			}
+
+			if (p_dict.has("enumeration")) {
+				doc.enumeration = p_dict["enumeration"];
+			}
+
+			if (p_dict.has("description")) {
+				doc.description = p_dict["description"];
+			}
+
+			if (p_dict.has("setter")) {
+				doc.setter = p_dict["setter"];
+			}
+
+			if (p_dict.has("getter")) {
+				doc.getter = p_dict["getter"];
+			}
+
+			if (p_dict.has("default_value")) {
+				doc.default_value = p_dict["default_value"];
+			}
+
+			if (p_dict.has("overridden")) {
+				doc.overridden = p_dict["overridden"];
+			}
+
+			if (p_dict.has("overrides")) {
+				doc.overrides = p_dict["overrides"];
+			}
+
+			if (p_dict.has("is_deprecated")) {
+				doc.is_deprecated = p_dict["is_deprecated"];
+			}
+
+			if (p_dict.has("is_experimental")) {
+				doc.is_experimental = p_dict["is_experimental"];
+			}
+
+			return doc;
+		}
 	};
 	};
 
 
 	struct ThemeItemDoc {
 	struct ThemeItemDoc {
@@ -149,11 +330,49 @@ public:
 			}
 			}
 			return data_type < p_theme_item.data_type;
 			return data_type < p_theme_item.data_type;
 		}
 		}
+		static ThemeItemDoc from_dict(const Dictionary &p_dict) {
+			ThemeItemDoc doc;
+
+			if (p_dict.has("name")) {
+				doc.name = p_dict["name"];
+			}
+
+			if (p_dict.has("type")) {
+				doc.type = p_dict["type"];
+			}
+
+			if (p_dict.has("data_type")) {
+				doc.data_type = p_dict["data_type"];
+			}
+
+			if (p_dict.has("description")) {
+				doc.description = p_dict["description"];
+			}
+
+			if (p_dict.has("default_value")) {
+				doc.default_value = p_dict["default_value"];
+			}
+
+			return doc;
+		}
 	};
 	};
 
 
 	struct TutorialDoc {
 	struct TutorialDoc {
 		String link;
 		String link;
 		String title;
 		String title;
+		static TutorialDoc from_dict(const Dictionary &p_dict) {
+			TutorialDoc doc;
+
+			if (p_dict.has("link")) {
+				doc.link = p_dict["link"];
+			}
+
+			if (p_dict.has("title")) {
+				doc.title = p_dict["title"];
+			}
+
+			return doc;
+		}
 	};
 	};
 
 
 	struct ClassDoc {
 	struct ClassDoc {
@@ -179,6 +398,127 @@ public:
 		bool operator<(const ClassDoc &p_class) const {
 		bool operator<(const ClassDoc &p_class) const {
 			return name < p_class.name;
 			return name < p_class.name;
 		}
 		}
+		static ClassDoc from_dict(const Dictionary &p_dict) {
+			ClassDoc doc;
+
+			if (p_dict.has("name")) {
+				doc.name = p_dict["name"];
+			}
+
+			if (p_dict.has("inherits")) {
+				doc.inherits = p_dict["inherits"];
+			}
+
+			if (p_dict.has("category")) {
+				doc.category = p_dict["category"];
+			}
+
+			if (p_dict.has("brief_description")) {
+				doc.brief_description = p_dict["brief_description"];
+			}
+
+			if (p_dict.has("description")) {
+				doc.description = p_dict["description"];
+			}
+
+			Array tutorials;
+			if (p_dict.has("tutorials")) {
+				tutorials = p_dict["tutorials"];
+			}
+			for (int i = 0; i < tutorials.size(); i++) {
+				doc.tutorials.push_back(TutorialDoc::from_dict(tutorials[i]));
+			}
+
+			Array constructors;
+			if (p_dict.has("constructors")) {
+				constructors = p_dict["constructors"];
+			}
+			for (int i = 0; i < constructors.size(); i++) {
+				doc.constructors.push_back(MethodDoc::from_dict(constructors[i]));
+			}
+
+			Array methods;
+			if (p_dict.has("methods")) {
+				methods = p_dict["methods"];
+			}
+			for (int i = 0; i < methods.size(); i++) {
+				doc.methods.push_back(MethodDoc::from_dict(methods[i]));
+			}
+
+			Array operators;
+			if (p_dict.has("operators")) {
+				operators = p_dict["operators"];
+			}
+			for (int i = 0; i < operators.size(); i++) {
+				doc.operators.push_back(MethodDoc::from_dict(operators[i]));
+			}
+
+			Array signals;
+			if (p_dict.has("signals")) {
+				signals = p_dict["signals"];
+			}
+			for (int i = 0; i < signals.size(); i++) {
+				doc.signals.push_back(MethodDoc::from_dict(signals[i]));
+			}
+
+			Array constants;
+			if (p_dict.has("constants")) {
+				constants = p_dict["constants"];
+			}
+			for (int i = 0; i < constants.size(); i++) {
+				doc.constants.push_back(ConstantDoc::from_dict(constants[i]));
+			}
+
+			Dictionary enums;
+			if (p_dict.has("enums")) {
+				enums = p_dict["enums"];
+			}
+			for (int i = 0; i < enums.size(); i++) {
+				doc.enums[enums.get_key_at_index(i)] = enums.get_value_at_index(i);
+			}
+
+			Array properties;
+			if (p_dict.has("properties")) {
+				properties = p_dict["properties"];
+			}
+			for (int i = 0; i < properties.size(); i++) {
+				doc.properties.push_back(PropertyDoc::from_dict(properties[i]));
+			}
+
+			Array annotations;
+			if (p_dict.has("annotations")) {
+				annotations = p_dict["annotations"];
+			}
+			for (int i = 0; i < annotations.size(); i++) {
+				doc.annotations.push_back(MethodDoc::from_dict(annotations[i]));
+			}
+
+			Array theme_properties;
+			if (p_dict.has("theme_properties")) {
+				theme_properties = p_dict["theme_properties"];
+			}
+			for (int i = 0; i < theme_properties.size(); i++) {
+				doc.theme_properties.push_back(ThemeItemDoc::from_dict(theme_properties[i]));
+			}
+
+			if (p_dict.has("is_deprecated")) {
+				doc.is_deprecated = p_dict["is_deprecated"];
+			}
+
+			if (p_dict.has("is_experimental")) {
+				doc.is_experimental = p_dict["is_experimental"];
+			}
+
+			if (p_dict.has("is_script_doc")) {
+				doc.is_script_doc = p_dict["is_script_doc"];
+			}
+
+			if (p_dict.has("script_path")) {
+				doc.script_path = p_dict["script_path"];
+			}
+
+			return doc;
+		}
 	};
 	};
 
 
 	static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo);
 	static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo);

+ 4 - 1
core/object/script_language_extension.h

@@ -82,7 +82,10 @@ public:
 		GDVIRTUAL_REQUIRED_CALL(_get_documentation, doc);
 		GDVIRTUAL_REQUIRED_CALL(_get_documentation, doc);
 
 
 		Vector<DocData::ClassDoc> class_doc;
 		Vector<DocData::ClassDoc> class_doc;
-		// TODO: Missing conversion from documentation to ClassDoc.
+		for (int i = 0; i < doc.size(); i++) {
+			class_doc.append(DocData::ClassDoc::from_dict(doc[i]));
+		}
+
 		return class_doc;
 		return class_doc;
 	}
 	}
 #endif // TOOLS_ENABLED
 #endif // TOOLS_ENABLED