You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Autocompletion: Add support for global enums
This commit is contained in:
@@ -863,3 +863,13 @@ void CoreConstants::get_enum_values(const StringName &p_enum, HashMap<StringName
|
|||||||
(*p_values)[constant.name] = constant.value;
|
(*p_values)[constant.name] = constant.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
|
|
||||||
|
void CoreConstants::get_global_enums(List<StringName> *r_values) {
|
||||||
|
for (const KeyValue<StringName, Vector<_CoreConstant>> &global_enum : _global_enums) {
|
||||||
|
r_values->push_back(global_enum.key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "core/string/string_name.h"
|
#include "core/string/string_name.h"
|
||||||
#include "core/templates/hash_map.h"
|
#include "core/templates/hash_map.h"
|
||||||
|
#include "core/templates/list.h"
|
||||||
|
|
||||||
class CoreConstants {
|
class CoreConstants {
|
||||||
public:
|
public:
|
||||||
@@ -44,5 +45,8 @@ public:
|
|||||||
static bool is_global_constant(const StringName &p_name);
|
static bool is_global_constant(const StringName &p_name);
|
||||||
static int get_global_constant_index(const StringName &p_name);
|
static int get_global_constant_index(const StringName &p_name);
|
||||||
static bool is_global_enum(const StringName &p_enum);
|
static bool is_global_enum(const StringName &p_enum);
|
||||||
static void get_enum_values(const StringName &p_enum, HashMap<StringName, int64_t> *p_values);
|
static void get_enum_values(const StringName &p_enum, HashMap<StringName, int64_t> *r_values);
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
|
static void get_global_enums(List<StringName> *r_values);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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) {
|
static void _list_available_types(bool p_inherit_only, GDScriptParser::CompletionContext &p_context, HashMap<String, ScriptLanguage::CodeCompletionOption> &r_result) {
|
||||||
// Built-in Variant Types
|
// Built-in Variant Types
|
||||||
_find_built_in_variants(r_result, true);
|
_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);
|
r_result.insert(option.display, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Global enums
|
||||||
|
if (!p_inherit_only) {
|
||||||
|
_find_global_enums(r_result);
|
||||||
|
}
|
||||||
|
|
||||||
// Autoload singletons
|
// Autoload singletons
|
||||||
HashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
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;
|
} break;
|
||||||
case GDScriptParser::DataType::ENUM: {
|
case GDScriptParser::DataType::ENUM: {
|
||||||
String type_str = base_type.native_type;
|
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;
|
if (type_str.contains_char('.')) {
|
||||||
ClassDB::get_enum_constants(type, type_enum, &enum_values);
|
StringName type = type_str.get_slicec('.', 0);
|
||||||
for (const StringName &E : enum_values) {
|
StringName type_enum = base_type.enum_type;
|
||||||
int location = p_recursion_depth + _get_enum_constant_location(type, E);
|
|
||||||
ScriptLanguage::CodeCompletionOption option(E, ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT, location);
|
List<StringName> enum_values;
|
||||||
r_result.insert(option.display, option);
|
|
||||||
|
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]];
|
[[fallthrough]];
|
||||||
@@ -1582,6 +1610,9 @@ static void _find_identifiers(const GDScriptParser::CompletionContext &p_context
|
|||||||
r_result.insert(option.display, option);
|
r_result.insert(option.display, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Global enums
|
||||||
|
_find_global_enums(r_result);
|
||||||
|
|
||||||
// Global classes
|
// Global classes
|
||||||
List<StringName> global_classes;
|
List<StringName> global_classes;
|
||||||
ScriptServer::get_global_class_list(&global_classes);
|
ScriptServer::get_global_class_list(&global_classes);
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
[output]
|
||||||
|
include=[
|
||||||
|
{"display": "DrawMode",
|
||||||
|
"location": 256},
|
||||||
|
{"display": "Anchor",
|
||||||
|
"location": 257},
|
||||||
|
{"display": "TextureRepeat",
|
||||||
|
"location": 258},
|
||||||
|
]
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
extends Control
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
var t: BaseButton.➡
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[output]
|
||||||
|
include=[
|
||||||
|
{"display": "Key"},
|
||||||
|
{"display": "KeyLocation"},
|
||||||
|
{"display": "Error"},
|
||||||
|
]
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
extends Object
|
||||||
|
|
||||||
|
func test():
|
||||||
|
var t = Ke➡
|
||||||
|
pass
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[output]
|
||||||
|
exclude=[
|
||||||
|
{"display": "Key"},
|
||||||
|
{"display": "KeyLocation"},
|
||||||
|
{"display": "Error"},
|
||||||
|
]
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
extends Ke➡
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[output]
|
||||||
|
include=[
|
||||||
|
{"display": "Key"},
|
||||||
|
{"display": "KeyLocation"},
|
||||||
|
{"display": "Error"},
|
||||||
|
]
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
extends Control
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
var t: Ke➡
|
||||||
|
pass
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
[output]
|
||||||
|
include=[
|
||||||
|
{"display": "KEY_A"},
|
||||||
|
{"display": "KEY_B"},
|
||||||
|
]
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
extends Control
|
||||||
|
|
||||||
|
func test():
|
||||||
|
Key.➡
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user