From 6db17a523e3747c489747d52de62790d9148d25d Mon Sep 17 00:00:00 2001 From: Francois Belair Date: Fri, 6 Aug 2021 15:20:47 -0400 Subject: [PATCH] Fix LSP completion crashing on sceneless scripts --- .../gdscript_text_document.cpp | 10 +++++-- .../language_server/gdscript_workspace.cpp | 28 ++++++++++--------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp index fed4d80742a..825b8d1cc95 100644 --- a/modules/gdscript/language_server/gdscript_text_document.cpp +++ b/modules/gdscript/language_server/gdscript_text_document.cpp @@ -425,9 +425,13 @@ void GDScriptTextDocument::sync_script_content(const String &p_path, const Strin GDScriptLanguageProtocol::get_singleton()->get_workspace()->parse_script(path, p_content); EditorFileSystem::get_singleton()->update_file(path); - Ref script = ResourceLoader::load(path); - script->load_source_code(path); - script->reload(true); + Error error; + Ref script = ResourceLoader::load(path, "", false, &error); + if (error == OK) { + if (script->load_source_code(path) == OK) { + script->reload(true); + } + } } void GDScriptTextDocument::show_native_symbol_in_editor(const String &p_symbol_id) { diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp index 2de15177a06..69a639d3ff3 100644 --- a/modules/gdscript/language_server/gdscript_workspace.cpp +++ b/modules/gdscript/language_server/gdscript_workspace.cpp @@ -517,22 +517,24 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List script = current->get_script(); + if (script.is_valid() && script->get_path() == path) { + break; + } + for (int i = 0; i < current->get_child_count(); ++i) { + stack.push_back(current->get_child(i)); + } + } + Ref script = current->get_script(); - if (script.is_valid() && script->get_path() == path) { - break; + if (!script.is_valid() || script->get_path() != path) { + current = owner_scene_node; } - for (int i = 0; i < current->get_child_count(); ++i) { - stack.push_back(current->get_child(i)); - } - } - - Ref script = current->get_script(); - if (!script.is_valid() || script->get_path() != path) { - current = owner_scene_node; } String code = parser->get_text_for_completion(p_params.position);