Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest scene unique nodes in get_node autocompletion #85384

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions modules/gdscript/gdscript_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3112,6 +3112,11 @@ ::Error GDScriptLanguage::complete_code(const String &p_code, const String &p_pa
List<String> 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<GDScriptParser::GetNodeNode *>(completion_context.node)->use_dollar) {
for_unique_name = true;
}

for (const String &E : opts) {
r_forced = true;
String opt = E.strip_edges();
Expand All @@ -3120,6 +3125,14 @@ ::Error GDScriptLanguage::complete_code(const String &p_code, const String &p_pa
// 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()) {
Expand All @@ -3131,11 +3144,13 @@ ::Error GDScriptLanguage::complete_code(const String &p_code, const String &p_pa
options.insert(option.display, option);
}

// Get autoloads.
for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &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<StringName, ProjectSettings::AutoloadInfo> &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;
Expand Down
4 changes: 4 additions & 0 deletions scene/main/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3029,6 +3029,10 @@ static void _add_nodes_to_options(const Node *p_base, const Node *p_node, List<S
if (p_node != p_base && !p_node->get_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++) {
Expand Down
Loading