Skip to content

Autocompletion: Don't use next for GET_NODE inference #107636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

HolonProduction
Copy link
Member

Fixes #107626

Node->next is a parser detail and has no semantic meaning. Using it for completion or analyzing is highly unreliable.

@HolonProduction HolonProduction requested review from a team as code owners June 17, 2025 15:07
@AThousandShips AThousandShips added the cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release label Jun 17, 2025
@AThousandShips AThousandShips added this to the 4.5 milestone Jun 17, 2025
@akien-mga akien-mga changed the title Autocompletion: Don't use next for GET_NODE inference Autocompletion: Don't use next for GET_NODE inference Jun 17, 2025
@@ -3142,8 +3142,21 @@ static bool _get_subscript_type(GDScriptParser::CompletionContext &p_context, co
}
} break;
case GDScriptParser::IdentifierNode::Source::LOCAL_VARIABLE: {
if (identifier_node->next != nullptr && identifier_node->next->type == GDScriptParser::ClassNode::Node::GET_NODE) {
get_node = static_cast<GDScriptParser::GetNodeNode *>(identifier_node->next);
// TODO: Do basic assignment flow analysis like in `_guess_expression_type`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by the comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard code path for type detection takes assignments into account when picking the expression from which to guess the type.

var a
a = "hello"
a. # suggests string methods

This special code path for GET_NODE does not do that right now and only works with the initializer of the variable.

But to support that without duplicating a lot of code, we'd probably need to remove _get_subscript_type and integrate GET_NODE into the standard _guess_expression_type code path. So it isn't a quick fix, which is why I just added a comment about it for now.

@Repiteo Repiteo merged commit bad29ef into godotengine:master Jul 1, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Jul 1, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release topic:editor topic:gdscript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code complete on $-derived variables doesn't work past the 2nd statement
5 participants