Merge pull request #23337 from RandomShaper/fix-autocomplete-crash

Fix GDScript assuming awareness of whole ClassDB
This commit is contained in:
Rémi Verschelde 2018-10-31 10:36:25 +01:00 committed by GitHub
commit 45154be35f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 28 deletions

View File

@ -1308,38 +1308,39 @@ static bool _guess_identifier_type(const GDScriptCompletionContext &p_context, c
return false; return false;
} }
for (int i = 0; i < 2; i++) {
StringName target_id;
switch (i) {
case 0:
// Check ClassDB // Check ClassDB
if (ClassDB::class_exists(p_identifier)) { target_id = p_identifier;
r_type.type.has_type = true; break;
r_type.type.kind = GDScriptParser::DataType::NATIVE; case 1:
r_type.type.native_type = p_identifier; // ClassDB again for underscore-prefixed classes
if (Engine::get_singleton()->has_singleton(p_identifier)) { target_id = String("_") + p_identifier;
r_type.type.is_meta_type = false; break;
r_type.value = Engine::get_singleton()->get_singleton_object(p_identifier);
} else {
r_type.type.is_meta_type = true;
int idx = GDScriptLanguage::get_singleton()->get_global_map()[p_identifier];
r_type.value = GDScriptLanguage::get_singleton()->get_global_array()[idx];
}
return true;
} }
// ClassDB again for underscore-prefixed classes if (ClassDB::class_exists(target_id)) {
StringName under_id = String("_") + p_identifier;
if (ClassDB::class_exists(under_id)) {
r_type.type.has_type = true; r_type.type.has_type = true;
r_type.type.kind = GDScriptParser::DataType::NATIVE; r_type.type.kind = GDScriptParser::DataType::NATIVE;
r_type.type.native_type = p_identifier; r_type.type.native_type = target_id;
if (Engine::get_singleton()->has_singleton(p_identifier)) { if (Engine::get_singleton()->has_singleton(target_id)) {
r_type.type.is_meta_type = false; r_type.type.is_meta_type = false;
r_type.value = Engine::get_singleton()->get_singleton_object(p_identifier); r_type.value = Engine::get_singleton()->get_singleton_object(target_id);
} else { } else {
r_type.type.is_meta_type = true; r_type.type.is_meta_type = true;
int idx = GDScriptLanguage::get_singleton()->get_global_map()[p_identifier]; const Map<StringName, int>::Element *target_elem = GDScriptLanguage::get_singleton()->get_global_map().find(target_id);
// Check because classes like EditorNode are in ClassDB by now, but unknown to GDScript
if (!target_elem) {
return false;
}
int idx = target_elem->get();
r_type.value = GDScriptLanguage::get_singleton()->get_global_array()[idx]; r_type.value = GDScriptLanguage::get_singleton()->get_global_array()[idx];
} }
return true; return true;
} }
}
// Check autoload singletons // Check autoload singletons
if (GDScriptLanguage::get_singleton()->get_named_globals_map().has(p_identifier)) { if (GDScriptLanguage::get_singleton()->get_named_globals_map().has(p_identifier)) {