Make Lookup Symbol recognize assert, preload, and yield in the script editor

This commit is contained in:
SnailRhymer 2022-06-01 18:57:07 +01:00
parent cef6e91450
commit b94a0d486d

View File

@ -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) { 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)) { if (ClassDB::class_exists(p_symbol)) {
r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS; r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS;
r_result.class_name = p_symbol; 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++) { 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) { if (GDScriptFunctions::get_func_name(GDScriptFunctions::Function(i)) == p_symbol) {
r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_METHOD; function_in_gdscript_functions = true;
r_result.class_name = "@GDScript"; break;
r_result.class_member = p_symbol;
return OK;
} }
} }
// 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; return ERR_CANT_RESOLVE;
} }