| 4301 | } |
| 4302 | |
| 4303 | ::Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) { |
| 4304 | // Before parsing, try the usual stuff. |
| 4305 | if (p_symbol.is_empty()) { |
| 4306 | r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS; |
| 4307 | r_result.class_name = "Variant"; //Nil |
| 4308 | return ERR_CANT_RESOLVE; |
| 4309 | } |
| 4310 | |
| 4311 | if (ClassDB::class_exists(p_symbol)) { |
| 4312 | r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS; |
| 4313 | r_result.class_name = p_symbol; |
| 4314 | return OK; |
| 4315 | } |
| 4316 | |
| 4317 | if (Variant::get_type_by_name(p_symbol) < Variant::VARIANT_MAX) { |
| 4318 | r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS; |
| 4319 | r_result.class_name = p_symbol; |
| 4320 | return OK; |
| 4321 | } |
| 4322 | |
| 4323 | if (p_symbol == "Variant") { |
| 4324 | r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS; |
| 4325 | r_result.class_name = "Variant"; |
| 4326 | return OK; |
| 4327 | } |
| 4328 | |
| 4329 | if (p_symbol == "PI" || p_symbol == "TAU" || p_symbol == "INF" || p_symbol == "NAN") { |
| 4330 | r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS_CONSTANT; |
| 4331 | r_result.class_name = "@GDScript"; |
| 4332 | r_result.class_member = p_symbol; |
| 4333 | return OK; |
| 4334 | } |
| 4335 | |
| 4336 | GDScriptParser parser; |
| 4337 | parser.parse(p_code, p_path, true); |
| 4338 | |
| 4339 | GDScriptParser::CompletionContext context = parser.get_completion_context(); |
| 4340 | context.base = p_owner; |
| 4341 | |
| 4342 | // Allows class functions with the names like built-ins to be handled properly. |
| 4343 | if (context.type != GDScriptParser::COMPLETION_ATTRIBUTE) { |
| 4344 | // Need special checks for `assert` and `preload` as they are technically |
| 4345 | // keywords, so are not registered in `GDScriptUtilityFunctions`. |
| 4346 | if (GDScriptUtilityFunctions::function_exists(p_symbol) || p_symbol == "assert" || p_symbol == "preload") { |
| 4347 | r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS_METHOD; |
| 4348 | r_result.class_name = "@GDScript"; |
| 4349 | r_result.class_member = p_symbol; |
| 4350 | return OK; |
| 4351 | } |
| 4352 | } |
| 4353 | |
| 4354 | GDScriptAnalyzer analyzer(&parser); |
| 4355 | analyzer.analyze(); |
| 4356 | |
| 4357 | if (context.current_class && context.current_class->extends.size() > 0) { |
| 4358 | StringName class_name = context.current_class->extends[0]->name; |
| 4359 | |
| 4360 | bool success = false; |
no test coverage detected