gdscript_docgen.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. /**************************************************************************/
  2. /* gdscript_docgen.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "gdscript_docgen.h"
  31. #include "../gdscript.h"
  32. #include "core/config/project_settings.h"
  33. HashMap<String, String> GDScriptDocGen::singletons;
  34. String GDScriptDocGen::_get_script_name(const String &p_path) {
  35. const HashMap<String, String>::ConstIterator E = singletons.find(p_path);
  36. if (E) {
  37. return E->value;
  38. }
  39. return p_path.trim_prefix("res://").quote();
  40. }
  41. String GDScriptDocGen::_get_class_name(const GDP::ClassNode &p_class) {
  42. const GDP::ClassNode *curr_class = &p_class;
  43. if (!curr_class->identifier) { // All inner classes have an identifier, so this is the outer class.
  44. return _get_script_name(curr_class->fqcn);
  45. }
  46. String full_name = curr_class->identifier->name;
  47. while (curr_class->outer) {
  48. curr_class = curr_class->outer;
  49. if (!curr_class->identifier) { // All inner classes have an identifier, so this is the outer class.
  50. return vformat("%s.%s", _get_script_name(curr_class->fqcn), full_name);
  51. }
  52. full_name = vformat("%s.%s", curr_class->identifier->name, full_name);
  53. }
  54. return full_name;
  55. }
  56. void GDScriptDocGen::_doctype_from_gdtype(const GDType &p_gdtype, String &r_type, String &r_enum, bool p_is_return) {
  57. if (!p_gdtype.is_hard_type()) {
  58. r_type = "Variant";
  59. return;
  60. }
  61. switch (p_gdtype.kind) {
  62. case GDType::BUILTIN:
  63. if (p_gdtype.builtin_type == Variant::NIL) {
  64. r_type = p_is_return ? "void" : "null";
  65. return;
  66. }
  67. if (p_gdtype.builtin_type == Variant::ARRAY && p_gdtype.has_container_element_type(0)) {
  68. _doctype_from_gdtype(p_gdtype.get_container_element_type(0), r_type, r_enum);
  69. if (!r_enum.is_empty()) {
  70. r_type = "int[]";
  71. r_enum += "[]";
  72. return;
  73. }
  74. if (!r_type.is_empty() && r_type != "Variant") {
  75. r_type += "[]";
  76. return;
  77. }
  78. }
  79. if (p_gdtype.builtin_type == Variant::DICTIONARY && p_gdtype.has_container_element_types()) {
  80. String key, value;
  81. _doctype_from_gdtype(p_gdtype.get_container_element_type_or_variant(0), key, r_enum);
  82. _doctype_from_gdtype(p_gdtype.get_container_element_type_or_variant(1), value, r_enum);
  83. if (key != "Variant" || value != "Variant") {
  84. r_type = "Dictionary[" + key + ", " + value + "]";
  85. return;
  86. }
  87. }
  88. r_type = Variant::get_type_name(p_gdtype.builtin_type);
  89. return;
  90. case GDType::NATIVE:
  91. if (p_gdtype.is_meta_type) {
  92. //r_type = GDScriptNativeClass::get_class_static();
  93. r_type = "Object"; // "GDScriptNativeClass" refers to a blank page.
  94. return;
  95. }
  96. r_type = p_gdtype.native_type;
  97. return;
  98. case GDType::SCRIPT:
  99. if (p_gdtype.is_meta_type) {
  100. r_type = p_gdtype.script_type.is_valid() ? p_gdtype.script_type->get_class() : Script::get_class_static();
  101. return;
  102. }
  103. if (p_gdtype.script_type.is_valid()) {
  104. if (p_gdtype.script_type->get_global_name() != StringName()) {
  105. r_type = p_gdtype.script_type->get_global_name();
  106. return;
  107. }
  108. if (!p_gdtype.script_type->get_path().is_empty()) {
  109. r_type = _get_script_name(p_gdtype.script_type->get_path());
  110. return;
  111. }
  112. }
  113. if (!p_gdtype.script_path.is_empty()) {
  114. r_type = _get_script_name(p_gdtype.script_path);
  115. return;
  116. }
  117. r_type = "Object";
  118. return;
  119. case GDType::CLASS:
  120. if (p_gdtype.is_meta_type) {
  121. r_type = GDScript::get_class_static();
  122. return;
  123. }
  124. r_type = _get_class_name(*p_gdtype.class_type);
  125. return;
  126. case GDType::ENUM:
  127. if (p_gdtype.is_meta_type) {
  128. r_type = "Dictionary";
  129. return;
  130. }
  131. r_type = "int";
  132. r_enum = String(p_gdtype.native_type).replace("::", ".");
  133. if (r_enum.begins_with("res://")) {
  134. int dot_pos = r_enum.rfind_char('.');
  135. if (dot_pos >= 0) {
  136. r_enum = _get_script_name(r_enum.left(dot_pos)) + r_enum.substr(dot_pos);
  137. } else {
  138. r_enum = _get_script_name(r_enum);
  139. }
  140. }
  141. return;
  142. case GDType::VARIANT:
  143. case GDType::RESOLVING:
  144. case GDType::UNRESOLVED:
  145. r_type = "Variant";
  146. return;
  147. }
  148. }
  149. String GDScriptDocGen::_docvalue_from_variant(const Variant &p_variant, int p_recursion_level) {
  150. constexpr int MAX_RECURSION_LEVEL = 2;
  151. switch (p_variant.get_type()) {
  152. case Variant::STRING:
  153. return String(p_variant).c_escape().quote();
  154. case Variant::OBJECT:
  155. return "<Object>";
  156. case Variant::DICTIONARY: {
  157. const Dictionary dict = p_variant;
  158. String result;
  159. if (dict.is_typed()) {
  160. result += "Dictionary[";
  161. Ref<Script> key_script = dict.get_typed_key_script();
  162. if (key_script.is_valid()) {
  163. if (key_script->get_global_name() != StringName()) {
  164. result += key_script->get_global_name();
  165. } else if (!key_script->get_path().get_file().is_empty()) {
  166. result += key_script->get_path().get_file();
  167. } else {
  168. result += dict.get_typed_key_class_name();
  169. }
  170. } else if (dict.get_typed_key_class_name() != StringName()) {
  171. result += dict.get_typed_key_class_name();
  172. } else if (dict.is_typed_key()) {
  173. result += Variant::get_type_name((Variant::Type)dict.get_typed_key_builtin());
  174. } else {
  175. result += "Variant";
  176. }
  177. result += ", ";
  178. Ref<Script> value_script = dict.get_typed_value_script();
  179. if (value_script.is_valid()) {
  180. if (value_script->get_global_name() != StringName()) {
  181. result += value_script->get_global_name();
  182. } else if (!value_script->get_path().get_file().is_empty()) {
  183. result += value_script->get_path().get_file();
  184. } else {
  185. result += dict.get_typed_value_class_name();
  186. }
  187. } else if (dict.get_typed_value_class_name() != StringName()) {
  188. result += dict.get_typed_value_class_name();
  189. } else if (dict.is_typed_value()) {
  190. result += Variant::get_type_name((Variant::Type)dict.get_typed_value_builtin());
  191. } else {
  192. result += "Variant";
  193. }
  194. result += "](";
  195. }
  196. if (dict.is_empty()) {
  197. result += "{}";
  198. } else if (p_recursion_level > MAX_RECURSION_LEVEL) {
  199. result += "{...}";
  200. } else {
  201. result += "{";
  202. List<Variant> keys;
  203. dict.get_key_list(&keys);
  204. keys.sort_custom<StringLikeVariantOrder>();
  205. for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
  206. if (E->prev()) {
  207. result += ", ";
  208. }
  209. result += _docvalue_from_variant(E->get(), p_recursion_level + 1) + ": " + _docvalue_from_variant(dict[E->get()], p_recursion_level + 1);
  210. }
  211. result += "}";
  212. }
  213. if (dict.is_typed()) {
  214. result += ")";
  215. }
  216. return result;
  217. } break;
  218. case Variant::ARRAY: {
  219. const Array array = p_variant;
  220. String result;
  221. if (array.is_typed()) {
  222. result += "Array[";
  223. Ref<Script> script = array.get_typed_script();
  224. if (script.is_valid()) {
  225. if (script->get_global_name() != StringName()) {
  226. result += script->get_global_name();
  227. } else if (!script->get_path().get_file().is_empty()) {
  228. result += script->get_path().get_file();
  229. } else {
  230. result += array.get_typed_class_name();
  231. }
  232. } else if (array.get_typed_class_name() != StringName()) {
  233. result += array.get_typed_class_name();
  234. } else {
  235. result += Variant::get_type_name((Variant::Type)array.get_typed_builtin());
  236. }
  237. result += "](";
  238. }
  239. if (array.is_empty()) {
  240. result += "[]";
  241. } else if (p_recursion_level > MAX_RECURSION_LEVEL) {
  242. result += "[...]";
  243. } else {
  244. result += "[";
  245. for (int i = 0; i < array.size(); i++) {
  246. if (i > 0) {
  247. result += ", ";
  248. }
  249. result += _docvalue_from_variant(array[i], p_recursion_level + 1);
  250. }
  251. result += "]";
  252. }
  253. if (array.is_typed()) {
  254. result += ")";
  255. }
  256. return result;
  257. } break;
  258. default:
  259. return p_variant.get_construct_string();
  260. }
  261. }
  262. String GDScriptDocGen::docvalue_from_expression(const GDP::ExpressionNode *p_expression) {
  263. ERR_FAIL_NULL_V(p_expression, String());
  264. if (p_expression->is_constant) {
  265. return _docvalue_from_variant(p_expression->reduced_value);
  266. }
  267. switch (p_expression->type) {
  268. case GDP::Node::ARRAY: {
  269. const GDP::ArrayNode *array = static_cast<const GDP::ArrayNode *>(p_expression);
  270. return array->elements.is_empty() ? "[]" : "[...]";
  271. } break;
  272. case GDP::Node::CALL: {
  273. const GDP::CallNode *call = static_cast<const GDP::CallNode *>(p_expression);
  274. return call->function_name.operator String() + (call->arguments.is_empty() ? "()" : "(...)");
  275. } break;
  276. case GDP::Node::DICTIONARY: {
  277. const GDP::DictionaryNode *dict = static_cast<const GDP::DictionaryNode *>(p_expression);
  278. return dict->elements.is_empty() ? "{}" : "{...}";
  279. } break;
  280. case GDP::Node::IDENTIFIER: {
  281. const GDP::IdentifierNode *id = static_cast<const GDP::IdentifierNode *>(p_expression);
  282. return id->name;
  283. } break;
  284. default: {
  285. return "<unknown>";
  286. } break;
  287. }
  288. }
  289. void GDScriptDocGen::_generate_docs(GDScript *p_script, const GDP::ClassNode *p_class) {
  290. p_script->_clear_doc();
  291. DocData::ClassDoc &doc = p_script->doc;
  292. doc.is_script_doc = true;
  293. if (p_script->local_name == StringName()) {
  294. // This is an outer unnamed class.
  295. doc.name = _get_script_name(p_script->get_script_path());
  296. } else {
  297. // This is an inner or global outer class.
  298. doc.name = p_script->local_name;
  299. if (p_script->_owner) {
  300. doc.name = p_script->_owner->doc.name + "." + doc.name;
  301. }
  302. }
  303. doc.script_path = p_script->get_script_path();
  304. if (p_script->base.is_valid() && p_script->base->is_valid()) {
  305. if (!p_script->base->doc.name.is_empty()) {
  306. doc.inherits = p_script->base->doc.name;
  307. } else {
  308. doc.inherits = p_script->base->get_instance_base_type();
  309. }
  310. } else if (p_script->native.is_valid()) {
  311. doc.inherits = p_script->native->get_name();
  312. }
  313. doc.brief_description = p_class->doc_data.brief;
  314. doc.description = p_class->doc_data.description;
  315. for (const Pair<String, String> &p : p_class->doc_data.tutorials) {
  316. DocData::TutorialDoc td;
  317. td.title = p.first;
  318. td.link = p.second;
  319. doc.tutorials.append(td);
  320. }
  321. doc.is_deprecated = p_class->doc_data.is_deprecated;
  322. doc.deprecated_message = p_class->doc_data.deprecated_message;
  323. doc.is_experimental = p_class->doc_data.is_experimental;
  324. doc.experimental_message = p_class->doc_data.experimental_message;
  325. for (const GDP::ClassNode::Member &member : p_class->members) {
  326. switch (member.type) {
  327. case GDP::ClassNode::Member::CLASS: {
  328. const GDP::ClassNode *inner_class = member.m_class;
  329. const StringName &class_name = inner_class->identifier->name;
  330. p_script->member_lines[class_name] = inner_class->start_line;
  331. // Recursively generate inner class docs.
  332. // Needs inner GDScripts to exist: previously generated in GDScriptCompiler::make_scripts().
  333. GDScriptDocGen::_generate_docs(*p_script->subclasses[class_name], inner_class);
  334. } break;
  335. case GDP::ClassNode::Member::CONSTANT: {
  336. const GDP::ConstantNode *m_const = member.constant;
  337. const StringName &const_name = member.constant->identifier->name;
  338. p_script->member_lines[const_name] = m_const->start_line;
  339. DocData::ConstantDoc const_doc;
  340. const_doc.name = const_name;
  341. const_doc.value = _docvalue_from_variant(m_const->initializer->reduced_value);
  342. const_doc.is_value_valid = true;
  343. _doctype_from_gdtype(m_const->get_datatype(), const_doc.type, const_doc.enumeration);
  344. const_doc.description = m_const->doc_data.description;
  345. const_doc.is_deprecated = m_const->doc_data.is_deprecated;
  346. const_doc.deprecated_message = m_const->doc_data.deprecated_message;
  347. const_doc.is_experimental = m_const->doc_data.is_experimental;
  348. const_doc.experimental_message = m_const->doc_data.experimental_message;
  349. doc.constants.push_back(const_doc);
  350. } break;
  351. case GDP::ClassNode::Member::FUNCTION: {
  352. const GDP::FunctionNode *m_func = member.function;
  353. const StringName &func_name = m_func->identifier->name;
  354. p_script->member_lines[func_name] = m_func->start_line;
  355. DocData::MethodDoc method_doc;
  356. method_doc.name = func_name;
  357. method_doc.description = m_func->doc_data.description;
  358. method_doc.is_deprecated = m_func->doc_data.is_deprecated;
  359. method_doc.deprecated_message = m_func->doc_data.deprecated_message;
  360. method_doc.is_experimental = m_func->doc_data.is_experimental;
  361. method_doc.experimental_message = m_func->doc_data.experimental_message;
  362. method_doc.qualifiers = m_func->is_static ? "static" : "";
  363. if (func_name == "_init") {
  364. method_doc.return_type = "void";
  365. } else if (m_func->return_type) {
  366. // `m_func->return_type->get_datatype()` is a metatype.
  367. _doctype_from_gdtype(m_func->get_datatype(), method_doc.return_type, method_doc.return_enum, true);
  368. } else if (!m_func->body->has_return) {
  369. // If no `return` statement, then return type is `void`, not `Variant`.
  370. method_doc.return_type = "void";
  371. } else {
  372. method_doc.return_type = "Variant";
  373. }
  374. for (const GDP::ParameterNode *p : m_func->parameters) {
  375. DocData::ArgumentDoc arg_doc;
  376. arg_doc.name = p->identifier->name;
  377. _doctype_from_gdtype(p->get_datatype(), arg_doc.type, arg_doc.enumeration);
  378. if (p->initializer != nullptr) {
  379. arg_doc.default_value = docvalue_from_expression(p->initializer);
  380. }
  381. method_doc.arguments.push_back(arg_doc);
  382. }
  383. doc.methods.push_back(method_doc);
  384. } break;
  385. case GDP::ClassNode::Member::SIGNAL: {
  386. const GDP::SignalNode *m_signal = member.signal;
  387. const StringName &signal_name = m_signal->identifier->name;
  388. p_script->member_lines[signal_name] = m_signal->start_line;
  389. DocData::MethodDoc signal_doc;
  390. signal_doc.name = signal_name;
  391. signal_doc.description = m_signal->doc_data.description;
  392. signal_doc.is_deprecated = m_signal->doc_data.is_deprecated;
  393. signal_doc.deprecated_message = m_signal->doc_data.deprecated_message;
  394. signal_doc.is_experimental = m_signal->doc_data.is_experimental;
  395. signal_doc.experimental_message = m_signal->doc_data.experimental_message;
  396. for (const GDP::ParameterNode *p : m_signal->parameters) {
  397. DocData::ArgumentDoc arg_doc;
  398. arg_doc.name = p->identifier->name;
  399. _doctype_from_gdtype(p->get_datatype(), arg_doc.type, arg_doc.enumeration);
  400. signal_doc.arguments.push_back(arg_doc);
  401. }
  402. doc.signals.push_back(signal_doc);
  403. } break;
  404. case GDP::ClassNode::Member::VARIABLE: {
  405. const GDP::VariableNode *m_var = member.variable;
  406. const StringName &var_name = m_var->identifier->name;
  407. p_script->member_lines[var_name] = m_var->start_line;
  408. DocData::PropertyDoc prop_doc;
  409. prop_doc.name = var_name;
  410. prop_doc.description = m_var->doc_data.description;
  411. prop_doc.is_deprecated = m_var->doc_data.is_deprecated;
  412. prop_doc.deprecated_message = m_var->doc_data.deprecated_message;
  413. prop_doc.is_experimental = m_var->doc_data.is_experimental;
  414. prop_doc.experimental_message = m_var->doc_data.experimental_message;
  415. _doctype_from_gdtype(m_var->get_datatype(), prop_doc.type, prop_doc.enumeration);
  416. switch (m_var->property) {
  417. case GDP::VariableNode::PROP_NONE:
  418. break;
  419. case GDP::VariableNode::PROP_INLINE:
  420. if (m_var->setter != nullptr) {
  421. prop_doc.setter = m_var->setter->identifier->name;
  422. }
  423. if (m_var->getter != nullptr) {
  424. prop_doc.getter = m_var->getter->identifier->name;
  425. }
  426. break;
  427. case GDP::VariableNode::PROP_SETGET:
  428. if (m_var->setter_pointer != nullptr) {
  429. prop_doc.setter = m_var->setter_pointer->name;
  430. }
  431. if (m_var->getter_pointer != nullptr) {
  432. prop_doc.getter = m_var->getter_pointer->name;
  433. }
  434. break;
  435. }
  436. if (m_var->initializer != nullptr) {
  437. prop_doc.default_value = docvalue_from_expression(m_var->initializer);
  438. }
  439. prop_doc.overridden = false;
  440. doc.properties.push_back(prop_doc);
  441. } break;
  442. case GDP::ClassNode::Member::ENUM: {
  443. const GDP::EnumNode *m_enum = member.m_enum;
  444. StringName name = m_enum->identifier->name;
  445. p_script->member_lines[name] = m_enum->start_line;
  446. DocData::EnumDoc enum_doc;
  447. enum_doc.description = m_enum->doc_data.description;
  448. enum_doc.is_deprecated = m_enum->doc_data.is_deprecated;
  449. enum_doc.deprecated_message = m_enum->doc_data.deprecated_message;
  450. enum_doc.is_experimental = m_enum->doc_data.is_experimental;
  451. enum_doc.experimental_message = m_enum->doc_data.experimental_message;
  452. doc.enums[name] = enum_doc;
  453. for (const GDP::EnumNode::Value &val : m_enum->values) {
  454. DocData::ConstantDoc const_doc;
  455. const_doc.name = val.identifier->name;
  456. const_doc.value = _docvalue_from_variant(val.value);
  457. const_doc.is_value_valid = true;
  458. const_doc.type = "int";
  459. const_doc.enumeration = name;
  460. const_doc.description = val.doc_data.description;
  461. const_doc.is_deprecated = val.doc_data.is_deprecated;
  462. const_doc.deprecated_message = val.doc_data.deprecated_message;
  463. const_doc.is_experimental = val.doc_data.is_experimental;
  464. const_doc.experimental_message = val.doc_data.experimental_message;
  465. doc.constants.push_back(const_doc);
  466. }
  467. } break;
  468. case GDP::ClassNode::Member::ENUM_VALUE: {
  469. const GDP::EnumNode::Value &m_enum_val = member.enum_value;
  470. const StringName &name = m_enum_val.identifier->name;
  471. p_script->member_lines[name] = m_enum_val.identifier->start_line;
  472. DocData::ConstantDoc const_doc;
  473. const_doc.name = name;
  474. const_doc.value = _docvalue_from_variant(m_enum_val.value);
  475. const_doc.is_value_valid = true;
  476. const_doc.type = "int";
  477. const_doc.enumeration = "@unnamed_enums";
  478. const_doc.description = m_enum_val.doc_data.description;
  479. const_doc.is_deprecated = m_enum_val.doc_data.is_deprecated;
  480. const_doc.deprecated_message = m_enum_val.doc_data.deprecated_message;
  481. const_doc.is_experimental = m_enum_val.doc_data.is_experimental;
  482. const_doc.experimental_message = m_enum_val.doc_data.experimental_message;
  483. doc.constants.push_back(const_doc);
  484. } break;
  485. default:
  486. break;
  487. }
  488. }
  489. // Add doc to the outer-most class.
  490. p_script->_add_doc(doc);
  491. }
  492. void GDScriptDocGen::generate_docs(GDScript *p_script, const GDP::ClassNode *p_class) {
  493. for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : ProjectSettings::get_singleton()->get_autoload_list()) {
  494. if (E.value.is_singleton) {
  495. singletons[E.value.path] = E.key;
  496. }
  497. }
  498. _generate_docs(p_script, p_class);
  499. singletons.clear();
  500. }
  501. // This method is needed for the editor, since during autocompletion the script is not compiled, only analyzed.
  502. void GDScriptDocGen::doctype_from_gdtype(const GDType &p_gdtype, String &r_type, String &r_enum, bool p_is_return) {
  503. for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : ProjectSettings::get_singleton()->get_autoload_list()) {
  504. if (E.value.is_singleton) {
  505. singletons[E.value.path] = E.key;
  506. }
  507. }
  508. _doctype_from_gdtype(p_gdtype, r_type, r_enum, p_is_return);
  509. singletons.clear();
  510. }