Skip to content

Commit 9a9045c

Browse files
committed
Merge pull request godotengine#89382 from dcaoc03/master
Fix enum autocompletion for core classes
2 parents c8fb248 + 935ea10 commit 9a9045c

File tree

5 files changed

+59
-7
lines changed

5 files changed

+59
-7
lines changed

modules/gdscript/gdscript_editor.cpp

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,21 @@ static int _get_enum_constant_location(const StringName &p_class, const StringNa
651651
return depth | ScriptLanguage::LOCATION_PARENT_MASK;
652652
}
653653

654+
static int _get_enum_location(const StringName &p_class, const StringName &p_enum) {
655+
if (!ClassDB::has_enum(p_class, p_enum)) {
656+
return ScriptLanguage::LOCATION_OTHER;
657+
}
658+
659+
int depth = 0;
660+
StringName class_test = p_class;
661+
while (class_test && !ClassDB::has_enum(class_test, p_enum, true)) {
662+
class_test = ClassDB::get_parent_class(class_test);
663+
depth++;
664+
}
665+
666+
return depth | ScriptLanguage::LOCATION_PARENT_MASK;
667+
}
668+
654669
// END LOCATION METHODS
655670

656671
static String _trim_parent_class(const String &p_class, const String &p_base_class) {
@@ -1202,13 +1217,15 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
12021217
return;
12031218
}
12041219

1220+
List<StringName> enums;
1221+
ClassDB::get_enum_list(type, &enums);
1222+
for (const StringName &E : enums) {
1223+
int location = p_recursion_depth + _get_enum_location(type, E);
1224+
ScriptLanguage::CodeCompletionOption option(E, ScriptLanguage::CODE_COMPLETION_KIND_ENUM, location);
1225+
r_result.insert(option.display, option);
1226+
}
1227+
12051228
if (p_types_only) {
1206-
List<StringName> enums;
1207-
ClassDB::get_enum_list(type, &enums);
1208-
for (const StringName &E : enums) {
1209-
ScriptLanguage::CodeCompletionOption option(E, ScriptLanguage::CODE_COMPLETION_KIND_ENUM);
1210-
r_result.insert(option.display, option);
1211-
}
12121229
return;
12131230
}
12141231

@@ -1268,7 +1285,20 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
12681285
}
12691286
return;
12701287
} break;
1271-
case GDScriptParser::DataType::ENUM:
1288+
case GDScriptParser::DataType::ENUM: {
1289+
String type_str = base_type.native_type;
1290+
StringName type = type_str.get_slicec('.', 0);
1291+
StringName type_enum = base_type.enum_type;
1292+
1293+
List<StringName> enum_values;
1294+
ClassDB::get_enum_constants(type, type_enum, &enum_values);
1295+
for (const StringName &E : enum_values) {
1296+
int location = p_recursion_depth + _get_enum_constant_location(type, E);
1297+
ScriptLanguage::CodeCompletionOption option(E, ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT, location);
1298+
r_result.insert(option.display, option);
1299+
}
1300+
}
1301+
[[fallthrough]];
12721302
case GDScriptParser::DataType::BUILTIN: {
12731303
if (p_types_only) {
12741304
return;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[output]
2+
include=[
3+
{"display": "DrawMode",
4+
"location": 256},
5+
{"display": "Anchor",
6+
"location": 257},
7+
{"display": "TextureRepeat",
8+
"location": 258},
9+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extends Control
2+
3+
func _ready():
4+
var t = BaseButton.➡
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[output]
2+
include=[
3+
{"display": "HEURISTIC_MAX"},
4+
{"display": "HEURISTIC_OCTILE"},
5+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extends Control
2+
3+
func _ready():
4+
AStarGrid2D.Heuristic.➡

0 commit comments

Comments
 (0)