1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Merge pull request #106198 from SatLess/User-Func-Autocomplete

Add code completion for user-defined methods when overriding in GDScript
This commit is contained in:
Rémi Verschelde
2025-06-09 00:44:22 +02:00
11 changed files with 124 additions and 9 deletions

View File

@@ -3519,9 +3519,29 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
} break;
case GDScriptParser::COMPLETION_OVERRIDE_METHOD: {
GDScriptParser::DataType native_type = completion_context.current_class->base_type;
GDScriptParser::FunctionNode *function_node = static_cast<GDScriptParser::FunctionNode *>(completion_context.node);
bool is_static = function_node != nullptr && function_node->is_static;
while (native_type.is_set() && native_type.kind != GDScriptParser::DataType::NATIVE) {
switch (native_type.kind) {
case GDScriptParser::DataType::CLASS: {
for (const GDScriptParser::ClassNode::Member &member : native_type.class_type->members) {
if (member.type != GDScriptParser::ClassNode::Member::FUNCTION) {
continue;
}
if (options.has(member.function->identifier->name) || completion_context.current_class->has_function(member.function->identifier->name)) {
continue;
}
if (is_static != member.function->is_static) {
continue;
}
String display_name = member.function->identifier->name;
display_name += member.function->signature + ":";
ScriptLanguage::CodeCompletionOption option(display_name, ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION);
options.insert(member.function->identifier->name, option); // Insert name instead of display to track duplicates.
}
native_type = native_type.class_type->base_type;
} break;
default: {
@@ -3542,17 +3562,20 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
bool use_type_hint = EditorSettings::get_singleton()->get_setting("text_editor/completion/add_type_hints").operator bool();
List<MethodInfo> virtual_methods;
ClassDB::get_virtual_methods(class_name, &virtual_methods);
{
if (is_static) {
// Not truly a virtual method, but can also be "overridden".
MethodInfo static_init("_static_init");
static_init.return_val.type = Variant::NIL;
static_init.flags |= METHOD_FLAG_STATIC | METHOD_FLAG_VIRTUAL;
virtual_methods.push_back(static_init);
} else {
ClassDB::get_virtual_methods(class_name, &virtual_methods);
}
for (const MethodInfo &mi : virtual_methods) {
if (options.has(mi.name) || completion_context.current_class->has_function(mi.name)) {
continue;
}
String method_hint = mi.name;
if (method_hint.contains_char(':')) {
method_hint = method_hint.get_slicec(':', 0);