@@ -245,8 +245,26 @@ void GDScriptParser::apply_pending_warnings() {
245
245
}
246
246
#endif
247
247
248
- void GDScriptParser::make_completion_context (CompletionType p_type, Node *p_node, int p_argument, bool p_force) {
249
- if (!for_completion || (!p_force && completion_context.type != COMPLETION_NONE)) {
248
+ void GDScriptParser::override_completion_context (const Node *p_for_node, CompletionType p_type, Node *p_node, int p_argument) {
249
+ if (!for_completion) {
250
+ return ;
251
+ }
252
+ if (completion_context.node != p_for_node) {
253
+ return ;
254
+ }
255
+ CompletionContext context;
256
+ context.type = p_type;
257
+ context.current_class = current_class;
258
+ context.current_function = current_function;
259
+ context.current_suite = current_suite;
260
+ context.current_line = tokenizer->get_cursor_line ();
261
+ context.current_argument = p_argument;
262
+ context.node = p_node;
263
+ completion_context = context;
264
+ }
265
+
266
+ void GDScriptParser::make_completion_context (CompletionType p_type, Node *p_node, int p_argument) {
267
+ if (!for_completion) {
250
268
return ;
251
269
}
252
270
if (previous.cursor_place != GDScriptTokenizerText::CURSOR_MIDDLE && previous.cursor_place != GDScriptTokenizerText::CURSOR_END && current.cursor_place == GDScriptTokenizerText::CURSOR_NONE) {
@@ -263,8 +281,8 @@ void GDScriptParser::make_completion_context(CompletionType p_type, Node *p_node
263
281
completion_context = context;
264
282
}
265
283
266
- void GDScriptParser::make_completion_context (CompletionType p_type, Variant::Type p_builtin_type, bool p_force ) {
267
- if (!for_completion || (!p_force && completion_context. type != COMPLETION_NONE) ) {
284
+ void GDScriptParser::make_completion_context (CompletionType p_type, Variant::Type p_builtin_type) {
285
+ if (!for_completion) {
268
286
return ;
269
287
}
270
288
if (previous.cursor_place != GDScriptTokenizerText::CURSOR_MIDDLE && previous.cursor_place != GDScriptTokenizerText::CURSOR_END && current.cursor_place == GDScriptTokenizerText::CURSOR_NONE) {
@@ -1618,15 +1636,15 @@ GDScriptParser::AnnotationNode *GDScriptParser::parse_annotation(uint32_t p_vali
1618
1636
advance ();
1619
1637
// Arguments.
1620
1638
push_completion_call (annotation);
1621
- make_completion_context (COMPLETION_ANNOTATION_ARGUMENTS, annotation, 0 , true );
1639
+ make_completion_context (COMPLETION_ANNOTATION_ARGUMENTS, annotation, 0 );
1622
1640
int argument_index = 0 ;
1623
1641
do {
1624
1642
if (check (GDScriptTokenizer::Token::PARENTHESIS_CLOSE)) {
1625
1643
// Allow for trailing comma.
1626
1644
break ;
1627
1645
}
1628
1646
1629
- make_completion_context (COMPLETION_ANNOTATION_ARGUMENTS, annotation, argument_index, true );
1647
+ make_completion_context (COMPLETION_ANNOTATION_ARGUMENTS, annotation, argument_index);
1630
1648
set_last_completion_call_arg (argument_index++);
1631
1649
ExpressionNode *argument = parse_expression (false );
1632
1650
if (argument == nullptr ) {
@@ -2567,8 +2585,11 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_literal(ExpressionNode *p_
2567
2585
}
2568
2586
2569
2587
LiteralNode *literal = alloc_node<LiteralNode>();
2570
- complete_extents (literal);
2571
2588
literal->value = previous.literal ;
2589
+ reset_extents (literal, p_previous_operand);
2590
+ update_extents (literal);
2591
+ make_completion_context (COMPLETION_NONE, literal, -1 );
2592
+ complete_extents (literal);
2572
2593
return literal;
2573
2594
}
2574
2595
@@ -3063,12 +3084,12 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_attribute(ExpressionNode *
3063
3084
const IdentifierNode *id = static_cast <const IdentifierNode *>(p_previous_operand);
3064
3085
Variant::Type builtin_type = get_builtin_type (id->name );
3065
3086
if (builtin_type < Variant::VARIANT_MAX) {
3066
- make_completion_context (COMPLETION_BUILT_IN_TYPE_CONSTANT_OR_STATIC_METHOD, builtin_type, true );
3087
+ make_completion_context (COMPLETION_BUILT_IN_TYPE_CONSTANT_OR_STATIC_METHOD, builtin_type);
3067
3088
is_builtin = true ;
3068
3089
}
3069
3090
}
3070
3091
if (!is_builtin) {
3071
- make_completion_context (COMPLETION_ATTRIBUTE, attribute, -1 , true );
3092
+ make_completion_context (COMPLETION_ATTRIBUTE, attribute, -1 );
3072
3093
}
3073
3094
}
3074
3095
@@ -3193,23 +3214,24 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_call(ExpressionNode *p_pre
3193
3214
push_completion_call (call);
3194
3215
int argument_index = 0 ;
3195
3216
do {
3196
- make_completion_context (ct, call, argument_index++, true );
3217
+ make_completion_context (ct, call, argument_index);
3197
3218
if (check (GDScriptTokenizer::Token::PARENTHESIS_CLOSE)) {
3198
3219
// Allow for trailing comma.
3199
3220
break ;
3200
3221
}
3201
- bool use_identifier_completion = current.cursor_place == GDScriptTokenizerText::CURSOR_END || current.cursor_place == GDScriptTokenizerText::CURSOR_MIDDLE;
3202
3222
ExpressionNode *argument = parse_expression (false );
3203
3223
if (argument == nullptr ) {
3204
3224
push_error (R"( Expected expression as the function argument.)" );
3205
3225
} else {
3206
3226
call->arguments .push_back (argument);
3207
3227
3208
- if (argument->type == Node::IDENTIFIER && use_identifier_completion ) {
3209
- completion_context. type = COMPLETION_IDENTIFIER ;
3228
+ if (argument->type == Node::LITERAL ) {
3229
+ override_completion_context (argument, ct, call, argument_index) ;
3210
3230
}
3211
3231
}
3232
+
3212
3233
ct = COMPLETION_CALL_ARGUMENTS;
3234
+ argument_index++;
3213
3235
} while (match (GDScriptTokenizer::Token::COMMA));
3214
3236
pop_completion_call ();
3215
3237
@@ -3222,7 +3244,7 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_call(ExpressionNode *p_pre
3222
3244
3223
3245
GDScriptParser::ExpressionNode *GDScriptParser::parse_get_node (ExpressionNode *p_previous_operand, bool p_can_assign) {
3224
3246
// We want code completion after a DOLLAR even if the current code is invalid.
3225
- make_completion_context (COMPLETION_GET_NODE, nullptr , -1 , true );
3247
+ make_completion_context (COMPLETION_GET_NODE, nullptr , -1 );
3226
3248
3227
3249
if (!current.is_node_name () && !check (GDScriptTokenizer::Token::LITERAL) && !check (GDScriptTokenizer::Token::SLASH) && !check (GDScriptTokenizer::Token::PERCENT)) {
3228
3250
push_error (vformat (R"( Expected node path as string or identifier after "%s".)" , previous.get_name ()));
@@ -3279,7 +3301,7 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_get_node(ExpressionNode *p
3279
3301
path_state = PATH_STATE_SLASH;
3280
3302
}
3281
3303
3282
- make_completion_context (COMPLETION_GET_NODE, get_node, context_argument++, true );
3304
+ make_completion_context (COMPLETION_GET_NODE, get_node, context_argument++);
3283
3305
3284
3306
if (match (GDScriptTokenizer::Token::LITERAL)) {
3285
3307
if (previous.literal .get_type () != Variant::STRING) {
0 commit comments