Added working version for user-defined function autocompletion

This commit is contained in:
Sat 2025-05-08 06:22:05 -03:00
parent a2aefab4c7
commit fc4df4b17d
11 changed files with 124 additions and 9 deletions

View file

@ -3521,9 +3521,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: {
@ -3544,17 +3564,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);