Skip to content

Commit

Permalink
Autocompletion: enable string literal completion in subscripts
Browse files Browse the repository at this point in the history
(cherry picked from commit c824403)
  • Loading branch information
HolonProduction authored and Spartan322 committed Feb 4, 2025
1 parent 8fa7c86 commit f697591
Show file tree
Hide file tree
Showing 19 changed files with 181 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/gdscript/gdscript_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3145,6 +3145,12 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_subscript(ExpressionNode *
subscript->base = p_previous_operand;
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) {
push_error(R"(Expected expression after "[".)");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[output]
include=[
{"display": "outer"},
{"display": "inner"},
]
exclude=[
{"display": "append"},
{"display": "\"append\""},
]
10 changes: 10 additions & 0 deletions modules/gdscript/tests/scripts/completion/index/array_type.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends Node

var outer

func _ready() -> void:
var inner

var array: Array

array[i➡]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[output]
include=[
{"display": "outer"},
{"display": "inner"},
]
exclude=[
{"display": "append"},
{"display": "\"append\""},
]
10 changes: 10 additions & 0 deletions modules/gdscript/tests/scripts/completion/index/array_value.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends Node

var outer

func _ready() -> void:
var inner

var array = []

array[i➡]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[output]
include=[
{"display": "\"key1\""},
{"display": "\"key2\""},
]
exclude=[
{"display": "keys"},
{"display": "\"keys\""},
{"display": "key1"},
{"display": "key2"},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends Node

var outer

const dict = {
"key1": "value",
"key2": null,
}

func _ready() -> void:
var inner

dict["➡"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[output]
include=[
{"display": "outer"},
{"display": "inner"},
]
exclude=[
{"display": "keys"},
{"display": "\"keys\""},
]
10 changes: 10 additions & 0 deletions modules/gdscript/tests/scripts/completion/index/dictionary_type.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends Node

var outer

func _ready() -> void:
var inner

var dict: Dictionary

dict[i➡]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[output]
include=[
{"display": "outer"},
{"display": "inner"},
]
exclude=[
{"display": "keys"},
{"display": "\"keys\""},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends Node

var outer

func _ready() -> void:
var inner

var dict = {}

dict[i➡]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[output]
include=[
{"display": "\"key1\""},
{"display": "\"key2\""},
]
exclude=[
{"display": "keys"},
{"display": "\"keys\""},
{"display": "key1"},
{"display": "key2"},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends Node

var outer

func _ready() -> void:
var inner

var dict: Dictionary = {
"key1": "value",
"key2": null,
}

dict["➡"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[output]
exclude=[
{"display": "keys"},
{"display": "\"keys\""},
{"display": "key1"},
{"display": "key2"},
{"display": "\"key1\""},
{"display": "\"key2\""},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends Node

var outer

var dict = {
"key1": "value",
"key2": null,
}

func _ready() -> void:
var inner

dict["➡"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[output]
include=[
{"display": "outer"},
{"display": "inner"},
]
10 changes: 10 additions & 0 deletions modules/gdscript/tests/scripts/completion/index/untyped_local.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends Node

var outer

func _ready() -> void:
var inner

var array

array[i➡]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[output]
include=[
{"display": "outer"},
{"display": "inner"},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extends Node

var outer
var array

func _ready() -> void:
var inner

array[i➡]

0 comments on commit f697591

Please sign in to comment.