Fix signal completion in GDScript editor

This commit is contained in:
Yuri Rubinsky 2022-05-12 16:07:05 +03:00
parent a624bfe150
commit a439832035
5 changed files with 37 additions and 3 deletions

View file

@ -346,6 +346,7 @@ public:
LOOKUP_RESULT_CLASS_CONSTANT,
LOOKUP_RESULT_CLASS_PROPERTY,
LOOKUP_RESULT_CLASS_METHOD,
LOOKUP_RESULT_CLASS_SIGNAL,
LOOKUP_RESULT_CLASS_ENUM,
LOOKUP_RESULT_CLASS_TBD_GLOBALSCOPE,
LOOKUP_RESULT_MAX

View file

@ -157,6 +157,7 @@ void ScriptLanguageExtension::_bind_methods() {
BIND_ENUM_CONSTANT(LOOKUP_RESULT_CLASS_CONSTANT);
BIND_ENUM_CONSTANT(LOOKUP_RESULT_CLASS_PROPERTY);
BIND_ENUM_CONSTANT(LOOKUP_RESULT_CLASS_METHOD);
BIND_ENUM_CONSTANT(LOOKUP_RESULT_CLASS_SIGNAL);
BIND_ENUM_CONSTANT(LOOKUP_RESULT_CLASS_ENUM);
BIND_ENUM_CONSTANT(LOOKUP_RESULT_CLASS_TBD_GLOBALSCOPE);
BIND_ENUM_CONSTANT(LOOKUP_RESULT_MAX);

View file

@ -372,11 +372,13 @@
</constant>
<constant name="LOOKUP_RESULT_CLASS_METHOD" value="4" enum="LookupResultType">
</constant>
<constant name="LOOKUP_RESULT_CLASS_ENUM" value="5" enum="LookupResultType">
<constant name="LOOKUP_RESULT_CLASS_SIGNAL" value="5" enum="LookupResultType">
</constant>
<constant name="LOOKUP_RESULT_CLASS_TBD_GLOBALSCOPE" value="6" enum="LookupResultType">
<constant name="LOOKUP_RESULT_CLASS_ENUM" value="6" enum="LookupResultType">
</constant>
<constant name="LOOKUP_RESULT_MAX" value="7" enum="LookupResultType">
<constant name="LOOKUP_RESULT_CLASS_TBD_GLOBALSCOPE" value="7" enum="LookupResultType">
</constant>
<constant name="LOOKUP_RESULT_MAX" value="8" enum="LookupResultType">
</constant>
<constant name="LOCATION_LOCAL" value="0" enum="CodeCompletionLocation">
The option is local to the location of the code completion query - e.g. a local variable.

View file

@ -854,6 +854,21 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c
emit_signal(SNAME("go_to_help"), "class_method:" + result.class_name + ":" + result.class_member);
} break;
case ScriptLanguage::LOOKUP_RESULT_CLASS_SIGNAL: {
StringName cname = result.class_name;
while (true) {
if (ClassDB::has_signal(cname, result.class_member)) {
result.class_name = cname;
cname = ClassDB::get_parent_class(cname);
} else {
break;
}
}
emit_signal(SNAME("go_to_help"), "class_signal:" + result.class_name + ":" + result.class_member);
} break;
case ScriptLanguage::LOOKUP_RESULT_CLASS_ENUM: {
StringName cname = result.class_name;

View file

@ -1057,6 +1057,14 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
r_result.insert(option.display, option);
}
List<MethodInfo> signals;
ClassDB::get_signal_list(type, &signals);
for (const MethodInfo &E : signals) {
int location = p_recursion_depth + _get_signal_location(type, StringName(E.name));
ScriptLanguage::CodeCompletionOption option(E.name, ScriptLanguage::CODE_COMPLETION_KIND_SIGNAL, location);
r_result.insert(option.display, option);
}
if (!_static || Engine::get_singleton()->has_singleton(type)) {
List<PropertyInfo> pinfo;
ClassDB::get_property_list(type, &pinfo);
@ -3058,6 +3066,13 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co
}
}
if (ClassDB::has_signal(class_name, p_symbol, true)) {
r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS_SIGNAL;
r_result.class_name = base_type.native_type;
r_result.class_member = p_symbol;
return OK;
}
StringName enum_name = ClassDB::get_integer_constant_enum(class_name, p_symbol, true);
if (enum_name != StringName()) {
r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS_ENUM;