summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-08-07 00:01:47 +0200
committerGitHub <noreply@github.com>2021-08-07 00:01:47 +0200
commit4cb406e02a7bc5761fd081b944cc1a5b09e2a365 (patch)
tree780980440599eac9842fca1f484ec36b138ef2db
parent1899dc996163cff445556a4f214d3e2205e027d9 (diff)
parent070d63496622bfd87f98c8f49669b87756906834 (diff)
Merge pull request #51332 from Razoric480/fix-completion-sceneless
Fix LSP completion crashing on scene-less scripts
-rw-r--r--modules/gdscript/language_server/gdscript_text_document.cpp10
-rw-r--r--modules/gdscript/language_server/gdscript_workspace.cpp28
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 c0013ac23a..9574c765bc 100644
--- a/modules/gdscript/language_server/gdscript_text_document.cpp
+++ b/modules/gdscript/language_server/gdscript_text_document.cpp
@@ -431,9 +431,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<GDScript> script = ResourceLoader::load(path);
- script->load_source_code(path);
- script->reload(true);
+ Error error;
+ Ref<GDScript> script = ResourceLoader::load(path, "", ResourceFormatLoader::CACHE_MODE_REUSE, &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 4fc229a0f8..1512b4bb89 100644
--- a/modules/gdscript/language_server/gdscript_workspace.cpp
+++ b/modules/gdscript/language_server/gdscript_workspace.cpp
@@ -523,22 +523,24 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S
Array stack;
Node *current = nullptr;
- stack.push_back(owner_scene_node);
+ if (owner_scene_node != nullptr) {
+ stack.push_back(owner_scene_node);
- while (!stack.is_empty()) {
- current = stack.pop_back();
- Ref<GDScript> 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));
+ while (!stack.is_empty()) {
+ current = stack.pop_back();
+ Ref<GDScript> 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<GDScript> script = current->get_script();
- if (!script.is_valid() || script->get_path() != path) {
- current = owner_scene_node;
+ Ref<GDScript> 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);