gdscript_workspace.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /*************************************************************************/
  2. /* gdscript_workspace.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  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_workspace.h"
  31. #include "../gdscript.h"
  32. #include "../gdscript_parser.h"
  33. #include "core/project_settings.h"
  34. #include "core/script_language.h"
  35. #include "editor/editor_help.h"
  36. #include "gdscript_language_protocol.h"
  37. void GDScriptWorkspace::_bind_methods() {
  38. ClassDB::bind_method(D_METHOD("symbol"), &GDScriptWorkspace::symbol);
  39. ClassDB::bind_method(D_METHOD("parse_script", "p_path", "p_content"), &GDScriptWorkspace::parse_script);
  40. ClassDB::bind_method(D_METHOD("parse_local_script", "p_path"), &GDScriptWorkspace::parse_local_script);
  41. ClassDB::bind_method(D_METHOD("get_file_path", "p_uri"), &GDScriptWorkspace::get_file_path);
  42. ClassDB::bind_method(D_METHOD("get_file_uri", "p_path"), &GDScriptWorkspace::get_file_uri);
  43. ClassDB::bind_method(D_METHOD("publish_diagnostics", "p_path"), &GDScriptWorkspace::publish_diagnostics);
  44. ClassDB::bind_method(D_METHOD("generate_script_api", "p_path"), &GDScriptWorkspace::generate_script_api);
  45. }
  46. void GDScriptWorkspace::remove_cache_parser(const String &p_path) {
  47. Map<String, ExtendGDScriptParser *>::Element *parser = parse_results.find(p_path);
  48. Map<String, ExtendGDScriptParser *>::Element *script = scripts.find(p_path);
  49. if (parser && script) {
  50. if (script->get() && script->get() == script->get()) {
  51. memdelete(script->get());
  52. } else {
  53. memdelete(script->get());
  54. memdelete(parser->get());
  55. }
  56. parse_results.erase(p_path);
  57. scripts.erase(p_path);
  58. } else if (parser) {
  59. memdelete(parser->get());
  60. parse_results.erase(p_path);
  61. } else if (script) {
  62. memdelete(script->get());
  63. scripts.erase(p_path);
  64. }
  65. }
  66. const lsp::DocumentSymbol *GDScriptWorkspace::get_native_symbol(const String &p_class, const String &p_member) const {
  67. StringName class_name = p_class;
  68. StringName empty;
  69. while (class_name != empty) {
  70. if (const Map<StringName, lsp::DocumentSymbol>::Element *E = native_symbols.find(class_name)) {
  71. const lsp::DocumentSymbol &class_symbol = E->value();
  72. if (p_member.empty()) {
  73. return &class_symbol;
  74. } else {
  75. for (int i = 0; i < class_symbol.children.size(); i++) {
  76. const lsp::DocumentSymbol &symbol = class_symbol.children[i];
  77. if (symbol.name == p_member) {
  78. return &symbol;
  79. }
  80. }
  81. }
  82. }
  83. class_name = ClassDB::get_parent_class(class_name);
  84. }
  85. return NULL;
  86. }
  87. const lsp::DocumentSymbol *GDScriptWorkspace::get_script_symbol(const String &p_path) const {
  88. const Map<String, ExtendGDScriptParser *>::Element *S = scripts.find(p_path);
  89. if (S) {
  90. return &(S->get()->get_symbols());
  91. }
  92. return NULL;
  93. }
  94. void GDScriptWorkspace::reload_all_workspace_scripts() {
  95. List<String> paths;
  96. list_script_files("res://", paths);
  97. for (List<String>::Element *E = paths.front(); E; E = E->next()) {
  98. const String &path = E->get();
  99. Error err;
  100. String content = FileAccess::get_file_as_string(path, &err);
  101. ERR_CONTINUE(err != OK);
  102. err = parse_script(path, content);
  103. if (err != OK) {
  104. Map<String, ExtendGDScriptParser *>::Element *S = parse_results.find(path);
  105. String err_msg = "Failed parse script " + path;
  106. if (S) {
  107. err_msg += "\n" + S->get()->get_error();
  108. }
  109. ERR_CONTINUE_MSG(err != OK, err_msg);
  110. }
  111. }
  112. }
  113. void GDScriptWorkspace::list_script_files(const String &p_root_dir, List<String> &r_files) {
  114. Error err;
  115. DirAccessRef dir = DirAccess::open(p_root_dir, &err);
  116. if (OK == err) {
  117. dir->list_dir_begin();
  118. String file_name = dir->get_next();
  119. while (file_name.length()) {
  120. if (dir->current_is_dir() && file_name != "." && file_name != ".." && file_name != "./") {
  121. list_script_files(p_root_dir.plus_file(file_name), r_files);
  122. } else if (file_name.ends_with(".gd")) {
  123. String script_file = p_root_dir.plus_file(file_name);
  124. r_files.push_back(script_file);
  125. }
  126. file_name = dir->get_next();
  127. }
  128. }
  129. }
  130. ExtendGDScriptParser *GDScriptWorkspace::get_parse_successed_script(const String &p_path) {
  131. const Map<String, ExtendGDScriptParser *>::Element *S = scripts.find(p_path);
  132. if (!S) {
  133. parse_local_script(p_path);
  134. S = scripts.find(p_path);
  135. }
  136. if (S) {
  137. return S->get();
  138. }
  139. return NULL;
  140. }
  141. ExtendGDScriptParser *GDScriptWorkspace::get_parse_result(const String &p_path) {
  142. const Map<String, ExtendGDScriptParser *>::Element *S = parse_results.find(p_path);
  143. if (!S) {
  144. parse_local_script(p_path);
  145. S = parse_results.find(p_path);
  146. }
  147. if (S) {
  148. return S->get();
  149. }
  150. return NULL;
  151. }
  152. Array GDScriptWorkspace::symbol(const Dictionary &p_params) {
  153. String query = p_params["query"];
  154. Array arr;
  155. if (!query.empty()) {
  156. for (Map<String, ExtendGDScriptParser *>::Element *E = scripts.front(); E; E = E->next()) {
  157. Vector<lsp::DocumentedSymbolInformation> script_symbols;
  158. E->get()->get_symbols().symbol_tree_as_list(E->key(), script_symbols);
  159. for (int i = 0; i < script_symbols.size(); ++i) {
  160. if (query.is_subsequence_ofi(script_symbols[i].name)) {
  161. arr.push_back(script_symbols[i].to_json());
  162. }
  163. }
  164. }
  165. }
  166. return arr;
  167. }
  168. Error GDScriptWorkspace::initialize() {
  169. if (initialized) return OK;
  170. DocData *doc = EditorHelp::get_doc_data();
  171. for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) {
  172. const DocData::ClassDoc &class_data = E->value();
  173. lsp::DocumentSymbol class_symbol;
  174. String class_name = E->key();
  175. class_symbol.name = class_name;
  176. class_symbol.native_class = class_name;
  177. class_symbol.kind = lsp::SymbolKind::Class;
  178. class_symbol.detail = String("<Native> class ") + class_name;
  179. if (!class_data.inherits.empty()) {
  180. class_symbol.detail += " extends " + class_data.inherits;
  181. }
  182. class_symbol.documentation = class_data.brief_description + "\n" + class_data.description;
  183. for (int i = 0; i < class_data.constants.size(); i++) {
  184. const DocData::ConstantDoc &const_data = class_data.constants[i];
  185. lsp::DocumentSymbol symbol;
  186. symbol.name = const_data.name;
  187. symbol.native_class = class_name;
  188. symbol.kind = lsp::SymbolKind::Constant;
  189. symbol.detail = "const " + class_name + "." + const_data.name;
  190. if (const_data.enumeration.length()) {
  191. symbol.detail += ": " + const_data.enumeration;
  192. }
  193. symbol.detail += " = " + const_data.value;
  194. symbol.documentation = const_data.description;
  195. class_symbol.children.push_back(symbol);
  196. }
  197. Vector<DocData::PropertyDoc> properties;
  198. properties.append_array(class_data.properties);
  199. const int theme_prop_start_idx = properties.size();
  200. properties.append_array(class_data.theme_properties);
  201. for (int i = 0; i < class_data.properties.size(); i++) {
  202. const DocData::PropertyDoc &data = class_data.properties[i];
  203. lsp::DocumentSymbol symbol;
  204. symbol.name = data.name;
  205. symbol.native_class = class_name;
  206. symbol.kind = lsp::SymbolKind::Property;
  207. symbol.detail = String(i >= theme_prop_start_idx ? "<Theme> var" : "var") + " " + class_name + "." + data.name;
  208. if (data.enumeration.length()) {
  209. symbol.detail += ": " + data.enumeration;
  210. } else {
  211. symbol.detail += ": " + data.type;
  212. }
  213. symbol.documentation = data.description;
  214. class_symbol.children.push_back(symbol);
  215. }
  216. Vector<DocData::MethodDoc> methods_signals;
  217. methods_signals.append_array(class_data.methods);
  218. const int signal_start_idx = methods_signals.size();
  219. methods_signals.append_array(class_data.signals);
  220. for (int i = 0; i < methods_signals.size(); i++) {
  221. const DocData::MethodDoc &data = methods_signals[i];
  222. lsp::DocumentSymbol symbol;
  223. symbol.name = data.name;
  224. symbol.native_class = class_name;
  225. symbol.kind = i >= signal_start_idx ? lsp::SymbolKind::Event : lsp::SymbolKind::Method;
  226. String params = "";
  227. bool arg_default_value_started = false;
  228. for (int j = 0; j < data.arguments.size(); j++) {
  229. const DocData::ArgumentDoc &arg = data.arguments[j];
  230. lsp::DocumentSymbol symbol_arg;
  231. symbol_arg.name = arg.name;
  232. symbol_arg.kind = lsp::SymbolKind::Variable;
  233. symbol_arg.detail = arg.type;
  234. if (!arg_default_value_started && !arg.default_value.empty()) {
  235. arg_default_value_started = true;
  236. }
  237. String arg_str = arg.name + ": " + arg.type;
  238. if (arg_default_value_started) {
  239. arg_str += " = " + arg.default_value;
  240. }
  241. if (j < data.arguments.size() - 1) {
  242. arg_str += ", ";
  243. }
  244. params += arg_str;
  245. symbol.children.push_back(symbol_arg);
  246. }
  247. if (data.qualifiers.find("vararg") != -1) {
  248. params += params.empty() ? "..." : ", ...";
  249. }
  250. String return_type = data.return_type;
  251. if (return_type.empty()) {
  252. return_type = "void";
  253. }
  254. symbol.detail = "func " + class_name + "." + data.name + "(" + params + ") -> " + return_type;
  255. symbol.documentation = data.description;
  256. class_symbol.children.push_back(symbol);
  257. }
  258. native_symbols.insert(class_name, class_symbol);
  259. }
  260. reload_all_workspace_scripts();
  261. if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) {
  262. for (Map<StringName, lsp::DocumentSymbol>::Element *E = native_symbols.front(); E; E = E->next()) {
  263. ClassMembers members;
  264. const lsp::DocumentSymbol &class_symbol = E->get();
  265. for (int i = 0; i < class_symbol.children.size(); i++) {
  266. const lsp::DocumentSymbol &symbol = class_symbol.children[i];
  267. members.set(symbol.name, &symbol);
  268. }
  269. native_members.set(E->key(), members);
  270. }
  271. // cache member completions
  272. for (Map<String, ExtendGDScriptParser *>::Element *S = scripts.front(); S; S = S->next()) {
  273. S->get()->get_member_completions();
  274. }
  275. }
  276. return OK;
  277. }
  278. Error GDScriptWorkspace::parse_script(const String &p_path, const String &p_content) {
  279. ExtendGDScriptParser *parser = memnew(ExtendGDScriptParser);
  280. Error err = parser->parse(p_content, p_path);
  281. Map<String, ExtendGDScriptParser *>::Element *last_parser = parse_results.find(p_path);
  282. Map<String, ExtendGDScriptParser *>::Element *last_script = scripts.find(p_path);
  283. if (err == OK) {
  284. remove_cache_parser(p_path);
  285. parse_results[p_path] = parser;
  286. scripts[p_path] = parser;
  287. } else {
  288. if (last_parser && last_script && last_parser->get() != last_script->get()) {
  289. memdelete(last_parser->get());
  290. }
  291. parse_results[p_path] = parser;
  292. }
  293. publish_diagnostics(p_path);
  294. return err;
  295. }
  296. Error GDScriptWorkspace::parse_local_script(const String &p_path) {
  297. Error err;
  298. String content = FileAccess::get_file_as_string(p_path, &err);
  299. if (err == OK) {
  300. err = parse_script(p_path, content);
  301. }
  302. return err;
  303. }
  304. String GDScriptWorkspace::get_file_path(const String &p_uri) const {
  305. String path = p_uri;
  306. path = path.replace(root_uri + "/", "res://");
  307. path = path.http_unescape();
  308. return path;
  309. }
  310. String GDScriptWorkspace::get_file_uri(const String &p_path) const {
  311. String uri = p_path;
  312. uri = uri.replace("res://", root_uri + "/");
  313. return uri;
  314. }
  315. void GDScriptWorkspace::publish_diagnostics(const String &p_path) {
  316. Dictionary params;
  317. Array errors;
  318. const Map<String, ExtendGDScriptParser *>::Element *ele = parse_results.find(p_path);
  319. if (ele) {
  320. const Vector<lsp::Diagnostic> &list = ele->get()->get_diagnostics();
  321. errors.resize(list.size());
  322. for (int i = 0; i < list.size(); ++i) {
  323. errors[i] = list[i].to_json();
  324. }
  325. }
  326. params["diagnostics"] = errors;
  327. params["uri"] = get_file_uri(p_path);
  328. GDScriptLanguageProtocol::get_singleton()->notify_client("textDocument/publishDiagnostics", params);
  329. }
  330. void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<ScriptCodeCompletionOption> *r_options) {
  331. String path = get_file_path(p_params.textDocument.uri);
  332. String call_hint;
  333. bool forced = false;
  334. if (const ExtendGDScriptParser *parser = get_parse_result(path)) {
  335. String code = parser->get_text_for_completion(p_params.position);
  336. GDScriptLanguage::get_singleton()->complete_code(code, path, NULL, r_options, forced, call_hint);
  337. }
  338. }
  339. const lsp::DocumentSymbol *GDScriptWorkspace::resolve_symbol(const lsp::TextDocumentPositionParams &p_doc_pos, const String &p_symbol_name, bool p_func_requred) {
  340. const lsp::DocumentSymbol *symbol = NULL;
  341. String path = get_file_path(p_doc_pos.textDocument.uri);
  342. if (const ExtendGDScriptParser *parser = get_parse_result(path)) {
  343. String symbol_identifier = p_symbol_name;
  344. Vector<String> identifier_parts = symbol_identifier.split("(");
  345. if (identifier_parts.size()) {
  346. symbol_identifier = identifier_parts[0];
  347. }
  348. lsp::Position pos = p_doc_pos.position;
  349. if (symbol_identifier.empty()) {
  350. Vector2i offset;
  351. symbol_identifier = parser->get_identifier_under_position(p_doc_pos.position, offset);
  352. pos.character += offset.y;
  353. }
  354. if (!symbol_identifier.empty()) {
  355. if (ScriptServer::is_global_class(symbol_identifier)) {
  356. String class_path = ScriptServer::get_global_class_path(symbol_identifier);
  357. symbol = get_script_symbol(class_path);
  358. } else {
  359. ScriptLanguage::LookupResult ret;
  360. if (OK == GDScriptLanguage::get_singleton()->lookup_code(parser->get_text_for_lookup_symbol(pos, symbol_identifier, p_func_requred), symbol_identifier, path, NULL, ret)) {
  361. if (ret.type == ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION) {
  362. String target_script_path = path;
  363. if (!ret.script.is_null()) {
  364. target_script_path = ret.script->get_path();
  365. }
  366. if (const ExtendGDScriptParser *target_parser = get_parse_result(target_script_path)) {
  367. symbol = target_parser->get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(ret.location));
  368. }
  369. } else {
  370. String member = ret.class_member;
  371. if (member.empty() && symbol_identifier != ret.class_name) {
  372. member = symbol_identifier;
  373. }
  374. symbol = get_native_symbol(ret.class_name, member);
  375. }
  376. } else {
  377. symbol = parser->get_member_symbol(symbol_identifier);
  378. }
  379. }
  380. }
  381. }
  382. return symbol;
  383. }
  384. void GDScriptWorkspace::resolve_related_symbols(const lsp::TextDocumentPositionParams &p_doc_pos, List<const lsp::DocumentSymbol *> &r_list) {
  385. String path = get_file_path(p_doc_pos.textDocument.uri);
  386. if (const ExtendGDScriptParser *parser = get_parse_result(path)) {
  387. String symbol_identifier;
  388. Vector2i offset;
  389. symbol_identifier = parser->get_identifier_under_position(p_doc_pos.position, offset);
  390. const StringName *class_ptr = native_members.next(NULL);
  391. while (class_ptr) {
  392. const ClassMembers &members = native_members.get(*class_ptr);
  393. if (const lsp::DocumentSymbol *const *symbol = members.getptr(symbol_identifier)) {
  394. r_list.push_back(*symbol);
  395. }
  396. class_ptr = native_members.next(class_ptr);
  397. }
  398. for (Map<String, ExtendGDScriptParser *>::Element *E = scripts.front(); E; E = E->next()) {
  399. const ExtendGDScriptParser *script = E->get();
  400. const ClassMembers &members = script->get_members();
  401. if (const lsp::DocumentSymbol *const *symbol = members.getptr(symbol_identifier)) {
  402. r_list.push_back(*symbol);
  403. }
  404. const HashMap<String, ClassMembers> &inner_classes = script->get_inner_classes();
  405. const String *_class = inner_classes.next(NULL);
  406. while (_class) {
  407. const ClassMembers *inner_class = inner_classes.getptr(*_class);
  408. if (const lsp::DocumentSymbol *const *symbol = inner_class->getptr(symbol_identifier)) {
  409. r_list.push_back(*symbol);
  410. }
  411. _class = inner_classes.next(_class);
  412. }
  413. }
  414. }
  415. }
  416. const lsp::DocumentSymbol *GDScriptWorkspace::resolve_native_symbol(const lsp::NativeSymbolInspectParams &p_params) {
  417. if (Map<StringName, lsp::DocumentSymbol>::Element *E = native_symbols.find(p_params.native_class)) {
  418. const lsp::DocumentSymbol &symbol = E->get();
  419. if (p_params.symbol_name.empty() || p_params.symbol_name == symbol.name) {
  420. return &symbol;
  421. }
  422. for (int i = 0; i < symbol.children.size(); ++i) {
  423. if (symbol.children[i].name == p_params.symbol_name) {
  424. return &(symbol.children[i]);
  425. }
  426. }
  427. }
  428. return NULL;
  429. }
  430. void GDScriptWorkspace::resolve_document_links(const String &p_uri, List<lsp::DocumentLink> &r_list) {
  431. if (const ExtendGDScriptParser *parser = get_parse_successed_script(get_file_path(p_uri))) {
  432. const List<lsp::DocumentLink> &links = parser->get_document_links();
  433. for (const List<lsp::DocumentLink>::Element *E = links.front(); E; E = E->next()) {
  434. r_list.push_back(E->get());
  435. }
  436. }
  437. }
  438. Dictionary GDScriptWorkspace::generate_script_api(const String &p_path) {
  439. Dictionary api;
  440. if (const ExtendGDScriptParser *parser = get_parse_successed_script(p_path)) {
  441. api = parser->generate_api();
  442. }
  443. return api;
  444. }
  445. Error GDScriptWorkspace::resolve_signature(const lsp::TextDocumentPositionParams &p_doc_pos, lsp::SignatureHelp &r_signature) {
  446. if (const ExtendGDScriptParser *parser = get_parse_result(get_file_path(p_doc_pos.textDocument.uri))) {
  447. lsp::TextDocumentPositionParams text_pos;
  448. text_pos.textDocument = p_doc_pos.textDocument;
  449. if (parser->get_left_function_call(p_doc_pos.position, text_pos.position, r_signature.activeParameter) == OK) {
  450. List<const lsp::DocumentSymbol *> symbols;
  451. if (const lsp::DocumentSymbol *symbol = resolve_symbol(text_pos)) {
  452. symbols.push_back(symbol);
  453. } else if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) {
  454. GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_related_symbols(text_pos, symbols);
  455. }
  456. for (List<const lsp::DocumentSymbol *>::Element *E = symbols.front(); E; E = E->next()) {
  457. const lsp::DocumentSymbol *symbol = E->get();
  458. if (symbol->kind == lsp::SymbolKind::Method || symbol->kind == lsp::SymbolKind::Function) {
  459. lsp::SignatureInformation signature_info;
  460. signature_info.label = symbol->detail;
  461. signature_info.documentation = symbol->render();
  462. for (int i = 0; i < symbol->children.size(); i++) {
  463. const lsp::DocumentSymbol &arg = symbol->children[i];
  464. lsp::ParameterInformation arg_info;
  465. arg_info.label = arg.name;
  466. signature_info.parameters.push_back(arg_info);
  467. }
  468. r_signature.signatures.push_back(signature_info);
  469. break;
  470. }
  471. }
  472. if (r_signature.signatures.size()) {
  473. return OK;
  474. }
  475. }
  476. }
  477. return ERR_METHOD_NOT_FOUND;
  478. }
  479. GDScriptWorkspace::GDScriptWorkspace() {
  480. ProjectSettings::get_singleton()->get_resource_path();
  481. }
  482. GDScriptWorkspace::~GDScriptWorkspace() {
  483. Set<String> cached_parsers;
  484. for (Map<String, ExtendGDScriptParser *>::Element *E = parse_results.front(); E; E = E->next()) {
  485. cached_parsers.insert(E->key());
  486. }
  487. for (Map<String, ExtendGDScriptParser *>::Element *E = scripts.front(); E; E = E->next()) {
  488. cached_parsers.insert(E->key());
  489. }
  490. for (Set<String>::Element *E = cached_parsers.front(); E; E = E->next()) {
  491. remove_cache_parser(E->get());
  492. }
  493. }