Merge pull request #85384 from HolonProduction/unique-name-completion
Suggest scene unique nodes in `get_node` autocompletion
This commit is contained in:
commit
28cf7fe2f6
2 changed files with 24 additions and 5 deletions
|
@ -3197,6 +3197,11 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
|
||||||
List<String> opts;
|
List<String> opts;
|
||||||
p_owner->get_argument_options("get_node", 0, &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) {
|
for (const String &E : opts) {
|
||||||
r_forced = true;
|
r_forced = true;
|
||||||
String opt = E.strip_edges();
|
String opt = E.strip_edges();
|
||||||
|
@ -3205,6 +3210,14 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
|
||||||
// or handle NodePaths which are valid identifiers and don't need quotes.
|
// or handle NodePaths which are valid identifiers and don't need quotes.
|
||||||
opt = opt.unquote();
|
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
|
// The path needs quotes if it's not a valid identifier (with an exception
|
||||||
// for "/" as path separator, which also doesn't require quotes).
|
// for "/" as path separator, which also doesn't require quotes).
|
||||||
if (!opt.replace("/", "_").is_valid_identifier()) {
|
if (!opt.replace("/", "_").is_valid_identifier()) {
|
||||||
|
@ -3216,11 +3229,13 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
|
||||||
options.insert(option.display, option);
|
options.insert(option.display, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get autoloads.
|
if (!for_unique_name) {
|
||||||
for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : ProjectSettings::get_singleton()->get_autoload_list()) {
|
// Get autoloads.
|
||||||
String path = "/root/" + E.key;
|
for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : ProjectSettings::get_singleton()->get_autoload_list()) {
|
||||||
ScriptLanguage::CodeCompletionOption option(path.quote(quote_style), ScriptLanguage::CODE_COMPLETION_KIND_NODE_PATH);
|
String path = "/root/" + E.key;
|
||||||
options.insert(option.display, option);
|
ScriptLanguage::CodeCompletionOption option(path.quote(quote_style), ScriptLanguage::CODE_COMPLETION_KIND_NODE_PATH);
|
||||||
|
options.insert(option.display, option);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
|
@ -3088,6 +3088,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()) {
|
if (p_node != p_base && !p_node->get_owner()) {
|
||||||
return;
|
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);
|
String n = p_base->get_path_to(p_node);
|
||||||
r_options->push_back(n.quote());
|
r_options->push_back(n.quote());
|
||||||
for (int i = 0; i < p_node->get_child_count(); i++) {
|
for (int i = 0; i < p_node->get_child_count(); i++) {
|
||||||
|
|
Loading…
Reference in a new issue