From ab0314938ed163af6a2167a8d40b2dd1ca9f4603 Mon Sep 17 00:00:00 2001 From: Rindbee Date: Tue, 4 Oct 2022 13:58:58 +0800 Subject: Implement `GDScriptTextDocument::willSaveWaitUntil` to clean up outdated documents before saving Implement `GDScriptTextDocument::willSaveWaitUntil` to clean up outdated documents before saving, then update the document in `GDScriptTextDocument::didSave`. --- editor/plugins/script_editor_plugin.cpp | 80 ++++++++++------------ editor/plugins/script_editor_plugin.h | 2 + .../language_server/gdscript_text_document.cpp | 32 +++++---- .../language_server/gdscript_text_document.h | 1 + modules/gdscript/language_server/godot_lsp.h | 2 +- 5 files changed, 59 insertions(+), 58 deletions(-) diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index f70f0dc0aa..a3f2c2509f 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -1301,26 +1301,15 @@ void ScriptEditor::_menu_option(int p_option) { break; } - if (script != nullptr) { - Vector documentations = script->get_documentation(); - for (int j = 0; j < documentations.size(); j++) { - const DocData::ClassDoc &doc = documentations.get(j); - if (EditorHelp::get_doc_data()->has_doc(doc.name)) { - EditorHelp::get_doc_data()->remove_doc(doc.name); - } - } + if (script.is_valid()) { + clear_docs_from_script(script); } EditorNode::get_singleton()->push_item(resource.ptr()); EditorNode::get_singleton()->save_resource_as(resource); - if (script != nullptr) { - Vector documentations = script->get_documentation(); - for (int j = 0; j < documentations.size(); j++) { - const DocData::ClassDoc &doc = documentations.get(j); - EditorHelp::get_doc_data()->add_doc(doc); - update_doc(doc.name); - } + if (script.is_valid()) { + update_docs_from_script(script); } } break; @@ -2418,14 +2407,8 @@ void ScriptEditor::save_current_script() { return; } - if (script != nullptr) { - Vector documentations = script->get_documentation(); - for (int j = 0; j < documentations.size(); j++) { - const DocData::ClassDoc &doc = documentations.get(j); - if (EditorHelp::get_doc_data()->has_doc(doc.name)) { - EditorHelp::get_doc_data()->remove_doc(doc.name); - } - } + if (script.is_valid()) { + clear_docs_from_script(script); } if (resource->is_built_in()) { @@ -2440,13 +2423,8 @@ void ScriptEditor::save_current_script() { EditorNode::get_singleton()->save_resource(resource); } - if (script != nullptr) { - Vector documentations = script->get_documentation(); - for (int j = 0; j < documentations.size(); j++) { - const DocData::ClassDoc &doc = documentations.get(j); - EditorHelp::get_doc_data()->add_doc(doc); - update_doc(doc.name); - } + if (script.is_valid()) { + update_docs_from_script(script); } } @@ -2491,25 +2469,14 @@ void ScriptEditor::save_all_scripts() { continue; } - if (script != nullptr) { - Vector documentations = script->get_documentation(); - for (int j = 0; j < documentations.size(); j++) { - const DocData::ClassDoc &doc = documentations.get(j); - if (EditorHelp::get_doc_data()->has_doc(doc.name)) { - EditorHelp::get_doc_data()->remove_doc(doc.name); - } - } + if (script.is_valid()) { + clear_docs_from_script(script); } EditorNode::get_singleton()->save_resource(edited_res); //external script, save it - if (script != nullptr) { - Vector documentations = script->get_documentation(); - for (int j = 0; j < documentations.size(); j++) { - const DocData::ClassDoc &doc = documentations.get(j); - EditorHelp::get_doc_data()->add_doc(doc); - update_doc(doc.name); - } + if (script.is_valid()) { + update_docs_from_script(script); } } else { // For built-in scripts, save their scenes instead. @@ -3331,6 +3298,29 @@ void ScriptEditor::update_doc(const String &p_name) { } } +void ScriptEditor::clear_docs_from_script(const Ref