Browse Source

GDScript: Fix double spaces for type hints when connecting signal

Danil Alexeev 2 months ago
parent
commit
a59587c308
1 changed files with 26 additions and 17 deletions
  1. 26 17
      modules/gdscript/gdscript_editor.cpp

+ 26 - 17
modules/gdscript/gdscript_editor.cpp

@@ -81,11 +81,15 @@ bool GDScriptLanguage::is_using_templates() {
 Ref<Script> GDScriptLanguage::make_template(const String &p_template, const String &p_class_name, const String &p_base_class_name) const {
 Ref<Script> GDScriptLanguage::make_template(const String &p_template, const String &p_class_name, const String &p_base_class_name) const {
 	Ref<GDScript> scr;
 	Ref<GDScript> scr;
 	scr.instantiate();
 	scr.instantiate();
+
 	String processed_template = p_template;
 	String processed_template = p_template;
-	bool type_hints = false;
+
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
-	type_hints = EDITOR_GET("text_editor/completion/add_type_hints");
+	const bool type_hints = EditorSettings::get_singleton()->get_setting("text_editor/completion/add_type_hints");
+#else
+	const bool type_hints = true;
 #endif
 #endif
+
 	if (!type_hints) {
 	if (!type_hints) {
 		processed_template = processed_template.replace(": int", "")
 		processed_template = processed_template.replace(": int", "")
 									 .replace(": Shader.Mode", "")
 									 .replace(": Shader.Mode", "")
@@ -109,6 +113,7 @@ Ref<Script> GDScriptLanguage::make_template(const String &p_template, const Stri
 								 .replace("_CLASS_", p_class_name.to_pascal_case().validate_unicode_identifier())
 								 .replace("_CLASS_", p_class_name.to_pascal_case().validate_unicode_identifier())
 								 .replace("_TS_", _get_indentation());
 								 .replace("_TS_", _get_indentation());
 	scr->set_source_code(processed_template);
 	scr->set_source_code(processed_template);
+
 	return scr;
 	return scr;
 }
 }
 
 
@@ -524,29 +529,33 @@ void GDScriptLanguage::get_public_annotations(List<MethodInfo> *p_annotations) c
 
 
 String GDScriptLanguage::make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const {
 String GDScriptLanguage::make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const {
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
-	bool th = EditorSettings::get_singleton()->get_setting("text_editor/completion/add_type_hints");
+	const bool type_hints = EditorSettings::get_singleton()->get_setting("text_editor/completion/add_type_hints");
 #else
 #else
-	bool th = false;
+	const bool type_hints = true;
 #endif
 #endif
 
 
-	String s = "func " + p_name + "(";
+	String result = "func " + p_name + "(";
 	if (p_args.size()) {
 	if (p_args.size()) {
 		for (int i = 0; i < p_args.size(); i++) {
 		for (int i = 0; i < p_args.size(); i++) {
 			if (i > 0) {
 			if (i > 0) {
-				s += ", ";
+				result += ", ";
 			}
 			}
-			s += p_args[i].get_slicec(':', 0);
-			if (th) {
-				String type = p_args[i].get_slicec(':', 1);
-				if (!type.is_empty()) {
-					s += ": " + type;
+
+			const String name_unstripped = p_args[i].get_slicec(':', 0);
+			result += name_unstripped.strip_edges();
+
+			if (type_hints) {
+				const String type_stripped = p_args[i].right(name_unstripped.length() + 1).strip_edges();
+				if (!type_stripped.is_empty()) {
+					result += ": " + type_stripped;
 				}
 				}
 			}
 			}
 		}
 		}
 	}
 	}
-	s += String(")") + (th ? " -> void" : "") + ":\n" + _get_indentation() + "pass # Replace with function body.\n";
+	result += String(")") + (type_hints ? " -> void" : "") + ":\n" +
+			_get_indentation() + "pass # Replace with function body.\n";
 
 
-	return s;
+	return result;
 }
 }
 
 
 //////// COMPLETION //////////
 //////// COMPLETION //////////
@@ -3588,7 +3597,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
 				break;
 				break;
 			}
 			}
 
 
-			bool use_type_hint = EditorSettings::get_singleton()->get_setting("text_editor/completion/add_type_hints").operator bool();
+			const bool type_hints = EditorSettings::get_singleton()->get_setting("text_editor/completion/add_type_hints");
 
 
 			List<MethodInfo> virtual_methods;
 			List<MethodInfo> virtual_methods;
 			if (is_static) {
 			if (is_static) {
@@ -3620,7 +3629,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
 						arg = arg.substr(0, arg.find_char(':'));
 						arg = arg.substr(0, arg.find_char(':'));
 					}
 					}
 					method_hint += arg;
 					method_hint += arg;
-					if (use_type_hint) {
+					if (type_hints) {
 						method_hint += ": " + _get_visual_datatype(mi.arguments[i], true, class_name);
 						method_hint += ": " + _get_visual_datatype(mi.arguments[i], true, class_name);
 					}
 					}
 				}
 				}
@@ -3629,12 +3638,12 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
 						method_hint += ", ";
 						method_hint += ", ";
 					}
 					}
 					method_hint += "...args"; // `MethodInfo` does not support the rest parameter name.
 					method_hint += "...args"; // `MethodInfo` does not support the rest parameter name.
-					if (use_type_hint) {
+					if (type_hints) {
 						method_hint += ": Array";
 						method_hint += ": Array";
 					}
 					}
 				}
 				}
 				method_hint += ")";
 				method_hint += ")";
-				if (use_type_hint) {
+				if (type_hints) {
 					method_hint += " -> " + _get_visual_datatype(mi.return_val, false, class_name);
 					method_hint += " -> " + _get_visual_datatype(mi.return_val, false, class_name);
 				}
 				}
 				method_hint += ":";
 				method_hint += ":";