Skip to content

Commit 8dd330d

Browse files
Ryan-000adamscottAThousandShips
committed
Fix language server thread crash
Co-Authored-By: Adam Scott <ascott.ca@gmail.com> Co-Authored-By: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
1 parent 77dcf97 commit 8dd330d

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

modules/gdscript/language_server/gdscript_text_document.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,21 @@ void GDScriptTextDocument::didSave(const Variant &p_param) {
112112
}
113113

114114
scr->update_exports();
115-
ScriptEditor::get_singleton()->reload_scripts(true);
116-
ScriptEditor::get_singleton()->update_docs_from_script(scr);
117-
ScriptEditor::get_singleton()->trigger_live_script_reload(scr->get_path());
115+
116+
if (!Thread::is_main_thread()) {
117+
callable_mp(this, &GDScriptTextDocument::reload_script).call_deferred(scr);
118+
} else {
119+
reload_script(scr);
120+
}
118121
}
119122
}
120123

124+
void GDScriptTextDocument::reload_script(Ref<GDScript> p_to_reload_script) {
125+
ScriptEditor::get_singleton()->reload_scripts(true);
126+
ScriptEditor::get_singleton()->update_docs_from_script(p_to_reload_script);
127+
ScriptEditor::get_singleton()->trigger_live_script_reload(p_to_reload_script->get_path());
128+
}
129+
121130
lsp::TextDocumentItem GDScriptTextDocument::load_document_item(const Variant &p_param) {
122131
lsp::TextDocumentItem doc;
123132
Dictionary params = p_param;

modules/gdscript/language_server/gdscript_text_document.h

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include "core/io/file_access.h"
3737
#include "core/object/ref_counted.h"
3838

39+
class GDScript;
40+
3941
class GDScriptTextDocument : public RefCounted {
4042
GDCLASS(GDScriptTextDocument, RefCounted)
4143
protected:
@@ -49,6 +51,7 @@ class GDScriptTextDocument : public RefCounted {
4951
void willSaveWaitUntil(const Variant &p_param);
5052
void didSave(const Variant &p_param);
5153

54+
void reload_script(Ref<GDScript> p_to_reload_script);
5255
void sync_script_content(const String &p_path, const String &p_content);
5356
void show_native_symbol_in_editor(const String &p_symbol_id);
5457

0 commit comments

Comments
 (0)