summaryrefslogtreecommitdiff
path: root/modules/gdscript
diff options
context:
space:
mode:
authorThakee Nathees <thakeenathees@gmail.com>2020-11-29 09:12:06 +0530
committerThakee Nathees <thakeenathees@gmail.com>2020-12-02 00:48:39 +0530
commit42bfa169960b59c5d9337e9f63862f5feae92d58 (patch)
tree5d20c798d3163bf6bbd80e5658278331d98c4ed2 /modules/gdscript
parentd0e7d9b62f0bcc2ba438b12c8bfbf68d82fff0ea (diff)
Refactor DocData into core and editor (DocTools) parts
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gdscript.cpp20
-rw-r--r--modules/gdscript/gdscript.h3
-rw-r--r--modules/gdscript/gdscript_compiler.cpp6
-rw-r--r--modules/gdscript/gdscript_editor.cpp4
-rw-r--r--modules/gdscript/gdscript_parser.cpp18
-rw-r--r--modules/gdscript/gdscript_parser.h2
-rw-r--r--modules/gdscript/language_server/gdscript_language_protocol.cpp3
-rw-r--r--modules/gdscript/language_server/gdscript_workspace.cpp3
-rw-r--r--modules/gdscript/language_server/lsp.hpp2
9 files changed, 21 insertions, 40 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index 8524ec276a..b00eb6f75b 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -39,8 +39,6 @@
#include "core/io/file_access_encrypted.h"
#include "core/os/file_access.h"
#include "core/os/os.h"
-#include "editor/editor_help.h"
-#include "editor/plugins/script_editor_plugin.h"
#include "gdscript_analyzer.h"
#include "gdscript_cache.h"
#include "gdscript_compiler.h"
@@ -242,7 +240,7 @@ void GDScript::_get_script_method_list(List<MethodInfo> *r_list, bool p_include_
mi.name = E->key();
for (int i = 0; i < func->get_argument_count(); i++) {
PropertyInfo arginfo = func->get_argument_type(i);
-#if TOOLS_ENABLED
+#ifdef TOOLS_ENABLED
arginfo.name = func->get_argument_name(i);
#endif
mi.arguments.push_back(arginfo);
@@ -419,11 +417,8 @@ void GDScript::_add_doc(const DocData::ClassDoc &p_inner_class) {
}
void GDScript::_clear_doc() {
- if (EditorHelp::get_doc_data() && EditorHelp::get_doc_data()->has_doc(doc.name)) {
- EditorHelp::get_doc_data()->remove_doc(doc.name);
- doc = DocData::ClassDoc();
- }
docs.clear();
+ doc = DocData::ClassDoc();
}
void GDScript::_update_doc() {
@@ -581,13 +576,6 @@ void GDScript::_update_doc() {
E->get()->_update_doc();
}
- if (EditorHelp::get_doc_data()) {
- EditorHelp::get_doc_data()->add_doc(doc);
- }
- if (ScriptEditor::get_singleton()) {
- ScriptEditor::get_singleton()->update_doc(doc.name);
- }
-
_add_doc(doc);
}
#endif
@@ -845,8 +833,8 @@ Error GDScript::reload(bool p_keep_state) {
GDScriptCompiler compiler;
err = compiler.compile(&parser, this, p_keep_state);
-#if TOOLS_ENABLED
- this->_update_doc();
+#ifdef TOOLS_ENABLED
+ _update_doc();
#endif
if (err) {
diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h
index a7052914ba..3eb260f95f 100644
--- a/modules/gdscript/gdscript.h
+++ b/modules/gdscript/gdscript.h
@@ -33,10 +33,10 @@
#include "core/debugger/engine_debugger.h"
#include "core/debugger/script_debugger.h"
+#include "core/doc_data.h"
#include "core/io/resource_loader.h"
#include "core/io/resource_saver.h"
#include "core/object/script_language.h"
-#include "editor/doc_data.h"
#include "gdscript_function.h"
class GDScriptNativeClass : public Reference {
@@ -470,6 +470,7 @@ public:
virtual Script *create_script() const;
virtual bool has_named_classes() const;
virtual bool supports_builtin_mode() const;
+ virtual bool supports_documentation() const;
virtual bool can_inherit_from_file() { return true; }
virtual int find_function(const String &p_function, const String &p_code) const;
virtual String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const;
diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp
index 3de09eec05..97f10d4013 100644
--- a/modules/gdscript/gdscript_compiler.cpp
+++ b/modules/gdscript/gdscript_compiler.cpp
@@ -2009,7 +2009,7 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar
}
}
-#if TOOLS_ENABLED
+#ifdef TOOLS_ENABLED
p_script->doc_functions.clear();
p_script->doc_variables.clear();
p_script->doc_constants.clear();
@@ -2142,7 +2142,7 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar
} else {
prop_info.usage = PROPERTY_USAGE_SCRIPT_VARIABLE;
}
-#if TOOLS_ENABLED
+#ifdef TOOLS_ENABLED
p_script->doc_variables[name] = variable->doc_description;
#endif
@@ -2224,7 +2224,7 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar
parameters_names.write[j] = signal->parameters[j]->identifier->name;
}
p_script->_signals[name] = parameters_names;
-#if TOOLS_ENABLED
+#ifdef TOOLS_ENABLED
if (!signal->doc_description.empty()) {
p_script->doc_signals[name] = signal->doc_description;
}
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp
index a426046797..4f847923a4 100644
--- a/modules/gdscript/gdscript_editor.cpp
+++ b/modules/gdscript/gdscript_editor.cpp
@@ -193,6 +193,10 @@ bool GDScriptLanguage::supports_builtin_mode() const {
return true;
}
+bool GDScriptLanguage::supports_documentation() const {
+ return true;
+}
+
int GDScriptLanguage::find_function(const String &p_function, const String &p_code) const {
GDScriptTokenizer tokenizer;
tokenizer.set_source_code(p_code);
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index 5259e831e9..48fca16ab1 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -561,11 +561,7 @@ void GDScriptParser::parse_program() {
#ifdef TOOLS_ENABLED
for (Map<int, GDScriptTokenizer::CommentData>::Element *E = tokenizer.get_comments().front(); E; E = E->next()) {
if (E->get().new_line && E->get().comment.begins_with("##")) {
- if (class_doc_line == -1) {
- class_doc_line = E->key();
- } else {
- class_doc_line = MIN(class_doc_line, E->key());
- }
+ class_doc_line = MIN(class_doc_line, E->key());
}
}
if (has_comment(class_doc_line)) {
@@ -708,6 +704,7 @@ void GDScriptParser::parse_class_member(T *(GDScriptParser::*p_parse_function)()
#ifdef TOOLS_ENABLED
// Consume doc comments.
+ class_doc_line = MIN(class_doc_line, doc_comment_line - 1);
if (has_comment(doc_comment_line)) {
if constexpr (std::is_same_v<T, ClassNode>) {
get_class_doc_comment(doc_comment_line, member->doc_brief_description, member->doc_description, member->doc_tutorials, true);
@@ -2741,12 +2738,6 @@ String GDScriptParser::get_doc_comment(int p_line, bool p_single_line) {
line--;
}
- if (class_doc_line == -1) {
- class_doc_line = line - 1;
- } else {
- class_doc_line = MIN(class_doc_line, line) - 1;
- }
-
int codeblock_begins = 0;
while (comments.has(line)) {
if (!comments[line].new_line || !comments[line].comment.begins_with("##")) {
@@ -2800,11 +2791,6 @@ void GDScriptParser::get_class_doc_comment(int p_line, String &p_brief, String &
}
line--;
}
- if (class_doc_line == -1) {
- class_doc_line = line - 1;
- } else {
- class_doc_line = MIN(class_doc_line, line) - 1;
- }
}
int codeblock_begins = 0;
diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h
index 598ac9cd34..44605bc20f 100644
--- a/modules/gdscript/gdscript_parser.h
+++ b/modules/gdscript/gdscript_parser.h
@@ -1303,7 +1303,7 @@ private:
TypeNode *parse_type(bool p_allow_void = false);
#ifdef TOOLS_ENABLED
// Doc comments.
- int class_doc_line = -1;
+ int class_doc_line = 0x7FFFFFFF;
bool has_comment(int p_line);
String get_doc_comment(int p_line, bool p_single_line = false);
void get_class_doc_comment(int p_line, String &p_brief, String &p_desc, Vector<Pair<String, String>> &p_tutorials, bool p_inner_class);
diff --git a/modules/gdscript/language_server/gdscript_language_protocol.cpp b/modules/gdscript/language_server/gdscript_language_protocol.cpp
index 6ddb0d149e..729be237ec 100644
--- a/modules/gdscript/language_server/gdscript_language_protocol.cpp
+++ b/modules/gdscript/language_server/gdscript_language_protocol.cpp
@@ -33,6 +33,7 @@
#include "core/config/project_settings.h"
#include "core/io/json.h"
#include "core/os/copymem.h"
+#include "editor/doc_tools.h"
#include "editor/editor_log.h"
#include "editor/editor_node.h"
@@ -212,7 +213,7 @@ Dictionary GDScriptLanguageProtocol::initialize(const Dictionary &p_params) {
void GDScriptLanguageProtocol::initialized(const Variant &p_params) {
lsp::GodotCapabilities capabilities;
- DocData *doc = EditorHelp::get_doc_data();
+ DocTools *doc = EditorHelp::get_doc_data();
for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) {
lsp::GodotNativeClassInfo gdclass;
gdclass.name = E->get().name;
diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp
index f6643d07f9..60668e7b31 100644
--- a/modules/gdscript/language_server/gdscript_workspace.cpp
+++ b/modules/gdscript/language_server/gdscript_workspace.cpp
@@ -34,6 +34,7 @@
#include "../gdscript_parser.h"
#include "core/config/project_settings.h"
#include "core/object/script_language.h"
+#include "editor/doc_tools.h"
#include "editor/editor_file_system.h"
#include "editor/editor_help.h"
#include "editor/editor_node.h"
@@ -189,7 +190,7 @@ Error GDScriptWorkspace::initialize() {
return OK;
}
- DocData *doc = EditorHelp::get_doc_data();
+ DocTools *doc = EditorHelp::get_doc_data();
for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) {
const DocData::ClassDoc &class_data = E->value();
lsp::DocumentSymbol class_symbol;
diff --git a/modules/gdscript/language_server/lsp.hpp b/modules/gdscript/language_server/lsp.hpp
index 288fd41c87..1029c53bbf 100644
--- a/modules/gdscript/language_server/lsp.hpp
+++ b/modules/gdscript/language_server/lsp.hpp
@@ -31,9 +31,9 @@
#ifndef GODOT_LSP_H
#define GODOT_LSP_H
+#include "core/doc_data.h"
#include "core/object/class_db.h"
#include "core/templates/list.h"
-#include "editor/doc_data.h"
namespace lsp {