Skip to content

Commit 49e8d3f

Browse files
Autocompletion: Don't use next for GET_NODE inference
1 parent 019ab87 commit 49e8d3f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

modules/gdscript/gdscript_editor.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3142,8 +3142,21 @@ static bool _get_subscript_type(GDScriptParser::CompletionContext &p_context, co
31423142
}
31433143
} break;
31443144
case GDScriptParser::IdentifierNode::Source::LOCAL_VARIABLE: {
3145-
if (identifier_node->next != nullptr && identifier_node->next->type == GDScriptParser::ClassNode::Node::GET_NODE) {
3146-
get_node = static_cast<GDScriptParser::GetNodeNode *>(identifier_node->next);
3145+
// TODO: Do basic assignment flow analysis like in `_guess_expression_type`.
3146+
const GDScriptParser::SuiteNode::Local local = identifier_node->suite->get_local(identifier_node->name);
3147+
switch (local.type) {
3148+
case GDScriptParser::SuiteNode::Local::CONSTANT: {
3149+
if (local.constant->initializer && local.constant->initializer->type == GDScriptParser::Node::GET_NODE) {
3150+
get_node = static_cast<GDScriptParser::GetNodeNode *>(local.constant->initializer);
3151+
}
3152+
} break;
3153+
case GDScriptParser::SuiteNode::Local::VARIABLE: {
3154+
if (local.variable->initializer && local.variable->initializer->type == GDScriptParser::Node::GET_NODE) {
3155+
get_node = static_cast<GDScriptParser::GetNodeNode *>(local.variable->initializer);
3156+
}
3157+
} break;
3158+
default: {
3159+
} break;
31473160
}
31483161
} break;
31493162
default: {

modules/gdscript/tests/scripts/completion/get_node/local/local.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ extends Node
22

33
func a():
44
var test = $AnimationPlayer
5+
var foo = 10
56
test.➡
67
pass

0 commit comments

Comments
 (0)