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 committed by Relintai
parent 4bd8abc32b
commit cdc646fd63

View File

@ -3302,7 +3302,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;
@ -3536,15 +3536,23 @@ 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) {
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;
}