Skip to content

Commit 935ea10

Browse files
committed
Fixed enum autocompletion for core classes (Issue godotengine#88858)
Minor fix consisted in the use of [[fallthrough]] macro
1 parent ec901ae commit 935ea10

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) {
@@ -1198,13 +1213,15 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
11981213
return;
11991214
}
12001215

1216+
List<StringName> enums;
1217+
ClassDB::get_enum_list(type, &enums);
1218+
for (const StringName &E : enums) {
1219+
int location = p_recursion_depth + _get_enum_location(type, E);
1220+
ScriptLanguage::CodeCompletionOption option(E, ScriptLanguage::CODE_COMPLETION_KIND_ENUM, location);
1221+
r_result.insert(option.display, option);
1222+
}
1223+
12011224
if (p_types_only) {
1202-
List<StringName> enums;
1203-
ClassDB::get_enum_list(type, &enums);
1204-
for (const StringName &E : enums) {
1205-
ScriptLanguage::CodeCompletionOption option(E, ScriptLanguage::CODE_COMPLETION_KIND_ENUM);
1206-
r_result.insert(option.display, option);
1207-
}
12081225
return;
12091226
}
12101227

@@ -1264,7 +1281,20 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
12641281
}
12651282
return;
12661283
} break;
1267-
case GDScriptParser::DataType::ENUM:
1284+
case GDScriptParser::DataType::ENUM: {
1285+
String type_str = base_type.native_type;
1286+
StringName type = type_str.get_slicec('.', 0);
1287+
StringName type_enum = base_type.enum_type;
1288+
1289+
List<StringName> enum_values;
1290+
ClassDB::get_enum_constants(type, type_enum, &enum_values);
1291+
for (const StringName &E : enum_values) {
1292+
int location = p_recursion_depth + _get_enum_constant_location(type, E);
1293+
ScriptLanguage::CodeCompletionOption option(E, ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT, location);
1294+
r_result.insert(option.display, option);
1295+
}
1296+
}
1297+
[[fallthrough]];
12681298
case GDScriptParser::DataType::BUILTIN: {
12691299
if (p_types_only) {
12701300
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)