From b94a0d486daeb8dfd28fd41b2b1953c532126db3 Mon Sep 17 00:00:00 2001 From: SnailRhymer Date: Wed, 1 Jun 2022 18:57:07 +0100 Subject: [PATCH] Make Lookup Symbol recognize assert, preload, and yield in the script editor --- modules/gdscript/gdscript_editor.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index e93f6bd12cc..b9a544600de 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -3300,7 +3300,7 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co } Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) { - //before parsing, try the usual stuff + // Before parsing, try the usual stuff. if (ClassDB::class_exists(p_symbol)) { r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS; r_result.class_name = p_symbol; @@ -3534,16 +3534,24 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol } } + // Must check GDScript functions after parsing to ensure functions like Array.max() are handled correctly. + bool function_in_gdscript_functions = false; for (int i = 0; i < GDScriptFunctions::FUNC_MAX; i++) { - // this has to get run after parsing because otherwise functions like Array.max() will trigger it if (GDScriptFunctions::get_func_name(GDScriptFunctions::Function(i)) == p_symbol) { - r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_METHOD; - r_result.class_name = "@GDScript"; - r_result.class_member = p_symbol; - return OK; + function_in_gdscript_functions = true; + break; } } + // Need special checks for assert, preload, and yield as they are technically + // keywords, so are not registered in GDScriptFunctions. + if (function_in_gdscript_functions || "yield" == p_symbol || "assert" == p_symbol || "preload" == p_symbol) { + r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_METHOD; + r_result.class_name = "@GDScript"; + r_result.class_member = p_symbol; + return OK; + } + return ERR_CANT_RESOLVE; }