Skip to content

Commit

Permalink
Improve GDScript autocompletion for methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazy-Rabbit-2001 committed Nov 22, 2024
1 parent f952bfe commit ae853e1
Show file tree
Hide file tree
Showing 52 changed files with 126 additions and 113 deletions.
21 changes: 17 additions & 4 deletions modules/gdscript/gdscript_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,10 +1139,12 @@ static void _find_identifiers_in_class(const GDScriptParser::ClassNode *p_class,
continue;
}
option = ScriptLanguage::CodeCompletionOption(member.function->identifier->name, ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION, location);
if (member.function->parameters.size() > 0) {
if (member.function->parameters.size() > 0 || (member.function->info.flags & METHOD_FLAG_VARARG)) {
option.insert_text += "(";
option.display += U"(\u2026)";
} else {
option.insert_text += "()";
option.display += "()";
}
break;
case GDScriptParser::ClassNode::Member::SIGNAL:
Expand Down Expand Up @@ -1184,6 +1186,7 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
if (!p_types_only && base_type.is_meta_type && base_type.kind != GDScriptParser::DataType::BUILTIN && base_type.kind != GDScriptParser::DataType::ENUM) {
ScriptLanguage::CodeCompletionOption option("new", ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION, ScriptLanguage::LOCATION_LOCAL);
option.insert_text += "(";
option.display += U"(\u2026)";
r_result.insert(option.display, option);
}

Expand Down Expand Up @@ -1241,10 +1244,12 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
}
int location = p_recursion_depth + _get_method_location(scr->get_class_name(), E.name);
ScriptLanguage::CodeCompletionOption option(E.name, ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION, location);
if (E.arguments.size()) {
if (E.arguments.size() || (E.flags & METHOD_FLAG_VARARG)) {
option.insert_text += "(";
option.display += U"(\u2026)";
} else {
option.insert_text += "()";
option.display += "()";
}
r_result.insert(option.display, option);
}
Expand Down Expand Up @@ -1327,10 +1332,12 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
}
int location = p_recursion_depth + _get_method_location(type, E.name);
ScriptLanguage::CodeCompletionOption option(E.name, ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION, location);
if (E.arguments.size()) {
if (E.arguments.size() || (E.flags & METHOD_FLAG_VARARG)) {
option.insert_text += "(";
option.display += U"(\u2026)";
} else {
option.insert_text += "()";
option.display += "()";
}
r_result.insert(option.display, option);
}
Expand Down Expand Up @@ -1398,10 +1405,12 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base
continue;
}
ScriptLanguage::CodeCompletionOption option(E.name, ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION, location);
if (E.arguments.size()) {
if (E.arguments.size() || (E.flags & METHOD_FLAG_VARARG)) {
option.insert_text += "(";
option.display += U"(\u2026)";
} else {
option.insert_text += "()";
option.display += "()";
}
r_result.insert(option.display, option);
}
Expand Down Expand Up @@ -1433,8 +1442,10 @@ static void _find_identifiers(const GDScriptParser::CompletionContext &p_context
ScriptLanguage::CodeCompletionOption option(String(E), ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION);
if (function.arguments.size() || (function.flags & METHOD_FLAG_VARARG)) {
option.insert_text += "(";
option.display += U"(\u2026)";
} else {
option.insert_text += "()";
option.display += "()";
}
r_result.insert(option.display, option);
}
Expand Down Expand Up @@ -1481,6 +1492,7 @@ static void _find_identifiers(const GDScriptParser::CompletionContext &p_context
while (*kwa) {
ScriptLanguage::CodeCompletionOption option(*kwa, ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION);
option.insert_text += "(";
option.display += U"(\u2026)";
r_result.insert(option.display, option);
kwa++;
}
Expand All @@ -1491,6 +1503,7 @@ static void _find_identifiers(const GDScriptParser::CompletionContext &p_context
for (List<StringName>::Element *E = utility_func_names.front(); E; E = E->next()) {
ScriptLanguage::CodeCompletionOption option(E->get(), ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION);
option.insert_text += "(";
option.display += U"(\u2026)"; // As all utility functions contain an argument or more, this is hardcoded here.
r_result.insert(option.display, option);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[output]
include=[
{"display": "new"},
{"display": "new(…)"},
{"display": "SIZE_EXPAND"},
{"display": "SIZE_EXPAND_FILL"},
{"display": "SIZE_FILL"},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[output]
include=[
{"display": "new"},
{"display": "new(…)"},
{"display": "SIZE_EXPAND"},
{"display": "SIZE_EXPAND_FILL"},
{"display": "SIZE_FILL"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ scene="res://completion/get_node/get_node.tscn"
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},

; GDScript: class_a.notest.gd
{"display": "property_of_a"},
{"display": "func_of_a"},
{"display": "func_of_a()"},
{"display": "signal_of_a"},

; GDScript: identifiers.gd
{"display": "test_signal_1"},
{"display": "test_signal_2"},
{"display": "test_var_1"},
{"display": "test_var_2"},
{"display": "test_func_1"},
{"display": "test_func_2"},
{"display": "test_func_1(…)"},
{"display": "test_func_2(…)"},
{"display": "test_parameter_1"},
{"display": "test_parameter_2"},
{"display": "local_test_var_1"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ scene="res://completion/get_node/get_node.tscn"
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},

; GDScript: class_a.notest.gd
{"display": "property_of_a"},
{"display": "func_of_a"},
{"display": "func_of_a()"},
{"display": "signal_of_a"},

; GDScript: identifiers.gd
{"display": "test_signal_1"},
{"display": "test_signal_2"},
{"display": "test_var_1"},
{"display": "test_var_2"},
{"display": "test_func_1"},
{"display": "test_func_2"},
{"display": "test_func_1(…)"},
{"display": "test_func_2(…)"},
{"display": "test_parameter_1"},
{"display": "test_parameter_2"},
{"display": "local_test_var_1"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ scene="res://completion/get_node/get_node.tscn"
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},

; GDScript: class_a.notest.gd
{"display": "property_of_a"},
{"display": "func_of_a"},
{"display": "func_of_a()"},
{"display": "signal_of_a"},

; GDScript: identifiers.gd
{"display": "test_signal_1"},
{"display": "test_signal_2"},
{"display": "test_var_1"},
{"display": "test_var_2"},
{"display": "test_func_1"},
{"display": "test_func_2"},
{"display": "test_func_1(…)"},
{"display": "test_func_2(…)"},
{"display": "test_parameter_1"},
{"display": "test_parameter_2"},
{"display": "local_test_var_1"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ scene="res://completion/get_node/get_node.tscn"
[output]
exclude=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},
{"display": "add_child"},
{"display": "add_child(…)"},

; GDScript: class_a.notest.gd
{"display": "property_of_a"},
{"display": "func_of_a"},
{"display": "func_of_a()"},
{"display": "signal_of_a"},

; GDScript: no_completion_in_string.gd
{"display": "test_signal_1"},
{"display": "test_signal_2"},
{"display": "test_var_1"},
{"display": "test_var_2"},
{"display": "test_func_1"},
{"display": "test_func_2"},
{"display": "test_func_1(…)"},
{"display": "test_func_2(…)"},
{"display": "test_parameter_1"},
{"display": "test_parameter_2"},
{"display": "local_test_var_1"},
Expand Down
8 changes: 4 additions & 4 deletions modules/gdscript/tests/scripts/completion/common/self.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ scene="res://completion/get_node/get_node.tscn"
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},

; GDScript: class_a.notest.gd
{"display": "property_of_a"},
{"display": "func_of_a"},
{"display": "func_of_a()"},
{"display": "signal_of_a"},

; GDScript: self.gd
{"display": "test_signal_1"},
{"display": "test_signal_2"},
{"display": "test_var_1"},
{"display": "test_var_2"},
{"display": "test_func_1"},
{"display": "test_func_2"},
{"display": "test_func_1(…)"},
{"display": "test_func_2(…)"},
]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},
]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ scene="res://completion/get_node/get_node.tscn"
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},

; GDScript: class_a.notest.gd
{"display": "property_of_a"},
{"display": "func_of_a"},
{"display": "func_of_a()"},
{"display": "signal_of_a"},
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ scene="res://completion/get_node/get_node.tscn"
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},

; AnimationPlayer
{"display": "autoplay"},
{"display": "play"},
{"display": "play(…)"},
{"display": "animation_changed"},
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ scene="res://completion/get_node/get_node.tscn"
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},

; GDScript: class_a.notest.gd
{"display": "property_of_a"},
{"display": "func_of_a"},
{"display": "func_of_a()"},
{"display": "signal_of_a"},
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ scene="res://completion/get_node/get_node.tscn"
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},

; AnimationPlayer
{"display": "autoplay"},
{"display": "play"},
{"display": "play(…)"},
{"display": "animation_changed"},
]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},
]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ scene="res://completion/get_node/get_node.tscn"
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},

; GDScript: class_a.notest.gd
{"display": "property_of_a"},
{"display": "func_of_a"},
{"display": "func_of_a()"},
{"display": "signal_of_a"},
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ scene="res://completion/get_node/get_node.tscn"
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},

; AnimationPlayer
{"display": "autoplay"},
{"display": "play"},
{"display": "play(…)"},
{"display": "animation_changed"},
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ scene="res://completion/get_node/get_node.tscn"
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},

; GDScript: class_a.notest.gd
{"display": "property_of_a"},
{"display": "func_of_a"},
{"display": "func_of_a()"},
{"display": "signal_of_a"},
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ scene="res://completion/get_node/get_node.tscn"
[output]
include=[
; Node
{"display": "add_child"},
{"display": "add_child(…)"},
{"display": "owner"},
{"display": "child_entered_tree"},

; AnimationPlayer
{"display": "autoplay"},
{"display": "play"},
{"display": "play(…)"},
{"display": "animation_changed"},
]
Loading

0 comments on commit ae853e1

Please sign in to comment.