Skip to content

Commit 9c9af03

Browse files
committed
Merge pull request #91060 from dalexeev/code-edit-add-doc-tooltips
Code Editor: Add documentation tooltips
2 parents 7254761 + 80d1150 commit 9c9af03

30 files changed

+1381
-569
lines changed

core/doc_data.cpp

-33
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,6 @@ void DocData::argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const
105105
}
106106
}
107107

108-
void DocData::property_doc_from_scriptmemberinfo(DocData::PropertyDoc &p_property, const ScriptMemberInfo &p_memberinfo) {
109-
p_property.name = p_memberinfo.propinfo.name;
110-
p_property.description = p_memberinfo.doc_string;
111-
112-
if (p_memberinfo.propinfo.type == Variant::OBJECT) {
113-
p_property.type = p_memberinfo.propinfo.class_name;
114-
} else if (p_memberinfo.propinfo.type == Variant::NIL && p_memberinfo.propinfo.usage & PROPERTY_USAGE_NIL_IS_VARIANT) {
115-
p_property.type = "Variant";
116-
} else {
117-
p_property.type = Variant::get_type_name(p_memberinfo.propinfo.type);
118-
}
119-
120-
p_property.setter = p_memberinfo.setter;
121-
p_property.getter = p_memberinfo.getter;
122-
123-
if (p_memberinfo.has_default_value && p_memberinfo.default_value.get_type() != Variant::OBJECT) {
124-
p_property.default_value = get_default_value_string(p_memberinfo.default_value);
125-
}
126-
127-
p_property.overridden = false;
128-
}
129-
130108
void DocData::method_doc_from_methodinfo(DocData::MethodDoc &p_method, const MethodInfo &p_methodinfo, const String &p_desc) {
131109
p_method.name = p_methodinfo.name;
132110
p_method.description = p_desc;
@@ -170,14 +148,3 @@ void DocData::method_doc_from_methodinfo(DocData::MethodDoc &p_method, const Met
170148
p_method.arguments.push_back(argument);
171149
}
172150
}
173-
174-
void DocData::constant_doc_from_variant(DocData::ConstantDoc &p_const, const StringName &p_name, const Variant &p_value, const String &p_desc) {
175-
p_const.name = p_name;
176-
p_const.value = p_value;
177-
p_const.is_value_valid = (p_value.get_type() != Variant::OBJECT);
178-
p_const.description = p_desc;
179-
}
180-
181-
void DocData::signal_doc_from_methodinfo(DocData::MethodDoc &p_signal, const MethodInfo &p_methodinfo, const String &p_desc) {
182-
return method_doc_from_methodinfo(p_signal, p_methodinfo, p_desc);
183-
}

core/doc_data.h

+7-13
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@
3434
#include "core/io/xml_parser.h"
3535
#include "core/variant/variant.h"
3636

37-
struct ScriptMemberInfo {
38-
PropertyInfo propinfo;
39-
String doc_string;
40-
StringName setter;
41-
StringName getter;
42-
43-
bool has_default_value = false;
44-
Variant default_value;
45-
};
46-
4737
class DocData {
4838
public:
4939
struct ArgumentDoc {
@@ -276,6 +266,7 @@ class DocData {
276266
String name;
277267
String value;
278268
bool is_value_valid = false;
269+
String type;
279270
String enumeration;
280271
bool is_bitfield = false;
281272
String description;
@@ -302,6 +293,10 @@ class DocData {
302293
doc.is_value_valid = p_dict["is_value_valid"];
303294
}
304295

296+
if (p_dict.has("type")) {
297+
doc.type = p_dict["type"];
298+
}
299+
305300
if (p_dict.has("enumeration")) {
306301
doc.enumeration = p_dict["enumeration"];
307302
if (p_dict.has("is_bitfield")) {
@@ -352,6 +347,8 @@ class DocData {
352347

353348
dict["is_value_valid"] = p_doc.is_value_valid;
354349

350+
dict["type"] = p_doc.type;
351+
355352
if (!p_doc.enumeration.is_empty()) {
356353
dict["enumeration"] = p_doc.enumeration;
357354
dict["is_bitfield"] = p_doc.is_bitfield;
@@ -981,10 +978,7 @@ class DocData {
981978

982979
static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo);
983980
static void argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const PropertyInfo &p_arginfo);
984-
static void property_doc_from_scriptmemberinfo(DocData::PropertyDoc &p_property, const ScriptMemberInfo &p_memberinfo);
985981
static void method_doc_from_methodinfo(DocData::MethodDoc &p_method, const MethodInfo &p_methodinfo, const String &p_desc);
986-
static void constant_doc_from_variant(DocData::ConstantDoc &p_const, const StringName &p_name, const Variant &p_value, const String &p_desc);
987-
static void signal_doc_from_methodinfo(DocData::MethodDoc &p_signal, const MethodInfo &p_methodinfo, const String &p_desc);
988982
};
989983

990984
#endif // DOC_DATA_H

core/object/script_language.h

+29-7
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class Script : public Resource {
150150
virtual Error reload(bool p_keep_state = false) = 0;
151151

152152
#ifdef TOOLS_ENABLED
153+
virtual StringName get_doc_class_name() const = 0;
153154
virtual Vector<DocData::ClassDoc> get_documentation() const = 0;
154155
virtual String get_class_icon_path() const = 0;
155156
virtual PropertyInfo get_class_category() const;
@@ -181,7 +182,7 @@ class Script : public Resource {
181182
virtual int get_member_line(const StringName &p_member) const { return -1; }
182183

183184
virtual void get_constants(HashMap<StringName, Variant> *p_constants) {}
184-
virtual void get_members(HashSet<StringName> *p_constants) {}
185+
virtual void get_members(HashSet<StringName> *p_members) {}
185186

186187
virtual bool is_placeholder_fallback_enabled() const { return false; }
187188

@@ -340,25 +341,46 @@ class ScriptLanguage : public Object {
340341
virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List<CodeCompletionOption> *r_options, bool &r_force, String &r_call_hint) { return ERR_UNAVAILABLE; }
341342

342343
enum LookupResultType {
343-
LOOKUP_RESULT_SCRIPT_LOCATION,
344+
LOOKUP_RESULT_SCRIPT_LOCATION, // Use if none of the options below apply.
344345
LOOKUP_RESULT_CLASS,
345346
LOOKUP_RESULT_CLASS_CONSTANT,
346347
LOOKUP_RESULT_CLASS_PROPERTY,
347348
LOOKUP_RESULT_CLASS_METHOD,
348349
LOOKUP_RESULT_CLASS_SIGNAL,
349350
LOOKUP_RESULT_CLASS_ENUM,
350-
LOOKUP_RESULT_CLASS_TBD_GLOBALSCOPE,
351+
LOOKUP_RESULT_CLASS_TBD_GLOBALSCOPE, // Deprecated.
351352
LOOKUP_RESULT_CLASS_ANNOTATION,
352-
LOOKUP_RESULT_MAX
353+
LOOKUP_RESULT_LOCAL_CONSTANT,
354+
LOOKUP_RESULT_LOCAL_VARIABLE,
355+
LOOKUP_RESULT_MAX,
353356
};
354357

355358
struct LookupResult {
356359
LookupResultType type;
357-
Ref<Script> script;
360+
361+
// For `CLASS_*`.
358362
String class_name;
359363
String class_member;
360-
String class_path;
361-
int location;
364+
365+
// For `LOCAL_*`.
366+
String description;
367+
bool is_deprecated = false;
368+
String deprecated_message;
369+
bool is_experimental = false;
370+
String experimental_message;
371+
372+
// For `LOCAL_*`.
373+
String doc_type;
374+
String enumeration;
375+
bool is_bitfield = false;
376+
377+
// For `LOCAL_*`.
378+
String value;
379+
380+
// `SCRIPT_LOCATION` and `LOCAL_*` must have, `CLASS_*` can have.
381+
Ref<Script> script;
382+
String script_path;
383+
int location = -1;
362384
};
363385

364386
virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) { return ERR_UNAVAILABLE; }

core/object/script_language_extension.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ void ScriptExtension::_bind_methods() {
5151
GDVIRTUAL_BIND(_set_source_code, "code");
5252
GDVIRTUAL_BIND(_reload, "keep_state");
5353

54+
GDVIRTUAL_BIND(_get_doc_class_name);
5455
GDVIRTUAL_BIND(_get_documentation);
5556
GDVIRTUAL_BIND(_get_class_icon_path);
5657

@@ -169,8 +170,10 @@ void ScriptLanguageExtension::_bind_methods() {
169170
BIND_ENUM_CONSTANT(LOOKUP_RESULT_CLASS_METHOD);
170171
BIND_ENUM_CONSTANT(LOOKUP_RESULT_CLASS_SIGNAL);
171172
BIND_ENUM_CONSTANT(LOOKUP_RESULT_CLASS_ENUM);
172-
BIND_ENUM_CONSTANT(LOOKUP_RESULT_CLASS_TBD_GLOBALSCOPE);
173+
BIND_ENUM_CONSTANT(LOOKUP_RESULT_CLASS_TBD_GLOBALSCOPE); // Deprecated.
173174
BIND_ENUM_CONSTANT(LOOKUP_RESULT_CLASS_ANNOTATION);
175+
BIND_ENUM_CONSTANT(LOOKUP_RESULT_LOCAL_CONSTANT);
176+
BIND_ENUM_CONSTANT(LOOKUP_RESULT_LOCAL_VARIABLE);
174177
BIND_ENUM_CONSTANT(LOOKUP_RESULT_MAX);
175178

176179
BIND_ENUM_CONSTANT(LOCATION_LOCAL);

core/object/script_language_extension.h

+28-12
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,16 @@ class ScriptExtension : public Script {
7676
EXBIND1(set_source_code, const String &)
7777
EXBIND1R(Error, reload, bool)
7878

79+
GDVIRTUAL0RC_REQUIRED(StringName, _get_doc_class_name)
7980
GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_documentation)
8081
GDVIRTUAL0RC(String, _get_class_icon_path)
8182
#ifdef TOOLS_ENABLED
83+
virtual StringName get_doc_class_name() const override {
84+
StringName ret;
85+
GDVIRTUAL_CALL(_get_doc_class_name, ret);
86+
return ret;
87+
}
88+
8289
virtual Vector<DocData::ClassDoc> get_documentation() const override {
8390
TypedArray<Dictionary> doc;
8491
GDVIRTUAL_CALL(_get_documentation, doc);
@@ -454,22 +461,31 @@ class ScriptLanguageExtension : public ScriptLanguage {
454461
virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) override {
455462
Dictionary ret;
456463
GDVIRTUAL_CALL(_lookup_code, p_code, p_symbol, p_path, p_owner, ret);
457-
if (!ret.has("result")) {
458-
return ERR_UNAVAILABLE;
459-
}
464+
465+
ERR_FAIL_COND_V(!ret.has("result"), ERR_UNAVAILABLE);
466+
const Error result = Error(int(ret["result"]));
460467

461468
ERR_FAIL_COND_V(!ret.has("type"), ERR_UNAVAILABLE);
462469
r_result.type = LookupResultType(int(ret["type"]));
463-
ERR_FAIL_COND_V(!ret.has("script"), ERR_UNAVAILABLE);
464-
r_result.script = ret["script"];
465-
ERR_FAIL_COND_V(!ret.has("class_name"), ERR_UNAVAILABLE);
466-
r_result.class_name = ret["class_name"];
467-
ERR_FAIL_COND_V(!ret.has("class_path"), ERR_UNAVAILABLE);
468-
r_result.class_path = ret["class_path"];
469-
ERR_FAIL_COND_V(!ret.has("location"), ERR_UNAVAILABLE);
470-
r_result.location = ret["location"];
471470

472-
Error result = Error(int(ret["result"]));
471+
r_result.class_name = ret.get("class_name", "");
472+
r_result.class_member = ret.get("class_member", "");
473+
474+
r_result.description = ret.get("description", "");
475+
r_result.is_deprecated = ret.get("is_deprecated", false);
476+
r_result.deprecated_message = ret.get("deprecated_message", "");
477+
r_result.is_deprecated = ret.get("is_deprecated", false);
478+
r_result.experimental_message = ret.get("experimental_message", "");
479+
480+
r_result.doc_type = ret.get("doc_type", "");
481+
r_result.enumeration = ret.get("enumeration", "");
482+
r_result.is_bitfield = ret.get("is_bitfield", false);
483+
484+
r_result.value = ret.get("value", "");
485+
486+
r_result.script = ret.get("script", Ref<Script>());
487+
r_result.script_path = ret.get("script_path", "");
488+
r_result.location = ret.get("location", -1);
473489

474490
return result;
475491
}

doc/classes/@GlobalScope.xml

+11
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@
844844
</description>
845845
</method>
846846
<method name="print" qualifiers="vararg">
847+
<return type="void" />
847848
<description>
848849
Converts one or more arguments of any type to string in the best way possible and prints them to the console.
849850
[codeblocks]
@@ -860,6 +861,7 @@
860861
</description>
861862
</method>
862863
<method name="print_rich" qualifiers="vararg">
864+
<return type="void" />
863865
<description>
864866
Converts one or more arguments of any type to string in the best way possible and prints them to the console.
865867
The following BBCode tags are supported: [code]b[/code], [code]i[/code], [code]u[/code], [code]s[/code], [code]indent[/code], [code]code[/code], [code]url[/code], [code]center[/code], [code]right[/code], [code]color[/code], [code]bgcolor[/code], [code]fgcolor[/code].
@@ -879,11 +881,13 @@
879881
</description>
880882
</method>
881883
<method name="print_verbose" qualifiers="vararg">
884+
<return type="void" />
882885
<description>
883886
If verbose mode is enabled ([method OS.is_stdout_verbose] returning [code]true[/code]), converts one or more arguments of any type to string in the best way possible and prints them to the console.
884887
</description>
885888
</method>
886889
<method name="printerr" qualifiers="vararg">
890+
<return type="void" />
887891
<description>
888892
Prints one or more arguments to strings in the best way possible to standard error line.
889893
[codeblocks]
@@ -897,6 +901,7 @@
897901
</description>
898902
</method>
899903
<method name="printraw" qualifiers="vararg">
904+
<return type="void" />
900905
<description>
901906
Prints one or more arguments to strings in the best way possible to the OS terminal. Unlike [method print], no newline is automatically added at the end.
902907
[b]Note:[/b] The OS terminal is [i]not[/i] the same as the editor's Output dock. The output sent to the OS terminal can be seen when running Godot from a terminal. On Windows, this requires using the [code]console.exe[/code] executable.
@@ -917,6 +922,7 @@
917922
</description>
918923
</method>
919924
<method name="prints" qualifiers="vararg">
925+
<return type="void" />
920926
<description>
921927
Prints one or more arguments to the console with a space between each argument.
922928
[codeblocks]
@@ -930,6 +936,7 @@
930936
</description>
931937
</method>
932938
<method name="printt" qualifiers="vararg">
939+
<return type="void" />
933940
<description>
934941
Prints one or more arguments to the console with a tab between each argument.
935942
[codeblocks]
@@ -943,6 +950,7 @@
943950
</description>
944951
</method>
945952
<method name="push_error" qualifiers="vararg">
953+
<return type="void" />
946954
<description>
947955
Pushes an error message to Godot's built-in debugger and to the OS terminal.
948956
[codeblocks]
@@ -957,6 +965,7 @@
957965
</description>
958966
</method>
959967
<method name="push_warning" qualifiers="vararg">
968+
<return type="void" />
960969
<description>
961970
Pushes a warning message to Godot's built-in debugger and to the OS terminal.
962971
[codeblocks]
@@ -1075,6 +1084,7 @@
10751084
</description>
10761085
</method>
10771086
<method name="randomize">
1087+
<return type="void" />
10781088
<description>
10791089
Randomizes the seed (or the internal state) of the random number generator. The current implementation uses a number based on the device's time.
10801090
[b]Note:[/b] This function is called automatically when the project is run. If you need to fix the seed to have consistent, reproducible results, use [method seed] to initialize the random number generator.
@@ -1151,6 +1161,7 @@
11511161
</description>
11521162
</method>
11531163
<method name="seed">
1164+
<return type="void" />
11541165
<param index="0" name="base" type="int" />
11551166
<description>
11561167
Sets the seed for the random number generator to [param base]. Setting the seed manually can ensure consistent, repeatable results for most random functions.

doc/classes/CodeEdit.xml

+13
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,9 @@
587587
<member name="symbol_lookup_on_click" type="bool" setter="set_symbol_lookup_on_click_enabled" getter="is_symbol_lookup_on_click_enabled" default="false">
588588
Set when a validated word from [signal symbol_validate] is clicked, the [signal symbol_lookup] should be emitted.
589589
</member>
590+
<member name="symbol_tooltip_on_hover" type="bool" setter="set_symbol_tooltip_on_hover_enabled" getter="is_symbol_tooltip_on_hover_enabled" default="false">
591+
Set when a word is hovered, the [signal symbol_hovered] should be emitted.
592+
</member>
590593
<member name="text_direction" type="int" setter="set_text_direction" getter="get_text_direction" overrides="TextEdit" enum="Control.TextDirection" default="1" />
591594
</members>
592595
<signals>
@@ -601,6 +604,15 @@
601604
Emitted when the user requests code completion. This signal will not be sent if [method _request_code_completion] is overridden or [member code_completion_enabled] is [code]false[/code].
602605
</description>
603606
</signal>
607+
<signal name="symbol_hovered">
608+
<param index="0" name="symbol" type="String" />
609+
<param index="1" name="line" type="int" />
610+
<param index="2" name="column" type="int" />
611+
<description>
612+
Emitted when the user hovers over a symbol. Unlike [signal Control.mouse_entered], this signal is not emitted immediately, but when the cursor is over the symbol for [member ProjectSettings.gui/timers/tooltip_delay_sec] seconds.
613+
[b]Note:[/b] [member symbol_tooltip_on_hover] must be [code]true[/code] for this signal to be emitted.
614+
</description>
615+
</signal>
604616
<signal name="symbol_lookup">
605617
<param index="0" name="symbol" type="String" />
606618
<param index="1" name="line" type="int" />
@@ -613,6 +625,7 @@
613625
<param index="0" name="symbol" type="String" />
614626
<description>
615627
Emitted when the user hovers over a symbol. The symbol should be validated and responded to, by calling [method set_symbol_lookup_word_as_valid].
628+
[b]Note:[/b] [member symbol_lookup_on_click] must be [code]true[/code] for this signal to be emitted.
616629
</description>
617630
</signal>
618631
</signals>

doc/classes/ScriptExtension.xml

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
<description>
3333
</description>
3434
</method>
35+
<method name="_get_doc_class_name" qualifiers="virtual const">
36+
<return type="StringName" />
37+
<description>
38+
</description>
39+
</method>
3540
<method name="_get_documentation" qualifiers="virtual const">
3641
<return type="Dictionary[]" />
3742
<description>

0 commit comments

Comments
 (0)