diff options
author | Francois Belair <razoric480@gmail.com> | 2021-08-05 11:45:37 -0400 |
---|---|---|
committer | Francois Belair <razoric480@gmail.com> | 2021-08-05 12:30:06 -0400 |
commit | 03f8fa9f62c97648491a0d8f0dd7fac6808eb9b4 (patch) | |
tree | a9480b48e1e34e315d3310d6d4bc2b9b237b944c /modules/gdscript/language_server | |
parent | dcf2a62b0540d7b06e74a13290cb569922dfd55c (diff) |
Fix LSP parsing get_node only from the scene root
Diffstat (limited to 'modules/gdscript/language_server')
-rw-r--r-- | modules/gdscript/language_server/gdscript_workspace.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp index 148aeec47a..4fc229a0f8 100644 --- a/modules/gdscript/language_server/gdscript_workspace.cpp +++ b/modules/gdscript/language_server/gdscript_workspace.cpp @@ -520,8 +520,29 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S if (const ExtendGDScriptParser *parser = get_parse_result(path)) { Node *owner_scene_node = _get_owner_scene_node(path); + + Array stack; + Node *current = 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)); + } + } + + 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); - GDScriptLanguage::get_singleton()->complete_code(code, path, owner_scene_node, r_options, forced, call_hint); + GDScriptLanguage::get_singleton()->complete_code(code, path, current, r_options, forced, call_hint); if (owner_scene_node) { memdelete(owner_scene_node); } |