Implement declaration and lambda function tooltips.

This commit is contained in:
PhairZ
2025-03-14 04:18:38 +02:00
committed by Seif El-Din Ahmed
parent 65e73b3a5e
commit 0c3bfae3ef
4 changed files with 27 additions and 1 deletions
@@ -316,6 +316,11 @@ String GDScriptDocGen::docvalue_from_expression(const GDP::ExpressionNode *p_exp
const GDP::IdentifierNode *id = static_cast<const GDP::IdentifierNode *>(p_expression);
return id->name;
} break;
case GDP::Node::LAMBDA: {
const GDP::LambdaNode *lambda = static_cast<const GDP::LambdaNode *>(p_expression);
const GDP::IdentifierNode *id = lambda->function->identifier;
return id != nullptr ? id->name : "<anonymous lambda>";
} break;
default: {
// Nothing to do.
} break;
+9
View File
@@ -3465,6 +3465,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
switch (completion_context.type) {
case GDScriptParser::COMPLETION_NONE:
case GDScriptParser::COMPLETION_DECLARATION:
break;
case GDScriptParser::COMPLETION_ANNOTATION: {
List<MethodInfo> annotations;
@@ -4412,6 +4413,8 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co
case GDScriptParser::COMPLETION_METHOD:
case GDScriptParser::COMPLETION_ASSIGN:
case GDScriptParser::COMPLETION_CALL_ARGUMENTS:
case GDScriptParser::COMPLETION_DECLARATION:
case GDScriptParser::COMPLETION_INHERIT_TYPE:
case GDScriptParser::COMPLETION_IDENTIFIER:
case GDScriptParser::COMPLETION_PROPERTY_METHOD:
case GDScriptParser::COMPLETION_SUBSCRIPT: {
@@ -4604,8 +4607,14 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co
}
} break;
case GDScriptParser::COMPLETION_OVERRIDE_METHOD: {
// This logic applies to any method declaration (override or not),
// but shows parent documentation on virtual method overrides.
GDScriptParser::DataType base_type = context.current_class->base_type;
if (_lookup_symbol_from_base(base_type, p_symbol, r_result) == OK) {
return OK;
}
base_type = context.current_class->get_datatype();
if (_lookup_symbol_from_base(base_type, p_symbol, r_result) == OK) {
return OK;
}
+12
View File
@@ -938,6 +938,8 @@ bool GDScriptParser::has_class(const GDScriptParser::ClassNode *p_class) const {
GDScriptParser::ClassNode *GDScriptParser::parse_class(bool p_is_static) {
ClassNode *n_class = alloc_node<ClassNode>();
make_completion_context(COMPLETION_DECLARATION, n_class);
ClassNode *previous_class = current_class;
current_class = n_class;
n_class->outer = previous_class;
@@ -994,6 +996,8 @@ void GDScriptParser::parse_class_name() {
current_class->fqcn = String(current_class->identifier->name);
}
make_completion_context(COMPLETION_DECLARATION, current_class);
if (match(GDScriptTokenizer::Token::EXTENDS)) {
// Allow extends on the same line.
parse_extends();
@@ -1227,6 +1231,8 @@ GDScriptParser::VariableNode *GDScriptParser::parse_variable(bool p_is_static) {
GDScriptParser::VariableNode *GDScriptParser::parse_variable(bool p_is_static, bool p_allow_property) {
VariableNode *variable = alloc_node<VariableNode>();
make_completion_context(COMPLETION_DECLARATION, variable);
if (!consume(GDScriptTokenizer::Token::IDENTIFIER, R"(Expected variable name after "var".)")) {
complete_extents(variable);
return nullptr;
@@ -1463,6 +1469,8 @@ void GDScriptParser::parse_property_getter(VariableNode *p_variable) {
GDScriptParser::ConstantNode *GDScriptParser::parse_constant(bool p_is_static) {
ConstantNode *constant = alloc_node<ConstantNode>();
make_completion_context(COMPLETION_DECLARATION, constant);
if (!consume(GDScriptTokenizer::Token::IDENTIFIER, R"(Expected constant name after "const".)")) {
complete_extents(constant);
return nullptr;
@@ -1531,6 +1539,8 @@ GDScriptParser::ParameterNode *GDScriptParser::parse_parameter() {
GDScriptParser::SignalNode *GDScriptParser::parse_signal(bool p_is_static) {
SignalNode *signal = alloc_node<SignalNode>();
make_completion_context(COMPLETION_DECLARATION, signal);
if (!consume(GDScriptTokenizer::Token::IDENTIFIER, R"(Expected signal name after "signal".)")) {
complete_extents(signal);
return nullptr;
@@ -1577,6 +1587,8 @@ GDScriptParser::EnumNode *GDScriptParser::parse_enum(bool p_is_static) {
EnumNode *enum_node = alloc_node<EnumNode>();
bool named = false;
make_completion_context(COMPLETION_DECLARATION, enum_node);
if (match(GDScriptTokenizer::Token::IDENTIFIER)) {
enum_node->identifier = parse_identifier();
named = true;
+1 -1
View File
@@ -1297,7 +1297,7 @@ public:
COMPLETION_ATTRIBUTE_METHOD, // After id.| to look for methods.
COMPLETION_BUILT_IN_TYPE_CONSTANT_OR_STATIC_METHOD, // Constants inside a built-in type (e.g. Color.BLUE) or static methods (e.g. Color.html).
COMPLETION_CALL_ARGUMENTS, // Complete with nodes, input actions, enum values (or usual expressions).
// TODO: COMPLETION_DECLARATION, // Potential declaration (var, const, func).
COMPLETION_DECLARATION, // Potential declaration (var, const, class, etc.).
COMPLETION_GET_NODE, // Get node with $ notation.
COMPLETION_IDENTIFIER, // List available identifiers in scope.
COMPLETION_INHERIT_TYPE, // Type after extends. Exclude non-viable types (built-ins, enums, void). Includes subtypes using the argument index.