Browse Source

Fix lookup symbol for super()

Chaosus 3 months ago
parent
commit
c232b7c717

+ 9 - 0
modules/gdscript/gdscript_editor.cpp

@@ -3755,6 +3755,8 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
 				}
 				}
 			}
 			}
 		} break;
 		} break;
+		case GDScriptParser::COMPLETION_SUPER:
+			break;
 		case GDScriptParser::COMPLETION_SUPER_METHOD: {
 		case GDScriptParser::COMPLETION_SUPER_METHOD: {
 			if (!completion_context.current_class) {
 			if (!completion_context.current_class) {
 				break;
 				break;
@@ -4315,6 +4317,13 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co
 				return OK;
 				return OK;
 			}
 			}
 		} break;
 		} break;
+		case GDScriptParser::COMPLETION_SUPER: {
+			if (context.current_class && context.current_function) {
+				if (_lookup_symbol_from_base(context.current_class->base_type, context.current_function->info.name, r_result) == OK) {
+					return OK;
+				}
+			}
+		} break;
 		case GDScriptParser::COMPLETION_SUPER_METHOD:
 		case GDScriptParser::COMPLETION_SUPER_METHOD:
 		case GDScriptParser::COMPLETION_METHOD:
 		case GDScriptParser::COMPLETION_METHOD:
 		case GDScriptParser::COMPLETION_ASSIGN:
 		case GDScriptParser::COMPLETION_ASSIGN:

+ 4 - 1
modules/gdscript/gdscript_parser.cpp

@@ -3371,6 +3371,9 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_call(ExpressionNode *p_pre
 	if (previous.type == GDScriptTokenizer::Token::SUPER) {
 	if (previous.type == GDScriptTokenizer::Token::SUPER) {
 		// Super call.
 		// Super call.
 		call->is_super = true;
 		call->is_super = true;
+		if (!check(GDScriptTokenizer::Token::PERIOD)) {
+			make_completion_context(COMPLETION_SUPER, call);
+		}
 		push_multiline(true);
 		push_multiline(true);
 		if (match(GDScriptTokenizer::Token::PARENTHESIS_OPEN)) {
 		if (match(GDScriptTokenizer::Token::PARENTHESIS_OPEN)) {
 			// Implicit call to the parent method of the same name.
 			// Implicit call to the parent method of the same name.
@@ -3387,7 +3390,7 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_call(ExpressionNode *p_pre
 			}
 			}
 		} else {
 		} else {
 			consume(GDScriptTokenizer::Token::PERIOD, R"(Expected "." or "(" after "super".)");
 			consume(GDScriptTokenizer::Token::PERIOD, R"(Expected "." or "(" after "super".)");
-			make_completion_context(COMPLETION_SUPER_METHOD, call, true);
+			make_completion_context(COMPLETION_SUPER_METHOD, call);
 			if (!consume(GDScriptTokenizer::Token::IDENTIFIER, R"(Expected function name after ".".)")) {
 			if (!consume(GDScriptTokenizer::Token::IDENTIFIER, R"(Expected function name after ".".)")) {
 				pop_multiline();
 				pop_multiline();
 				complete_extents(call);
 				complete_extents(call);

+ 1 - 0
modules/gdscript/gdscript_parser.h

@@ -1300,6 +1300,7 @@ public:
 		COMPLETION_PROPERTY_METHOD, // Property setter or getter (list available methods).
 		COMPLETION_PROPERTY_METHOD, // Property setter or getter (list available methods).
 		COMPLETION_RESOURCE_PATH, // For load/preload.
 		COMPLETION_RESOURCE_PATH, // For load/preload.
 		COMPLETION_SUBSCRIPT, // Inside id[|].
 		COMPLETION_SUBSCRIPT, // Inside id[|].
+		COMPLETION_SUPER, // super(), used for lookup.
 		COMPLETION_SUPER_METHOD, // After super.
 		COMPLETION_SUPER_METHOD, // After super.
 		COMPLETION_TYPE_ATTRIBUTE, // Attribute in type name (Type.|).
 		COMPLETION_TYPE_ATTRIBUTE, // Attribute in type name (Type.|).
 		COMPLETION_TYPE_NAME, // Name of type (after :).
 		COMPLETION_TYPE_NAME, // Name of type (after :).

+ 16 - 0
modules/gdscript/tests/scripts/lsp/super.gd

@@ -0,0 +1,16 @@
+extends Node
+
+class Inner1:
+#     ^^^^^^ class1 -> class1
+	func _init():
+	#    ^^^^^ class1:init
+		pass
+
+class Inner2 extends Inner1:
+#     |    |         ^^^^^^ -> class1
+#     ^^^^^^ class2 -> class2
+	func _init():
+	#    ^^^^^ class2:init
+        super ()
+    #   ^^^^^ -> class1:init
+		pass