mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Autocompletion: Add support for global enums
This commit is contained in:
parent
019ab8745f
commit
af54b13603
13 changed files with 106 additions and 9 deletions
|
@ -1032,6 +1032,15 @@ static void _find_built_in_variants(HashMap<String, ScriptLanguage::CodeCompleti
|
|||
}
|
||||
}
|
||||
|
||||
static void _find_global_enums(HashMap<String, ScriptLanguage::CodeCompletionOption> &r_result) {
|
||||
List<StringName> global_enums;
|
||||
CoreConstants::get_global_enums(&global_enums);
|
||||
for (const StringName &enum_name : global_enums) {
|
||||
ScriptLanguage::CodeCompletionOption option(enum_name, ScriptLanguage::CODE_COMPLETION_KIND_ENUM, ScriptLanguage::LOCATION_OTHER);
|
||||
r_result.insert(option.display, option);
|
||||
}
|
||||
}
|
||||
|
||||
static void _list_available_types(bool p_inherit_only, GDScriptParser::CompletionContext &p_context, HashMap<String, ScriptLanguage::CodeCompletionOption> &r_result) {
|
||||
// Built-in Variant Types
|
||||
_find_built_in_variants(r_result, true);
|
||||
|
@ -1093,6 +1102,11 @@ static void _list_available_types(bool p_inherit_only, GDScriptParser::Completio
|
|||
r_result.insert(option.display, option);
|
||||
}
|
||||
|
||||
// Global enums
|
||||
if (!p_inherit_only) {
|
||||
_find_global_enums(r_result);
|
||||
}
|
||||
|
||||
// Autoload singletons
|
||||
HashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
||||
|
||||
|
@ -1393,15 +1407,29 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
|
|||
} break;
|
||||
case GDScriptParser::DataType::ENUM: {
|
||||
String type_str = base_type.native_type;
|
||||
StringName type = type_str.get_slicec('.', 0);
|
||||
StringName type_enum = base_type.enum_type;
|
||||
|
||||
List<StringName> enum_values;
|
||||
ClassDB::get_enum_constants(type, type_enum, &enum_values);
|
||||
for (const StringName &E : enum_values) {
|
||||
int location = p_recursion_depth + _get_enum_constant_location(type, E);
|
||||
ScriptLanguage::CodeCompletionOption option(E, ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT, location);
|
||||
r_result.insert(option.display, option);
|
||||
if (type_str.contains_char('.')) {
|
||||
StringName type = type_str.get_slicec('.', 0);
|
||||
StringName type_enum = base_type.enum_type;
|
||||
|
||||
List<StringName> enum_values;
|
||||
|
||||
ClassDB::get_enum_constants(type, type_enum, &enum_values);
|
||||
|
||||
for (const StringName &E : enum_values) {
|
||||
int location = p_recursion_depth + _get_enum_constant_location(type, E);
|
||||
ScriptLanguage::CodeCompletionOption option(E, ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT, location);
|
||||
r_result.insert(option.display, option);
|
||||
}
|
||||
} else if (CoreConstants::is_global_enum(base_type.enum_type)) {
|
||||
HashMap<StringName, int64_t> enum_values;
|
||||
CoreConstants::get_enum_values(base_type.enum_type, &enum_values);
|
||||
|
||||
for (const KeyValue<StringName, int64_t> &enum_value : enum_values) {
|
||||
int location = p_recursion_depth + ScriptLanguage::LOCATION_OTHER;
|
||||
ScriptLanguage::CodeCompletionOption option(enum_value.key, ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT, location);
|
||||
r_result.insert(option.display, option);
|
||||
}
|
||||
}
|
||||
}
|
||||
[[fallthrough]];
|
||||
|
@ -1582,6 +1610,9 @@ static void _find_identifiers(const GDScriptParser::CompletionContext &p_context
|
|||
r_result.insert(option.display, option);
|
||||
}
|
||||
|
||||
// Global enums
|
||||
_find_global_enums(r_result);
|
||||
|
||||
// Global classes
|
||||
List<StringName> global_classes;
|
||||
ScriptServer::get_global_class_list(&global_classes);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue