Skip to content

Commit

Permalink
Fix language server thread crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan-000 committed Nov 30, 2024
1 parent 77dcf97 commit e6a4c17
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 14 additions & 3 deletions modules/gdscript/language_server/gdscript_text_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,23 @@ 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 ((bool)_EDITOR_GET("network/language_server/use_thread")) {
// its not safe to call "reload_scripts" from the currrent thread, so it needs to be deferred
// otherwise it will randomly cause a crash.
(callable_mp(this, &GDScriptTextDocument::reload_script)).call_deferred(scr);
} else {
reload_script(scr);
}
}
}

void GDScriptTextDocument::reload_script(Ref<GDScript> to_reload_script) {
ScriptEditor::get_singleton()->reload_scripts(true);
ScriptEditor::get_singleton()->update_docs_from_script(to_reload_script);
ScriptEditor::get_singleton()->trigger_live_script_reload(to_reload_script->get_path());
}

lsp::TextDocumentItem GDScriptTextDocument::load_document_item(const Variant &p_param) {
lsp::TextDocumentItem doc;
Dictionary params = p_param;
Expand Down
2 changes: 2 additions & 0 deletions modules/gdscript/language_server/gdscript_text_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include "core/io/file_access.h"
#include "core/object/ref_counted.h"
#include "modules/gdscript/gdscript.h"

class GDScriptTextDocument : public RefCounted {
GDCLASS(GDScriptTextDocument, RefCounted)
Expand All @@ -49,6 +50,7 @@ class GDScriptTextDocument : public RefCounted {
void willSaveWaitUntil(const Variant &p_param);
void didSave(const Variant &p_param);

void reload_script(Ref<GDScript> 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);

Expand Down

0 comments on commit e6a4c17

Please sign in to comment.