diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp index 2224bb00402..9b3a1a78df3 100644 --- a/modules/gdscript/language_server/gdscript_text_document.cpp +++ b/modules/gdscript/language_server/gdscript_text_document.cpp @@ -112,12 +112,21 @@ void GDScriptTextDocument::didSave(const Variant &p_param) { } scr->update_exports(); - ScriptEditor::get_singleton()->reload_scripts(true); - ScriptEditor::get_singleton()->update_docs_from_script(scr); - ScriptEditor::get_singleton()->trigger_live_script_reload(scr->get_path()); + + if (!Thread::is_main_thread()) { + callable_mp(this, &GDScriptTextDocument::reload_script).call_deferred(scr); + } else { + reload_script(scr); + } } } +void GDScriptTextDocument::reload_script(Ref p_to_reload_script) { + ScriptEditor::get_singleton()->reload_scripts(true); + ScriptEditor::get_singleton()->update_docs_from_script(p_to_reload_script); + ScriptEditor::get_singleton()->trigger_live_script_reload(p_to_reload_script->get_path()); +} + lsp::TextDocumentItem GDScriptTextDocument::load_document_item(const Variant &p_param) { lsp::TextDocumentItem doc; Dictionary params = p_param; diff --git a/modules/gdscript/language_server/gdscript_text_document.h b/modules/gdscript/language_server/gdscript_text_document.h index cfd0490f0a8..6b89adfe63b 100644 --- a/modules/gdscript/language_server/gdscript_text_document.h +++ b/modules/gdscript/language_server/gdscript_text_document.h @@ -36,6 +36,8 @@ #include "core/io/file_access.h" #include "core/object/ref_counted.h" +class GDScript; + class GDScriptTextDocument : public RefCounted { GDCLASS(GDScriptTextDocument, RefCounted) protected: @@ -49,6 +51,7 @@ protected: void willSaveWaitUntil(const Variant &p_param); void didSave(const Variant &p_param); + void reload_script(Ref p_to_reload_script); void sync_script_content(const String &p_path, const String &p_content); void show_native_symbol_in_editor(const String &p_symbol_id);