From a9098e6147d294378bf7c62fb10c83a0d2670b33 Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Mon, 4 Jul 2022 18:56:34 +0300 Subject: Add support for documenting built-in annotations --- modules/gdscript/doc_classes/@GDScript.xml | 141 +++++++++++++++++++++++++++++ modules/gdscript/gdscript.h | 1 + modules/gdscript/gdscript_editor.cpp | 19 ++++ modules/gdscript/gdscript_parser.cpp | 4 + modules/gdscript/gdscript_parser.h | 1 + modules/mono/csharp_script.h | 1 + modules/visual_script/visual_script.cpp | 3 + modules/visual_script/visual_script.h | 1 + 8 files changed, 171 insertions(+) (limited to 'modules') diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml index 70151c4d21..e672ea6454 100644 --- a/modules/gdscript/doc_classes/@GDScript.xml +++ b/modules/gdscript/doc_classes/@GDScript.xml @@ -257,4 +257,145 @@ [b]Note:[/b] "Not a Number" is only a concept with floating-point numbers, and has no equivalent for integers. Dividing an integer [code]0[/code] by [code]0[/code] will not result in [constant NAN] and will result in a run-time error instead. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index feb0a237df..e9a206f48b 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -489,6 +489,7 @@ public: virtual void get_public_functions(List *p_functions) const override; virtual void get_public_constants(List> *p_constants) const override; + virtual void get_public_annotations(List *p_annotations) const override; virtual void profiling_start() override; virtual void profiling_stop() override; diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 474c8094f2..d62104fb5b 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -445,6 +445,16 @@ void GDScriptLanguage::get_public_constants(List> *p_const p_constants->push_back(nan); } +void GDScriptLanguage::get_public_annotations(List *p_annotations) const { + GDScriptParser parser; + List annotations; + parser.get_annotation_list(&annotations); + + for (const MethodInfo &E : annotations) { + p_annotations->push_back(E); + } +} + String GDScriptLanguage::make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const { #ifdef TOOLS_ENABLED bool th = EditorSettings::get_singleton()->get_setting("text_editor/completion/add_type_hints"); @@ -3376,6 +3386,15 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co return OK; } } break; + case GDScriptParser::COMPLETION_ANNOTATION: { + const String annotation_symbol = "@" + p_symbol; + if (parser.annotation_exists(annotation_symbol)) { + r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS_ANNOTATION; + r_result.class_name = "@GDScript"; + r_result.class_member = annotation_symbol; + return OK; + } + } break; default: { } } diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index ca430b0f72..b69eef0a75 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -105,6 +105,10 @@ void GDScriptParser::get_annotation_list(List *r_annotations) const } } +bool GDScriptParser::annotation_exists(const String &p_annotation_name) const { + return valid_annotations.has(p_annotation_name); +} + GDScriptParser::GDScriptParser() { // Register valid annotations. // TODO: Should this be static? diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index e3f8d4b8ba..8f3862b324 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -1413,6 +1413,7 @@ public: CompletionContext get_completion_context() const { return completion_context; } CompletionCall get_completion_call() const { return completion_call; } void get_annotation_list(List *r_annotations) const; + bool annotation_exists(const String &p_annotation_name) const; const List &get_errors() const { return errors; } const List get_dependencies() const { diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h index 69bd8703aa..91b14ba108 100644 --- a/modules/mono/csharp_script.h +++ b/modules/mono/csharp_script.h @@ -502,6 +502,7 @@ public: /* TODO? */ void get_public_functions(List *p_functions) const override {} /* TODO? */ void get_public_constants(List> *p_constants) const override {} + /* TODO? */ void get_public_annotations(List *p_annotations) const override {} void reload_all_scripts() override; void reload_tool_script(const Ref