From 3e0c867980cdaf47c96319444b9404a24481876c Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Wed, 11 Dec 2024 10:25:03 +0300 Subject: [PATCH] Code Editor: Add documentation tooltips --- core/doc_data.cpp | 33 - core/doc_data.h | 20 +- core/input/input.cpp | 20 + core/input/input.h | 1 + core/object/script_language.h | 36 +- core/object/script_language_extension.cpp | 5 +- core/object/script_language_extension.h | 40 +- doc/classes/CodeEdit.xml | 13 + doc/classes/ScriptExtension.xml | 5 + doc/classes/ScriptLanguageExtension.xml | 8 +- editor/create_dialog.cpp | 2 +- editor/doc_tools.cpp | 7 +- editor/editor_help.cpp | 770 ++++++++++++------ editor/editor_help.h | 43 +- editor/editor_inspector.cpp | 16 +- editor/plugins/script_text_editor.cpp | 256 ++++-- editor/plugins/script_text_editor.h | 2 + modules/gdscript/editor/gdscript_docgen.cpp | 20 +- modules/gdscript/editor/gdscript_docgen.h | 3 +- modules/gdscript/gdscript.cpp | 16 +- modules/gdscript/gdscript.h | 8 +- modules/gdscript/gdscript_analyzer.h | 3 +- modules/gdscript/gdscript_editor.cpp | 491 +++++++---- modules/gdscript/gdscript_parser.cpp | 63 +- modules/gdscript/gdscript_parser.h | 1 + .../language_server/gdscript_workspace.cpp | 9 +- modules/mono/csharp_script.h | 1 + scene/gui/code_edit.cpp | 43 + scene/gui/code_edit.h | 16 +- scene/gui/rich_text_label.cpp | 5 + scene/gui/rich_text_label.h | 5 + 31 files changed, 1359 insertions(+), 602 deletions(-) diff --git a/core/doc_data.cpp b/core/doc_data.cpp index f40e878d52b9..2881443545f6 100644 --- a/core/doc_data.cpp +++ b/core/doc_data.cpp @@ -105,28 +105,6 @@ void DocData::argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const } } -void DocData::property_doc_from_scriptmemberinfo(DocData::PropertyDoc &p_property, const ScriptMemberInfo &p_memberinfo) { - p_property.name = p_memberinfo.propinfo.name; - p_property.description = p_memberinfo.doc_string; - - if (p_memberinfo.propinfo.type == Variant::OBJECT) { - p_property.type = p_memberinfo.propinfo.class_name; - } else if (p_memberinfo.propinfo.type == Variant::NIL && p_memberinfo.propinfo.usage & PROPERTY_USAGE_NIL_IS_VARIANT) { - p_property.type = "Variant"; - } else { - p_property.type = Variant::get_type_name(p_memberinfo.propinfo.type); - } - - p_property.setter = p_memberinfo.setter; - p_property.getter = p_memberinfo.getter; - - if (p_memberinfo.has_default_value && p_memberinfo.default_value.get_type() != Variant::OBJECT) { - p_property.default_value = get_default_value_string(p_memberinfo.default_value); - } - - p_property.overridden = false; -} - void DocData::method_doc_from_methodinfo(DocData::MethodDoc &p_method, const MethodInfo &p_methodinfo, const String &p_desc) { p_method.name = p_methodinfo.name; p_method.description = p_desc; @@ -170,14 +148,3 @@ void DocData::method_doc_from_methodinfo(DocData::MethodDoc &p_method, const Met p_method.arguments.push_back(argument); } } - -void DocData::constant_doc_from_variant(DocData::ConstantDoc &p_const, const StringName &p_name, const Variant &p_value, const String &p_desc) { - p_const.name = p_name; - p_const.value = p_value; - p_const.is_value_valid = (p_value.get_type() != Variant::OBJECT); - p_const.description = p_desc; -} - -void DocData::signal_doc_from_methodinfo(DocData::MethodDoc &p_signal, const MethodInfo &p_methodinfo, const String &p_desc) { - return method_doc_from_methodinfo(p_signal, p_methodinfo, p_desc); -} diff --git a/core/doc_data.h b/core/doc_data.h index 6a7f4355db54..49f9c3aa1496 100644 --- a/core/doc_data.h +++ b/core/doc_data.h @@ -34,16 +34,6 @@ #include "core/io/xml_parser.h" #include "core/variant/variant.h" -struct ScriptMemberInfo { - PropertyInfo propinfo; - String doc_string; - StringName setter; - StringName getter; - - bool has_default_value = false; - Variant default_value; -}; - class DocData { public: struct ArgumentDoc { @@ -276,6 +266,7 @@ class DocData { String name; String value; bool is_value_valid = false; + String type; String enumeration; bool is_bitfield = false; String description; @@ -302,6 +293,10 @@ class DocData { doc.is_value_valid = p_dict["is_value_valid"]; } + if (p_dict.has("type")) { + doc.type = p_dict["type"]; + } + if (p_dict.has("enumeration")) { doc.enumeration = p_dict["enumeration"]; if (p_dict.has("is_bitfield")) { @@ -352,6 +347,8 @@ class DocData { dict["is_value_valid"] = p_doc.is_value_valid; + dict["type"] = p_doc.type; + if (!p_doc.enumeration.is_empty()) { dict["enumeration"] = p_doc.enumeration; dict["is_bitfield"] = p_doc.is_bitfield; @@ -981,10 +978,7 @@ class DocData { static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo); static void argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const PropertyInfo &p_arginfo); - static void property_doc_from_scriptmemberinfo(DocData::PropertyDoc &p_property, const ScriptMemberInfo &p_memberinfo); static void method_doc_from_methodinfo(DocData::MethodDoc &p_method, const MethodInfo &p_methodinfo, const String &p_desc); - static void constant_doc_from_variant(DocData::ConstantDoc &p_const, const StringName &p_name, const Variant &p_value, const String &p_desc); - static void signal_doc_from_methodinfo(DocData::MethodDoc &p_signal, const MethodInfo &p_methodinfo, const String &p_desc); }; #endif // DOC_DATA_H diff --git a/core/input/input.cpp b/core/input/input.cpp index a0c00d7716dc..5314e9f02d1c 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -308,6 +308,26 @@ bool Input::is_anything_pressed() const { return false; } +bool Input::is_anything_pressed_except_mouse() const { + _THREAD_SAFE_METHOD_ + + if (disable_input) { + return false; + } + + if (!keys_pressed.is_empty() || !joy_buttons_pressed.is_empty()) { + return true; + } + + for (const KeyValue &E : action_states) { + if (E.value.cache.pressed) { + return true; + } + } + + return false; +} + bool Input::is_key_pressed(Key p_keycode) const { _THREAD_SAFE_METHOD_ diff --git a/core/input/input.h b/core/input/input.h index a189ae7d9ada..005ddcca4fdb 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -294,6 +294,7 @@ class Input : public Object { static Input *get_singleton(); bool is_anything_pressed() const; + bool is_anything_pressed_except_mouse() const; bool is_key_pressed(Key p_keycode) const; bool is_physical_key_pressed(Key p_keycode) const; bool is_key_label_pressed(Key p_keycode) const; diff --git a/core/object/script_language.h b/core/object/script_language.h index 31d6638e58e8..9c0632ed5321 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -150,6 +150,7 @@ class Script : public Resource { virtual Error reload(bool p_keep_state = false) = 0; #ifdef TOOLS_ENABLED + virtual StringName get_doc_class_name() const = 0; virtual Vector get_documentation() const = 0; virtual String get_class_icon_path() const = 0; virtual PropertyInfo get_class_category() const; @@ -181,7 +182,7 @@ class Script : public Resource { virtual int get_member_line(const StringName &p_member) const { return -1; } virtual void get_constants(HashMap *p_constants) {} - virtual void get_members(HashSet *p_constants) {} + virtual void get_members(HashSet *p_members) {} virtual bool is_placeholder_fallback_enabled() const { return false; } @@ -340,25 +341,46 @@ class ScriptLanguage : public Object { virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List *r_options, bool &r_force, String &r_call_hint) { return ERR_UNAVAILABLE; } enum LookupResultType { - LOOKUP_RESULT_SCRIPT_LOCATION, + LOOKUP_RESULT_SCRIPT_LOCATION, // Use if none of the options below apply. LOOKUP_RESULT_CLASS, LOOKUP_RESULT_CLASS_CONSTANT, LOOKUP_RESULT_CLASS_PROPERTY, LOOKUP_RESULT_CLASS_METHOD, LOOKUP_RESULT_CLASS_SIGNAL, LOOKUP_RESULT_CLASS_ENUM, - LOOKUP_RESULT_CLASS_TBD_GLOBALSCOPE, + LOOKUP_RESULT_CLASS_TBD_GLOBALSCOPE, // Deprecated. LOOKUP_RESULT_CLASS_ANNOTATION, - LOOKUP_RESULT_MAX + LOOKUP_RESULT_LOCAL_CONSTANT, + LOOKUP_RESULT_LOCAL_VARIABLE, + LOOKUP_RESULT_MAX, }; struct LookupResult { LookupResultType type; - Ref