@@ -578,29 +578,34 @@ static int _get_enum_constant_location(StringName p_class, StringName p_enum_con
578578
579579// END LOCATION METHODS
580580
581- static String _get_visual_datatype (const PropertyInfo &p_info, bool p_is_arg = true ) {
582- if (p_info.usage & (PROPERTY_USAGE_CLASS_IS_ENUM | PROPERTY_USAGE_CLASS_IS_BITFIELD )) {
583- String enum_name = p_info.class_name ;
584- if (!enum_name.contains (" ." )) {
585- return enum_name;
581+ static String _trim_parent_class (const String &p_class, const String &p_base_class) {
582+ if (p_base_class.is_empty ()) {
583+ return p_class;
584+ }
585+ Vector<String> names = p_class.split (" ." , false , 1 );
586+ if (names.size () == 2 ) {
587+ String first = names[0 ];
588+ String rest = names[1 ];
589+ if (ClassDB::class_exists (p_base_class) && ClassDB::class_exists (first) && ClassDB::is_parent_class (p_base_class, first)) {
590+ return rest;
586591 }
587- return enum_name.get_slice (" ." , 1 );
588592 }
593+ return p_class;
594+ }
589595
590- String n = p_info.name ;
591- int idx = n.find (" :" );
592- if (idx != -1 ) {
593- return n.substr (idx + 1 , n.length ());
594- }
596+ static String _get_visual_datatype (const PropertyInfo &p_info, bool p_is_arg, const String &p_base_class = " " ) {
597+ String class_name = p_info.class_name ;
598+ bool is_enum = p_info.type == Variant::INT && p_info.usage & PROPERTY_USAGE_CLASS_IS_ENUM ;
599+ // PROPERTY_USAGE_CLASS_IS_BITFIELD: BitField[T] isn't supported (yet?), use plain int.
595600
596- if (p_info.type == Variant::OBJECT ) {
597- if (p_info.hint == PROPERTY_HINT_RESOURCE_TYPE ) {
598- return p_info.hint_string ;
599- } else {
600- return p_info.class_name .operator String ();
601+ if ((p_info.type == Variant::OBJECT || is_enum) && !class_name.is_empty ()) {
602+ if (is_enum && CoreConstants::is_global_enum (p_info.class_name )) {
603+ return class_name;
601604 }
602- }
603- if (p_info.type == Variant::NIL ) {
605+ return _trim_parent_class (class_name, p_base_class);
606+ } else if (p_info.type == Variant::ARRAY && p_info.hint == PROPERTY_HINT_ARRAY_TYPE && !p_info.hint_string .is_empty ()) {
607+ return " Array[" + _trim_parent_class (p_info.hint_string , p_base_class) + " ]" ;
608+ } else if (p_info.type == Variant::NIL ) {
604609 if (p_is_arg || (p_info.usage & PROPERTY_USAGE_NIL_IS_VARIANT )) {
605610 return " Variant" ;
606611 } else {
@@ -3001,26 +3006,14 @@ ::Error GDScriptLanguage::complete_code(const String &p_code, const String &p_pa
30013006 arg = arg.substr (0 , arg.find (" :" ));
30023007 }
30033008 method_hint += arg;
3004- if (use_type_hint && mi.arguments [i].type != Variant::NIL ) {
3005- method_hint += " : " ;
3006- if (mi.arguments [i].type == Variant::OBJECT && mi.arguments [i].class_name != StringName ()) {
3007- method_hint += mi.arguments [i].class_name .operator String ();
3008- } else {
3009- method_hint += Variant::get_type_name (mi.arguments [i].type );
3010- }
3009+ if (use_type_hint) {
3010+ method_hint += " : " + _get_visual_datatype (mi.arguments [i], true , class_name);
30113011 }
30123012 }
30133013 }
30143014 method_hint += " )" ;
3015- if (use_type_hint && (mi.return_val .type != Variant::NIL || !(mi.return_val .usage & PROPERTY_USAGE_NIL_IS_VARIANT ))) {
3016- method_hint += " -> " ;
3017- if (mi.return_val .type == Variant::NIL ) {
3018- method_hint += " void" ;
3019- } else if (mi.return_val .type == Variant::OBJECT && mi.return_val .class_name != StringName ()) {
3020- method_hint += mi.return_val .class_name .operator String ();
3021- } else {
3022- method_hint += Variant::get_type_name (mi.return_val .type );
3023- }
3015+ if (use_type_hint) {
3016+ method_hint += " -> " + _get_visual_datatype (mi.return_val , false , class_name);
30243017 }
30253018 method_hint += " :" ;
30263019
0 commit comments