diff options
author | Francois Belair <razoric480@gmail.com> | 2021-08-06 14:55:05 -0400 |
---|---|---|
committer | Francois Belair <razoric480@gmail.com> | 2021-08-06 14:55:05 -0400 |
commit | 070d63496622bfd87f98c8f49669b87756906834 (patch) | |
tree | a3bdd06e116a179b31ad4b5a88854c9c1b994404 /modules/gdscript/language_server/gdscript_workspace.cpp | |
parent | 18c5d862e425b121498aaf613772169f911581e6 (diff) |
Fix LSP completion crashing on scene-less scripts
Diffstat (limited to 'modules/gdscript/language_server/gdscript_workspace.cpp')
-rw-r--r-- | modules/gdscript/language_server/gdscript_workspace.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
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); |