Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Code completion is not suggesting the subclass for inherited class

Dexterabe63a168609
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp
index b632e70e154..c0386afc62c 100644
--- a/modules/gdscript/gdscript_editor.cpp
+++ b/modules/gdscript/gdscript_editor.cpp
@@ -1159,30 +1159,40 @@ static void _list_available_types(bool p_inherit_only, GDScriptParser::Completio
}
}
// Check current class for potential types.
- // TODO: Also check classes the current class inherits from.
const GDScriptParser::ClassNode *current = p_context.current_class;
int location_offset = 0;
while (current) {
- for (const GDScriptParser::ClassNode::Member &member : current->members) {
- switch (member.type) {
- case GDScriptParser::ClassNode::Member::CLASS: {
- EditorLanguage::CompletionOption option(member.m_class->identifier->name, EditorLanguage::CompletionKind::CLASS, EditorLanguage::CompletionLocation::LOCAL + location_offset);
- r_result.insert(option.display, option);
- } break;
- case GDScriptParser::ClassNode::Member::ENUM: {
- if (!p_inherit_only) {
- EditorLanguage::CompletionOption option(member.m_enum->identifier->name, EditorLanguage::CompletionKind::ENUM, EditorLanguage::CompletionLocation::LOCAL + location_offset);
- r_result.insert(option.display, option);
- }
- } break;
- case GDScriptParser::ClassNode::Member::CONSTANT: {
- if (member.constant->type_constraint.is_meta_type) {
- EditorLanguage::CompletionOption option(member.constant->identifier->name, EditorLanguage::CompletionKind::CLASS, EditorLanguage::CompletionLocation::LOCAL + location_offset);
+ const GDScriptParser::ClassNode *base = current;
+ while (base) {
+ for (const GDScriptParser::ClassNode::Member &member : base->members) {
+ switch (member.type) {
+ case GDScriptParser::ClassNode::Member::CLASS: {
+ if (p_inherit_only && member.m_class == p_context.current_class) {
+ break;
+ }
+ EditorLanguage::CompletionOption option(member.m_class->identifier->name, EditorLanguage::CompletionKind::CLASS, EditorLanguage::CompletionLocation::LOCAL + location_offset);
r_result.insert(option.display, option);
- }
- } break;
- default:
- break;
+ } break;
+ case GDScriptParser::ClassNode::Member::ENUM: {
+ if (!p_inherit_only) {
+ EditorLanguage::CompletionOption option(member.m_enum->identifier->name, EditorLanguage::CompletionKind::ENUM, EditorLanguage::CompletionLocation::LOCAL + location_offset);
+ r_result.insert(option.display, option);
+ }
+ } break;
+ case GDScriptParser::ClassNode::Member::CONSTANT: {
+ if (member.constant->type_constraint.is_meta_type) {
+ EditorLanguage::CompletionOption option(member.constant->identifier->name, EditorLanguage::CompletionKind::CLASS, EditorLanguage::CompletionLocation::LOCAL + location_offset);
+ r_result.insert(option.display, option);
+ }
+ } break;
+ default:
+ break;
+ }
+ }
+ if (base->base_type.kind == GDScriptParser::DataType::CLASS) {
+ base = base->base_type.class_type;
+ } else {
+ base = nullptr;
}
}
location_offset += 1;
diff --git a/modules/gdscript/tests/scripts/completion/extends/extends_inherited_inner_class.cfg b/modules/gdscript/tests/scripts/completion/extends/extends_inherited_inner_class.cfg
new file mode 100644
index 00000000000..ed283bece0f
--- /dev/null
+++ b/modules/gdscript/tests/scripts/completion/extends/extends_inherited_inner_class.cfg
@@ -0,0 +1,5 @@
+[output]
+
+include=[
+ {"display": "InnerClassA"},
+]
diff --git a/modules/gdscript/tests/scripts/completion/extends/extends_inherited_inner_class.gd b/modules/gdscript/tests/scripts/completion/extends/extends_inherited_inner_class.gd
new file mode 100644
index 00000000000..97fa81639f7
--- /dev/null
+++ b/modules/gdscript/tests/scripts/completion/extends/extends_inherited_inner_class.gd
@@ -0,0 +1,3 @@
+extends TestExtendsClass
+
+class InnerClassB extends ➡
diff --git a/modules/gdscript/tests/scripts/completion/extends/extends_self.cfg b/modules/gdscript/tests/scripts/completion/extends/extends_self.cfg
new file mode 100644
index 00000000000..8b33dc2dfa5
--- /dev/null
+++ b/modules/gdscript/tests/scripts/completion/extends/extends_self.cfg
@@ -0,0 +1,10 @@
+[output]
+
+include=[
+ {"display": "InnerClassA"},
+ {"display": "InnerClassB"},
+]
+
+exclude=[
+ {"display": "InnerClassC"},
+]
diff --git a/modules/gdscript/tests/scripts/completion/extends/extends_self.gd b/modules/gdscript/tests/scripts/completion/extends/extends_self.gd
new file mode 100644
index 00000000000..2375b4cd58d
--- /dev/null
+++ b/modules/gdscript/tests/scripts/completion/extends/extends_self.gd
@@ -0,0 +1,9 @@
+extends Node
+
+class InnerClassA extends Node:
+ pass
+
+class InnerClassB extends Node:
+ pass
+
+class InnerClassC extends ➡
diff --git a/modules/gdscript/tests/scripts/completion/extends/test_extends_class.notest.gd b/modules/gdscript/tests/scripts/completion/extends/test_extends_class.notest.gd
new file mode 100644
index 00000000000..cc5bdc7cd2b
--- /dev/null
+++ b/modules/gdscript/tests/scripts/completion/extends/test_extends_class.notest.gd
@@ -0,0 +1,5 @@
+class_name TestExtendsClass
+extends Node
+
+class InnerClassA extends Node:
+ pass