Merge pull request #96160 from HolonProduction/dict-fix

Autocompletion: Enable string literal completion in subscripts
This commit is contained in:
Rémi Verschelde 2024-08-27 16:55:31 +02:00
commit 3eba191c9e
No known key found for this signature in database
GPG Key ID: C3336907360768E1
19 changed files with 181 additions and 0 deletions

View File

@ -3122,6 +3122,12 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_subscript(ExpressionNode *
subscript->base = p_previous_operand; subscript->base = p_previous_operand;
subscript->index = parse_expression(false); subscript->index = parse_expression(false);
#ifdef TOOLS_ENABLED
if (subscript->index != nullptr && subscript->index->type == Node::LITERAL) {
override_completion_context(subscript->index, COMPLETION_SUBSCRIPT, subscript);
}
#endif
if (subscript->index == nullptr) { if (subscript->index == nullptr) {
push_error(R"(Expected expression after "[".)"); push_error(R"(Expected expression after "[".)");
} }

View File

@ -0,0 +1,9 @@
[output]
include=[
{"display": "outer"},
{"display": "inner"},
]
exclude=[
{"display": "append"},
{"display": "\"append\""},
]

View File

@ -0,0 +1,10 @@
extends Node
var outer
func _ready() -> void:
var inner
var array: Array
array[i]

View File

@ -0,0 +1,9 @@
[output]
include=[
{"display": "outer"},
{"display": "inner"},
]
exclude=[
{"display": "append"},
{"display": "\"append\""},
]

View File

@ -0,0 +1,10 @@
extends Node
var outer
func _ready() -> void:
var inner
var array = []
array[i]

View File

@ -0,0 +1,11 @@
[output]
include=[
{"display": "\"key1\""},
{"display": "\"key2\""},
]
exclude=[
{"display": "keys"},
{"display": "\"keys\""},
{"display": "key1"},
{"display": "key2"},
]

View File

@ -0,0 +1,13 @@
extends Node
var outer
const dict = {
"key1": "value",
"key2": null,
}
func _ready() -> void:
var inner
dict[""]

View File

@ -0,0 +1,9 @@
[output]
include=[
{"display": "outer"},
{"display": "inner"},
]
exclude=[
{"display": "keys"},
{"display": "\"keys\""},
]

View File

@ -0,0 +1,10 @@
extends Node
var outer
func _ready() -> void:
var inner
var dict: Dictionary
dict[i]

View File

@ -0,0 +1,9 @@
[output]
include=[
{"display": "outer"},
{"display": "inner"},
]
exclude=[
{"display": "keys"},
{"display": "\"keys\""},
]

View File

@ -0,0 +1,10 @@
extends Node
var outer
func _ready() -> void:
var inner
var dict = {}
dict[i]

View File

@ -0,0 +1,11 @@
[output]
include=[
{"display": "\"key1\""},
{"display": "\"key2\""},
]
exclude=[
{"display": "keys"},
{"display": "\"keys\""},
{"display": "key1"},
{"display": "key2"},
]

View File

@ -0,0 +1,13 @@
extends Node
var outer
func _ready() -> void:
var inner
var dict: Dictionary = {
"key1": "value",
"key2": null,
}
dict[""]

View File

@ -0,0 +1,9 @@
[output]
exclude=[
{"display": "keys"},
{"display": "\"keys\""},
{"display": "key1"},
{"display": "key2"},
{"display": "\"key1\""},
{"display": "\"key2\""},
]

View File

@ -0,0 +1,13 @@
extends Node
var outer
var dict = {
"key1": "value",
"key2": null,
}
func _ready() -> void:
var inner
dict[""]

View File

@ -0,0 +1,5 @@
[output]
include=[
{"display": "outer"},
{"display": "inner"},
]

View File

@ -0,0 +1,10 @@
extends Node
var outer
func _ready() -> void:
var inner
var array
array[i]

View File

@ -0,0 +1,5 @@
[output]
include=[
{"display": "outer"},
{"display": "inner"},
]

View File

@ -0,0 +1,9 @@
extends Node
var outer
var array
func _ready() -> void:
var inner
array[i]