From 8cc85515aff75352780001cf1b4321b75d87d65f Mon Sep 17 00:00:00 2001 From: HolonProduction Date: Sun, 26 Nov 2023 15:41:29 +0100 Subject: [PATCH] Suggest scene unique nodes in `get_node` autocompletion --- modules/gdscript/gdscript_editor.cpp | 25 ++++++++++++++++++++----- scene/main/node.cpp | 4 ++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 7c342cc41a2..6c77f5ef728 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -3112,6 +3112,11 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c List opts; p_owner->get_argument_options("get_node", 0, &opts); + bool for_unique_name = false; + if (completion_context.node != nullptr && completion_context.node->type == GDScriptParser::Node::GET_NODE && !static_cast(completion_context.node)->use_dollar) { + for_unique_name = true; + } + for (const String &E : opts) { r_forced = true; String opt = E.strip_edges(); @@ -3120,6 +3125,14 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c // or handle NodePaths which are valid identifiers and don't need quotes. opt = opt.unquote(); } + + if (for_unique_name) { + if (!opt.begins_with("%")) { + continue; + } + opt = opt.substr(1); + } + // The path needs quotes if it's not a valid identifier (with an exception // for "/" as path separator, which also doesn't require quotes). if (!opt.replace("/", "_").is_valid_identifier()) { @@ -3131,11 +3144,13 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c options.insert(option.display, option); } - // Get autoloads. - for (const KeyValue &E : ProjectSettings::get_singleton()->get_autoload_list()) { - String path = "/root/" + E.key; - ScriptLanguage::CodeCompletionOption option(path.quote(quote_style), ScriptLanguage::CODE_COMPLETION_KIND_NODE_PATH); - options.insert(option.display, option); + if (!for_unique_name) { + // Get autoloads. + for (const KeyValue &E : ProjectSettings::get_singleton()->get_autoload_list()) { + String path = "/root/" + E.key; + ScriptLanguage::CodeCompletionOption option(path.quote(quote_style), ScriptLanguage::CODE_COMPLETION_KIND_NODE_PATH); + options.insert(option.display, option); + } } } } break; diff --git a/scene/main/node.cpp b/scene/main/node.cpp index e730f47607e..31f79423d1f 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -3029,6 +3029,10 @@ static void _add_nodes_to_options(const Node *p_base, const Node *p_node, Listget_owner()) { return; } + if (p_node->is_unique_name_in_owner() && p_node->get_owner() == p_base) { + String n = "%" + p_node->get_name(); + r_options->push_back(n.quote()); + } String n = p_base->get_path_to(p_node); r_options->push_back(n.quote()); for (int i = 0; i < p_node->get_child_count(); i++) {