summaryrefslogtreecommitdiff
path: root/modules/gdscript/gdscript_editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript/gdscript_editor.cpp')
-rw-r--r--modules/gdscript/gdscript_editor.cpp327
1 files changed, 163 insertions, 164 deletions
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp
index 1bc1aae0d2..3a5db3687b 100644
--- a/modules/gdscript/gdscript_editor.cpp
+++ b/modules/gdscript/gdscript_editor.cpp
@@ -41,19 +41,16 @@
#endif
void GDScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const {
-
p_delimiters->push_back("#");
}
void GDScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const {
-
p_delimiters->push_back("\" \"");
p_delimiters->push_back("' '");
p_delimiters->push_back("\"\"\" \"\"\"");
}
String GDScriptLanguage::_get_processed_template(const String &p_template, const String &p_base_class_name) const {
-
String processed_template = p_template;
#ifdef TOOLS_ENABLED
@@ -109,18 +106,15 @@ Ref<Script> GDScriptLanguage::get_template(const String &p_class_name, const Str
}
bool GDScriptLanguage::is_using_templates() {
-
return true;
}
void GDScriptLanguage::make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) {
-
String _template = _get_processed_template(p_script->get_source_code(), p_base_class_name);
p_script->set_source_code(_template);
}
bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const {
-
GDScriptParser parser;
Error err = parser.parse(p_script, p_path.get_base_dir(), true, p_path, false, r_safe_lines);
@@ -143,35 +137,29 @@ bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int &
r_test_error = parser.get_error();
return false;
} else {
-
const GDScriptParser::Node *root = parser.get_parse_tree();
ERR_FAIL_COND_V(root->type != GDScriptParser::Node::TYPE_CLASS, false);
const GDScriptParser::ClassNode *cl = static_cast<const GDScriptParser::ClassNode *>(root);
Map<int, String> funcs;
for (int i = 0; i < cl->functions.size(); i++) {
-
funcs[cl->functions[i]->line] = cl->functions[i]->name;
}
for (int i = 0; i < cl->static_functions.size(); i++) {
-
funcs[cl->static_functions[i]->line] = cl->static_functions[i]->name;
}
for (int i = 0; i < cl->subclasses.size(); i++) {
for (int j = 0; j < cl->subclasses[i]->functions.size(); j++) {
-
funcs[cl->subclasses[i]->functions[j]->line] = String(cl->subclasses[i]->name) + "." + cl->subclasses[i]->functions[j]->name;
}
for (int j = 0; j < cl->subclasses[i]->static_functions.size(); j++) {
-
funcs[cl->subclasses[i]->static_functions[j]->line] = String(cl->subclasses[i]->name) + "." + cl->subclasses[i]->static_functions[j]->name;
}
}
for (Map<int, String>::Element *E = funcs.front(); E; E = E->next()) {
-
r_functions->push_back(E->get() + ":" + itos(E->key()));
}
}
@@ -180,27 +168,22 @@ bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int &
}
bool GDScriptLanguage::has_named_classes() const {
-
return false;
}
bool GDScriptLanguage::supports_builtin_mode() const {
-
return true;
}
int GDScriptLanguage::find_function(const String &p_function, const String &p_code) const {
-
GDScriptTokenizerText tokenizer;
tokenizer.set_code(p_code);
int indent = 0;
while (tokenizer.get_token() != GDScriptTokenizer::TK_EOF && tokenizer.get_token() != GDScriptTokenizer::TK_ERROR) {
-
if (tokenizer.get_token() == GDScriptTokenizer::TK_NEWLINE) {
indent = tokenizer.get_token_line_indent();
}
if (indent == 0 && tokenizer.get_token() == GDScriptTokenizer::TK_PR_FUNCTION && tokenizer.get_token(1) == GDScriptTokenizer::TK_IDENTIFIER) {
-
String identifier = tokenizer.get_token_identifier(1);
if (identifier == p_function) {
return tokenizer.get_token_line();
@@ -212,7 +195,6 @@ int GDScriptLanguage::find_function(const String &p_function, const String &p_co
}
Script *GDScriptLanguage::create_script() const {
-
return memnew(GDScript);
}
@@ -221,12 +203,11 @@ Script *GDScriptLanguage::create_script() const {
bool GDScriptLanguage::debug_break_parse(const String &p_file, int p_line, const String &p_error) {
//break because of parse error
- if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) {
-
+ if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) {
_debug_parse_err_line = p_line;
_debug_parse_err_file = p_file;
_debug_error = p_error;
- ScriptDebugger::get_singleton()->debug(this, false, true);
+ EngineDebugger::get_script_debugger()->debug(this, false, true);
return true;
} else {
return false;
@@ -234,14 +215,12 @@ bool GDScriptLanguage::debug_break_parse(const String &p_file, int p_line, const
}
bool GDScriptLanguage::debug_break(const String &p_error, bool p_allow_continue) {
-
- if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) {
-
+ if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) {
_debug_parse_err_line = -1;
_debug_parse_err_file = "";
_debug_error = p_error;
bool is_error_breakpoint = p_error != "Breakpoint";
- ScriptDebugger::get_singleton()->debug(this, p_allow_continue, is_error_breakpoint);
+ EngineDebugger::get_script_debugger()->debug(this, p_allow_continue, is_error_breakpoint);
return true;
} else {
return false;
@@ -249,21 +228,21 @@ bool GDScriptLanguage::debug_break(const String &p_error, bool p_allow_continue)
}
String GDScriptLanguage::debug_get_error() const {
-
return _debug_error;
}
int GDScriptLanguage::debug_get_stack_level_count() const {
-
- if (_debug_parse_err_line >= 0)
+ if (_debug_parse_err_line >= 0) {
return 1;
+ }
return _debug_call_stack_pos;
}
-int GDScriptLanguage::debug_get_stack_level_line(int p_level) const {
- if (_debug_parse_err_line >= 0)
+int GDScriptLanguage::debug_get_stack_level_line(int p_level) const {
+ if (_debug_parse_err_line >= 0) {
return _debug_parse_err_line;
+ }
ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, -1);
@@ -271,55 +250,59 @@ int GDScriptLanguage::debug_get_stack_level_line(int p_level) const {
return *(_call_stack[l].line);
}
-String GDScriptLanguage::debug_get_stack_level_function(int p_level) const {
- if (_debug_parse_err_line >= 0)
+String GDScriptLanguage::debug_get_stack_level_function(int p_level) const {
+ if (_debug_parse_err_line >= 0) {
return "";
+ }
ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, "");
int l = _debug_call_stack_pos - p_level - 1;
return _call_stack[l].function->get_name();
}
-String GDScriptLanguage::debug_get_stack_level_source(int p_level) const {
- if (_debug_parse_err_line >= 0)
+String GDScriptLanguage::debug_get_stack_level_source(int p_level) const {
+ if (_debug_parse_err_line >= 0) {
return _debug_parse_err_file;
+ }
ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, "");
int l = _debug_call_stack_pos - p_level - 1;
return _call_stack[l].function->get_source();
}
-void GDScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
- if (_debug_parse_err_line >= 0)
+void GDScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
+ if (_debug_parse_err_line >= 0) {
return;
+ }
ERR_FAIL_INDEX(p_level, _debug_call_stack_pos);
int l = _debug_call_stack_pos - p_level - 1;
GDScriptFunction *f = _call_stack[l].function;
- List<Pair<StringName, int> > locals;
+ List<Pair<StringName, int>> locals;
f->debug_get_stack_member_state(*_call_stack[l].line, &locals);
- for (List<Pair<StringName, int> >::Element *E = locals.front(); E; E = E->next()) {
-
+ for (List<Pair<StringName, int>>::Element *E = locals.front(); E; E = E->next()) {
p_locals->push_back(E->get().first);
p_values->push_back(_call_stack[l].stack[E->get().second]);
}
}
-void GDScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
- if (_debug_parse_err_line >= 0)
+void GDScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
+ if (_debug_parse_err_line >= 0) {
return;
+ }
ERR_FAIL_INDEX(p_level, _debug_call_stack_pos);
int l = _debug_call_stack_pos - p_level - 1;
GDScriptInstance *instance = _call_stack[l].instance;
- if (!instance)
+ if (!instance) {
return;
+ }
Ref<GDScript> script = instance->get_script();
ERR_FAIL_COND(script.is_null());
@@ -327,18 +310,17 @@ void GDScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *
const Map<StringName, GDScript::MemberInfo> &mi = script->debug_get_member_indices();
for (const Map<StringName, GDScript::MemberInfo>::Element *E = mi.front(); E; E = E->next()) {
-
p_members->push_back(E->key());
p_values->push_back(instance->debug_get_member_by_index(E->get().index));
}
}
ScriptInstance *GDScriptLanguage::debug_get_stack_level_instance(int p_level) {
+ if (_debug_parse_err_line >= 0) {
+ return nullptr;
+ }
- if (_debug_parse_err_line >= 0)
- return NULL;
-
- ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, NULL);
+ ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, nullptr);
int l = _debug_call_stack_pos - p_level - 1;
ScriptInstance *instance = _call_stack[l].instance;
@@ -347,32 +329,33 @@ ScriptInstance *GDScriptLanguage::debug_get_stack_level_instance(int p_level) {
}
void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
-
const Map<StringName, int> &name_idx = GDScriptLanguage::get_singleton()->get_global_map();
const Variant *globals = GDScriptLanguage::get_singleton()->get_global_array();
- List<Pair<String, Variant> > cinfo;
+ List<Pair<String, Variant>> cinfo;
get_public_constants(&cinfo);
for (const Map<StringName, int>::Element *E = name_idx.front(); E; E = E->next()) {
-
- if (ClassDB::class_exists(E->key()) || Engine::get_singleton()->has_singleton(E->key()))
+ if (ClassDB::class_exists(E->key()) || Engine::get_singleton()->has_singleton(E->key())) {
continue;
+ }
bool is_script_constant = false;
- for (List<Pair<String, Variant> >::Element *CE = cinfo.front(); CE; CE = CE->next()) {
+ for (List<Pair<String, Variant>>::Element *CE = cinfo.front(); CE; CE = CE->next()) {
if (CE->get().first == E->key()) {
is_script_constant = true;
break;
}
}
- if (is_script_constant)
+ if (is_script_constant) {
continue;
+ }
const Variant &var = globals[E->value()];
if (Object *obj = var) {
- if (Object::cast_to<GDScriptNativeClass>(obj))
+ if (Object::cast_to<GDScriptNativeClass>(obj)) {
continue;
+ }
}
bool skip = false;
@@ -382,8 +365,9 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant>
break;
}
}
- if (skip)
+ if (skip) {
continue;
+ }
p_globals->push_back(E->key());
p_values->push_back(var);
@@ -391,19 +375,15 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant>
}
String GDScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) {
-
return "";
}
void GDScriptLanguage::get_recognized_extensions(List<String> *p_extensions) const {
-
p_extensions->push_back("gd");
}
void GDScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const {
-
for (int i = 0; i < GDScriptFunctions::FUNC_MAX; i++) {
-
p_functions->push_back(GDScriptFunctions::get_info(GDScriptFunctions::Function(i)));
}
@@ -430,12 +410,13 @@ void GDScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const
mi.name = "assert";
mi.return_val.type = Variant::NIL;
mi.arguments.push_back(PropertyInfo(Variant::BOOL, "condition"));
+ mi.arguments.push_back(PropertyInfo(Variant::STRING, "message"));
+ mi.default_arguments.push_back(String());
p_functions->push_back(mi);
}
}
-void GDScriptLanguage::get_public_constants(List<Pair<String, Variant> > *p_constants) const {
-
+void GDScriptLanguage::get_public_constants(List<Pair<String, Variant>> *p_constants) const {
Pair<String, Variant> pi;
pi.first = "PI";
pi.second = Math_PI;
@@ -458,7 +439,6 @@ void GDScriptLanguage::get_public_constants(List<Pair<String, Variant> > *p_cons
}
String GDScriptLanguage::make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const {
-
#ifdef TOOLS_ENABLED
bool th = EditorSettings::get_singleton()->get_setting("text_editor/completion/add_type_hints");
#else
@@ -468,8 +448,9 @@ String GDScriptLanguage::make_function(const String &p_class, const String &p_na
String s = "func " + p_name + "(";
if (p_args.size()) {
for (int i = 0; i < p_args.size(); i++) {
- if (i > 0)
+ if (i > 0) {
s += ", ";
+ }
s += p_args[i].get_slice(":", 0);
if (th) {
String type = p_args[i].get_slice(":", 1);
@@ -489,36 +470,27 @@ String GDScriptLanguage::make_function(const String &p_class, const String &p_na
#if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED)
struct GDScriptCompletionContext {
-
- const GDScriptParser::ClassNode *_class;
- const GDScriptParser::FunctionNode *function;
- const GDScriptParser::BlockNode *block;
- Object *base;
+ const GDScriptParser::ClassNode *_class = nullptr;
+ const GDScriptParser::FunctionNode *function = nullptr;
+ const GDScriptParser::BlockNode *block = nullptr;
+ Object *base = nullptr;
String base_path;
- int line;
- uint32_t depth;
-
- GDScriptCompletionContext() :
- _class(NULL),
- function(NULL),
- block(NULL),
- base(NULL),
- line(0),
- depth(0) {}
+ int line = 0;
+ uint32_t depth = 0;
+
+ GDScriptCompletionContext() {}
};
struct GDScriptCompletionIdentifier {
GDScriptParser::DataType type;
String enumeration;
Variant value;
- const GDScriptParser::Node *assigned_expression;
+ const GDScriptParser::Node *assigned_expression = nullptr;
- GDScriptCompletionIdentifier() :
- assigned_expression(NULL) {}
+ GDScriptCompletionIdentifier() {}
};
static void _get_directory_contents(EditorFileSystemDirectory *p_dir, Map<String, ScriptCodeCompletionOption> &r_list) {
-
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\"";
for (int i = 0; i < p_dir->get_file_count(); i++) {
@@ -533,7 +505,6 @@ static void _get_directory_contents(EditorFileSystemDirectory *p_dir, Map<String
}
static String _get_visual_datatype(const PropertyInfo &p_info, bool p_isarg = true) {
-
if (p_info.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
String enum_name = p_info.class_name;
if (enum_name.find(".") == -1) {
@@ -833,7 +804,6 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G
Object *baseptr = base.value;
if (all_is_const && String(id) == "get_node" && ClassDB::is_parent_class(native_type.native_type, "Node") && args.size()) {
-
String arg1 = args[0];
if (arg1.begins_with("/root/")) {
String which = arg1.get_slice("/", 2);
@@ -847,7 +817,6 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G
ProjectSettings::get_singleton()->get_property_list(&props);
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
-
String s = E->get().name;
if (!s.begins_with("autoload/")) {
continue;
@@ -909,7 +878,7 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G
Variant ret = mb->call(baseptr, (const Variant **)argptr.ptr(), argptr.size(), ce);
if (ce.error == Callable::CallError::CALL_OK && ret.get_type() != Variant::NIL) {
- if (ret.get_type() != Variant::OBJECT || ret.operator Object *() != NULL) {
+ if (ret.get_type() != Variant::OBJECT || ret.operator Object *() != nullptr) {
r_type = _type_from_variant(ret);
found = true;
}
@@ -963,7 +932,7 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G
break;
}
- const GDScriptParser::DictionaryNode *dn = NULL;
+ const GDScriptParser::DictionaryNode *dn = nullptr;
if (op->arguments[0]->type == GDScriptParser::Node::TYPE_DICTIONARY) {
dn = static_cast<const GDScriptParser::DictionaryNode *>(op->arguments[0]);
} else if (base.assigned_expression && base.assigned_expression->type == GDScriptParser::Node::TYPE_DICTIONARY) {
@@ -1017,7 +986,7 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G
}
// Look if it is a dictionary node
- const GDScriptParser::DictionaryNode *dn = NULL;
+ const GDScriptParser::DictionaryNode *dn = nullptr;
if (op->arguments[0]->type == GDScriptParser::Node::TYPE_DICTIONARY) {
dn = static_cast<const GDScriptParser::DictionaryNode *>(op->arguments[0]);
} else if (base.assigned_expression && base.assigned_expression->type == GDScriptParser::Node::TYPE_DICTIONARY) {
@@ -1041,7 +1010,7 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G
// Look if it is an array node
if (!found && index.value.is_num()) {
int idx = index.value;
- const GDScriptParser::ArrayNode *an = NULL;
+ const GDScriptParser::ArrayNode *an = nullptr;
if (op->arguments[0]->type == GDScriptParser::Node::TYPE_ARRAY) {
an = static_cast<const GDScriptParser::ArrayNode *>(op->arguments[0]);
} else if (base.assigned_expression && base.assigned_expression->type == GDScriptParser::Node::TYPE_ARRAY) {
@@ -1061,7 +1030,7 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G
found = _guess_identifier_type_from_base(c, base, id, r_type);
} else if (!found && index.type.kind == GDScriptParser::DataType::BUILTIN) {
Callable::CallError err;
- Variant base_val = Variant::construct(base.type.builtin_type, NULL, 0, err);
+ Variant base_val = Variant::construct(base.type.builtin_type, nullptr, 0, err);
bool valid = false;
Variant res = base_val.get(index.value, &valid);
if (valid) {
@@ -1080,16 +1049,36 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G
Variant::Operator vop = Variant::OP_MAX;
switch (op->op) {
- case GDScriptParser::OperatorNode::OP_ADD: vop = Variant::OP_ADD; break;
- case GDScriptParser::OperatorNode::OP_SUB: vop = Variant::OP_SUBTRACT; break;
- case GDScriptParser::OperatorNode::OP_MUL: vop = Variant::OP_MULTIPLY; break;
- case GDScriptParser::OperatorNode::OP_DIV: vop = Variant::OP_DIVIDE; break;
- case GDScriptParser::OperatorNode::OP_MOD: vop = Variant::OP_MODULE; break;
- case GDScriptParser::OperatorNode::OP_SHIFT_LEFT: vop = Variant::OP_SHIFT_LEFT; break;
- case GDScriptParser::OperatorNode::OP_SHIFT_RIGHT: vop = Variant::OP_SHIFT_RIGHT; break;
- case GDScriptParser::OperatorNode::OP_BIT_AND: vop = Variant::OP_BIT_AND; break;
- case GDScriptParser::OperatorNode::OP_BIT_OR: vop = Variant::OP_BIT_OR; break;
- case GDScriptParser::OperatorNode::OP_BIT_XOR: vop = Variant::OP_BIT_XOR; break;
+ case GDScriptParser::OperatorNode::OP_ADD:
+ vop = Variant::OP_ADD;
+ break;
+ case GDScriptParser::OperatorNode::OP_SUB:
+ vop = Variant::OP_SUBTRACT;
+ break;
+ case GDScriptParser::OperatorNode::OP_MUL:
+ vop = Variant::OP_MULTIPLY;
+ break;
+ case GDScriptParser::OperatorNode::OP_DIV:
+ vop = Variant::OP_DIVIDE;
+ break;
+ case GDScriptParser::OperatorNode::OP_MOD:
+ vop = Variant::OP_MODULE;
+ break;
+ case GDScriptParser::OperatorNode::OP_SHIFT_LEFT:
+ vop = Variant::OP_SHIFT_LEFT;
+ break;
+ case GDScriptParser::OperatorNode::OP_SHIFT_RIGHT:
+ vop = Variant::OP_SHIFT_RIGHT;
+ break;
+ case GDScriptParser::OperatorNode::OP_BIT_AND:
+ vop = Variant::OP_BIT_AND;
+ break;
+ case GDScriptParser::OperatorNode::OP_BIT_OR:
+ vop = Variant::OP_BIT_OR;
+ break;
+ case GDScriptParser::OperatorNode::OP_BIT_XOR:
+ vop = Variant::OP_BIT_XOR;
+ break;
default: {
}
}
@@ -1116,9 +1105,9 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G
Callable::CallError ce;
bool v1_use_value = p1.value.get_type() != Variant::NIL && p1.value.get_type() != Variant::OBJECT;
- Variant v1 = (v1_use_value) ? p1.value : Variant::construct(p1.type.builtin_type, NULL, 0, ce);
+ Variant v1 = (v1_use_value) ? p1.value : Variant::construct(p1.type.builtin_type, nullptr, 0, ce);
bool v2_use_value = p2.value.get_type() != Variant::NIL && p2.value.get_type() != Variant::OBJECT;
- Variant v2 = (v2_use_value) ? p2.value : Variant::construct(p2.type.builtin_type, NULL, 0, ce);
+ Variant v2 = (v2_use_value) ? p2.value : Variant::construct(p2.type.builtin_type, nullptr, 0, ce);
// avoid potential invalid ops
if ((vop == Variant::OP_DIVIDE || vop == Variant::OP_MODULE) && v2.get_type() == Variant::INT) {
v2 = 1;
@@ -1169,11 +1158,10 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G
}
static bool _guess_identifier_type(GDScriptCompletionContext &p_context, const StringName &p_identifier, GDScriptCompletionIdentifier &r_type) {
-
// Look in blocks first
const GDScriptParser::BlockNode *blk = p_context.block;
int last_assign_line = -1;
- const GDScriptParser::Node *last_assigned_expression = NULL;
+ const GDScriptParser::Node *last_assigned_expression = nullptr;
GDScriptParser::DataType var_type;
while (blk) {
if (blk->variables.has(p_identifier)) {
@@ -1227,7 +1215,7 @@ static bool _guess_identifier_type(GDScriptCompletionContext &p_context, const S
r_type.type.is_meta_type = false; // Right-hand of `is` will be a meta type, but the left-hand value is not
// Not an assignment, it shouldn't carry any value
r_type.value = Variant();
- r_type.assigned_expression = NULL;
+ r_type.assigned_expression = nullptr;
return true;
}
@@ -1271,8 +1259,8 @@ static bool _guess_identifier_type(GDScriptCompletionContext &p_context, const S
return false;
}
GDScriptCompletionContext c = p_context;
- c.function = NULL;
- c.block = NULL;
+ c.function = nullptr;
+ c.block = nullptr;
return _guess_expression_type(c, op->arguments[1], r_type);
}
}
@@ -1425,6 +1413,7 @@ static bool _guess_identifier_type_from_base(GDScriptCompletionContext &p_contex
// Variable used in the same expression
return false;
}
+
if (_guess_expression_type(p_context, m.expression, r_type)) {
return true;
}
@@ -1534,7 +1523,7 @@ static bool _guess_identifier_type_from_base(GDScriptCompletionContext &p_contex
} break;
case GDScriptParser::DataType::BUILTIN: {
Callable::CallError err;
- Variant tmp = Variant::construct(base_type.builtin_type, NULL, 0, err);
+ Variant tmp = Variant::construct(base_type.builtin_type, nullptr, 0, err);
if (err.error != Callable::CallError::CALL_OK) {
return false;
@@ -1612,7 +1601,7 @@ static bool _guess_method_return_type_from_base(GDScriptCompletionContext &p_con
for (int i = 0; i < base_type.class_type->static_functions.size(); i++) {
if (base_type.class_type->static_functions[i]->name == p_method) {
int last_return_line = -1;
- const GDScriptParser::Node *last_returned_value = NULL;
+ const GDScriptParser::Node *last_returned_value = nullptr;
GDScriptCompletionContext c = p_context;
c._class = base_type.class_type;
c.function = base_type.class_type->static_functions[i];
@@ -1629,7 +1618,7 @@ static bool _guess_method_return_type_from_base(GDScriptCompletionContext &p_con
for (int i = 0; i < base_type.class_type->functions.size(); i++) {
if (base_type.class_type->functions[i]->name == p_method) {
int last_return_line = -1;
- const GDScriptParser::Node *last_returned_value = NULL;
+ const GDScriptParser::Node *last_returned_value = nullptr;
GDScriptCompletionContext c = p_context;
c._class = base_type.class_type;
c.function = base_type.class_type->functions[i];
@@ -1704,7 +1693,7 @@ static bool _guess_method_return_type_from_base(GDScriptCompletionContext &p_con
} break;
case GDScriptParser::DataType::BUILTIN: {
Callable::CallError err;
- Variant tmp = Variant::construct(base_type.builtin_type, NULL, 0, err);
+ Variant tmp = Variant::construct(base_type.builtin_type, nullptr, 0, err);
if (err.error != Callable::CallError::CALL_OK) {
return false;
}
@@ -1730,7 +1719,6 @@ static bool _guess_method_return_type_from_base(GDScriptCompletionContext &p_con
}
static String _make_arguments_hint(const MethodInfo &p_info, int p_arg_idx) {
-
String arghint = _get_visual_datatype(p_info.return_val, false) + " " + p_info.name + "(";
int def_args = p_info.arguments.size() - p_info.default_arguments.size();
@@ -1775,7 +1763,6 @@ static String _make_arguments_hint(const MethodInfo &p_info, int p_arg_idx) {
}
static String _make_arguments_hint(const GDScriptParser::FunctionNode *p_function, int p_arg_idx) {
-
String arghint = p_function->return_type.to_string() + " " + p_function->name.operator String() + "(";
int def_args = p_function->arguments.size() - p_function->default_values.size();
@@ -1817,7 +1804,6 @@ static String _make_arguments_hint(const GDScriptParser::FunctionNode *p_functio
}
static void _find_enumeration_candidates(const String p_enum_hint, Map<String, ScriptCodeCompletionOption> &r_result) {
-
if (p_enum_hint.find(".") == -1) {
// Global constant
StringName current_enum = p_enum_hint;
@@ -1911,8 +1897,8 @@ static void _find_identifiers_in_class(const GDScriptCompletionContext &p_contex
base_type.value = p_context.base;
GDScriptCompletionContext c = p_context;
- c.block = NULL;
- c.function = NULL;
+ c.block = nullptr;
+ c.function = nullptr;
_find_identifiers_in_base(c, base_type, p_only_functions, r_result);
}
@@ -1932,8 +1918,8 @@ static void _find_identifiers_in_base(const GDScriptCompletionContext &p_context
case GDScriptParser::DataType::CLASS: {
GDScriptCompletionContext c = p_context;
c._class = base_type.class_type;
- c.block = NULL;
- c.function = NULL;
+ c.block = nullptr;
+ c.function = nullptr;
_find_identifiers_in_class(c, _static, p_only_functions, false, r_result);
base_type = base_type.class_type->base_type;
} break;
@@ -1972,7 +1958,7 @@ static void _find_identifiers_in_base(const GDScriptCompletionContext &p_context
}
}
if (!p_only_functions) {
- for (const Map<StringName, Ref<GDScript> >::Element *E = script->get_subclasses().front(); E; E = E->next()) {
+ for (const Map<StringName, Ref<GDScript>>::Element *E = script->get_subclasses().front(); E; E = E->next()) {
ScriptCodeCompletionOption option(E->key().operator String(), ScriptCodeCompletionOption::KIND_CLASS);
r_result.insert(option.display, option);
}
@@ -2055,7 +2041,7 @@ static void _find_identifiers_in_base(const GDScriptCompletionContext &p_context
List<PropertyInfo> pinfo;
ClassDB::get_property_list(type, &pinfo);
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (E->get().usage & (PROPERTY_USAGE_GROUP | PROPERTY_USAGE_CATEGORY)) {
+ if (E->get().usage & (PROPERTY_USAGE_GROUP | PROPERTY_USAGE_SUBGROUP | PROPERTY_USAGE_CATEGORY)) {
continue;
}
if (E->get().name.find("/") != -1) {
@@ -2089,14 +2075,18 @@ static void _find_identifiers_in_base(const GDScriptCompletionContext &p_context
} break;
case GDScriptParser::DataType::BUILTIN: {
Callable::CallError err;
- Variant tmp = Variant::construct(base_type.builtin_type, NULL, 0, err);
+ Variant tmp = Variant::construct(base_type.builtin_type, nullptr, 0, err);
if (err.error != Callable::CallError::CALL_OK) {
return;
}
if (!p_only_functions) {
List<PropertyInfo> members;
- p_base.value.get_property_list(&members);
+ if (p_base.value.get_type() != Variant::NIL) {
+ p_base.value.get_property_list(&members);
+ } else {
+ tmp.get_property_list(&members);
+ }
for (List<PropertyInfo>::Element *E = members.front(); E; E = E->next()) {
if (String(E->get().name).find("/") == -1) {
@@ -2128,11 +2118,9 @@ static void _find_identifiers_in_base(const GDScriptCompletionContext &p_context
}
static void _find_identifiers(const GDScriptCompletionContext &p_context, bool p_only_functions, Map<String, ScriptCodeCompletionOption> &r_result) {
-
const GDScriptParser::BlockNode *block = p_context.block;
if (p_context.function) {
-
const GDScriptParser::FunctionNode *f = p_context.function;
for (int i = 0; i < f->arguments.size(); i++) {
@@ -2148,13 +2136,13 @@ static void _find_identifiers(const GDScriptCompletionContext &p_context, bool p
}
const GDScriptParser::ClassNode *clss = p_context._class;
- bool _static = !p_context.function || p_context.function->_static;
+ bool _static = p_context.function && p_context.function->_static;
while (clss) {
GDScriptCompletionContext c = p_context;
c._class = clss;
- c.block = NULL;
- c.function = NULL;
+ c.block = nullptr;
+ c.function = nullptr;
_find_identifiers_in_class(c, _static, p_only_functions, false, r_result);
_static = true;
clss = clss->owner;
@@ -2188,7 +2176,7 @@ static void _find_identifiers(const GDScriptCompletionContext &p_context, bool p
"const", "enum", "export", "onready", "static", "var", "break", "continue", "if", "elif",
"else", "for", "pass", "return", "match", "while", "remote", "master", "puppet",
"remotesync", "mastersync", "puppetsync",
- 0
+ nullptr
};
const char **kw = _keywords;
@@ -2234,6 +2222,8 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\"";
+#define IS_METHOD_SIGNAL(m_method) (m_method == "connect" || m_method == "disconnect" || m_method == "is_connected" || m_method == "emit_signal")
+
while (base_type.has_type) {
switch (base_type.kind) {
case GDScriptParser::DataType::CLASS: {
@@ -2250,7 +2240,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con
}
}
- if ((p_method == "connect" || p_method == "emit_signal") && p_argidx == 0) {
+ if (IS_METHOD_SIGNAL(p_method) && p_argidx == 0) {
for (int i = 0; i < base_type.class_type->_signals.size(); i++) {
ScriptCodeCompletionOption option(base_type.class_type->_signals[i].name.operator String(), ScriptCodeCompletionOption::KIND_SIGNAL);
option.insert_text = quote_style + option.display + quote_style;
@@ -2263,7 +2253,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con
case GDScriptParser::DataType::GDSCRIPT: {
Ref<GDScript> gds = base_type.script_type;
if (gds.is_valid()) {
- if ((p_method == "connect" || p_method == "emit_signal") && p_argidx == 0) {
+ if (IS_METHOD_SIGNAL(p_method) && p_argidx == 0) {
List<MethodInfo> signals;
gds->get_script_signal_list(&signals);
for (List<MethodInfo>::Element *E = signals.front(); E; E = E->next()) {
@@ -2325,7 +2315,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con
}
}
- if ((p_method == "connect" || p_method == "emit_signal") && p_argidx == 0) {
+ if (IS_METHOD_SIGNAL(p_method) && p_argidx == 0) {
List<MethodInfo> signals;
ClassDB::get_signal_list(class_name, &signals);
for (List<MethodInfo>::Element *E = signals.front(); E; E = E->next()) {
@@ -2334,6 +2324,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con
r_result.insert(option.display, option);
}
}
+#undef IS_METHOD_SIGNAL
if (ClassDB::is_parent_class(class_name, "Node") && (p_method == "get_node" || p_method == "has_node") && p_argidx == 0) {
// Get autoloads
@@ -2373,7 +2364,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con
case GDScriptParser::DataType::BUILTIN: {
if (base.get_type() == Variant::NIL) {
Callable::CallError err;
- base = Variant::construct(base_type.builtin_type, NULL, 0, err);
+ base = Variant::construct(base_type.builtin_type, nullptr, 0, err);
if (err.error != Callable::CallError::CALL_OK) {
return;
}
@@ -2398,7 +2389,6 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con
}
static void _find_call_arguments(GDScriptCompletionContext &p_context, const GDScriptParser::Node *p_node, int p_argidx, Map<String, ScriptCodeCompletionOption> &r_result, bool &r_forced, String &r_arghint) {
-
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\"";
if (!p_node || p_node->type != GDScriptParser::Node::TYPE_OPERATOR) {
@@ -2454,7 +2444,6 @@ static void _find_call_arguments(GDScriptCompletionContext &p_context, const GDS
}
return;
} else if (op->arguments[0]->type == GDScriptParser::Node::TYPE_SELF) {
-
if (op->arguments.size() < 2 || op->arguments[1]->type != GDScriptParser::Node::TYPE_IDENTIFIER) {
return;
}
@@ -2528,7 +2517,6 @@ static void _find_call_arguments(GDScriptCompletionContext &p_context, const GDS
}
Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptCodeCompletionOption> *r_options, bool &r_forced, String &r_call_hint) {
-
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\"";
GDScriptParser parser;
@@ -2542,7 +2530,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path
context.function = parser.get_completion_function();
context.line = parser.get_completion_line();
- if (!context._class || context._class->owner == NULL) {
+ if (!context._class || context._class->owner == nullptr) {
context.base = p_owner;
context.base_path = p_path.get_base_dir();
}
@@ -2576,7 +2564,6 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path
p_owner->get_argument_options("get_node", 0, &opts);
for (List<String>::Element *E = opts.front(); E; E = E->next()) {
-
String opt = E->get().strip_edges();
if (opt.is_quoted()) {
r_forced = true;
@@ -2626,13 +2613,13 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path
}
GDScriptCompletionContext c = context;
- c.function = NULL;
- c.block = NULL;
- c.base = base.value.get_type() == Variant::OBJECT ? base.value.operator Object *() : NULL;
+ c.function = nullptr;
+ c.block = nullptr;
+ c.base = base.value.get_type() == Variant::OBJECT ? base.value.operator Object *() : nullptr;
if (base.type.kind == GDScriptParser::DataType::CLASS) {
c._class = base.type.class_type;
} else {
- c._class = NULL;
+ c._class = nullptr;
}
_find_identifiers_in_base(c, base, is_function, options);
@@ -2684,7 +2671,6 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path
List<MethodInfo> virtual_methods;
ClassDB::get_virtual_methods(class_name, &virtual_methods);
for (List<MethodInfo>::Element *E = virtual_methods.front(); E; E = E->next()) {
-
MethodInfo &mi = E->get();
String method_hint = mi.name;
if (method_hint.find(":") != -1) {
@@ -2818,8 +2804,8 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path
for (Map<StringName, GDScriptParser::ClassNode::Constant>::Element *E = clss->constant_expressions.front(); E; E = E->next()) {
GDScriptCompletionIdentifier constant;
GDScriptCompletionContext c = context;
- c.function = NULL;
- c.block = NULL;
+ c.function = nullptr;
+ c.block = nullptr;
c.line = E->value().expression->line;
if (_guess_expression_type(c, E->value().expression, constant)) {
if (constant.type.has_type && constant.type.is_meta_type) {
@@ -2887,9 +2873,9 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path
}
GDScriptCompletionContext c = context;
- c._class = NULL;
- c.function = NULL;
- c.block = NULL;
+ c._class = nullptr;
+ c.function = nullptr;
+ c.block = nullptr;
bool finding = true;
index = index.right(index.find(".") + 1);
while (index.find(".") != -1) {
@@ -2917,8 +2903,8 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path
GDScriptCompletionIdentifier constant;
GDScriptCompletionContext c2 = context;
c2._class = base_type.class_type;
- c2.function = NULL;
- c2.block = NULL;
+ c2.function = nullptr;
+ c2.block = nullptr;
c2.line = E->value().expression->line;
if (_guess_expression_type(c2, E->value().expression, constant)) {
if (constant.type.has_type && constant.type.is_meta_type) {
@@ -3008,19 +2994,16 @@ String GDScriptLanguage::_get_indentation() const {
}
void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const {
-
String indent = _get_indentation();
Vector<String> lines = p_code.split("\n");
List<int> indent_stack;
for (int i = 0; i < lines.size(); i++) {
-
String l = lines[i];
int tc = 0;
for (int j = 0; j < l.length(); j++) {
if (l[j] == ' ' || l[j] == '\t') {
-
tc++;
} else {
break;
@@ -3028,8 +3011,9 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t
}
String st = l.substr(tc, l.length()).strip_edges();
- if (st == "" || st.begins_with("#"))
+ if (st == "" || st.begins_with("#")) {
continue; //ignore!
+ }
int ilevel = 0;
if (indent_stack.size()) {
@@ -3043,12 +3027,12 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t
indent_stack.pop_back();
}
- if (indent_stack.size() && indent_stack.back()->get() != tc)
+ if (indent_stack.size() && indent_stack.back()->get() != tc) {
indent_stack.push_back(tc); //this is not right but gets the job done
+ }
}
if (i >= p_from_line) {
-
l = "";
for (int j = 0; j < indent_stack.size(); j++) {
l += indent;
@@ -3064,8 +3048,9 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t
p_code = "";
for (int i = 0; i < lines.size(); i++) {
- if (i > 0)
+ if (i > 0) {
p_code += "\n";
+ }
p_code += lines[i];
}
}
@@ -3108,6 +3093,14 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co
return OK;
}
}
+
+ for (int i = 0; i < base_type.class_type->subclasses.size(); i++) {
+ if (base_type.class_type->subclasses[i]->name == p_symbol) {
+ r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
+ r_result.location = base_type.class_type->subclasses[i]->line;
+ return OK;
+ }
+ }
}
base_type = base_type.class_type->base_type;
}
@@ -3220,7 +3213,7 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co
v = v_ref;
} else {
Callable::CallError err;
- v = Variant::construct(base_type.builtin_type, NULL, 0, err);
+ v = Variant::construct(base_type.builtin_type, nullptr, 0, err);
if (err.error != Callable::CallError::CALL_OK) {
break;
}
@@ -3252,7 +3245,6 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co
}
Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) {
-
//before parsing, try the usual stuff
if (ClassDB::class_exists(p_symbol)) {
r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS;
@@ -3333,7 +3325,6 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol
[[fallthrough]];
}
case GDScriptParser::COMPLETION_IDENTIFIER: {
-
if (!is_function) {
is_function = parser.get_completion_identifier_is_function();
}
@@ -3385,13 +3376,12 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol
ProjectSettings::get_singleton()->get_property_list(&props);
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
-
String s = E->get().name;
- if (!s.begins_with("autoload/"))
+ if (!s.begins_with("autoload/")) {
continue;
+ }
String name = s.get_slice("/", 1);
if (name == String(p_symbol)) {
-
String path = ProjectSettings::get_singleton()->get(s);
if (path.begins_with("*")) {
String script = path.substr(1, path.length());
@@ -3403,7 +3393,6 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol
}
if (FileAccess::exists(script)) {
-
r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION;
r_result.location = 0;
r_result.script = ResourceLoader::load(script);
@@ -3440,7 +3429,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol
// We cannot determine the exact nature of the identifier here
// Otherwise these codes would work
StringName enumName = ClassDB::get_integer_constant_enum("@GlobalScope", p_symbol, true);
- if (enumName != NULL) {
+ if (enumName != nullptr) {
r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_ENUM;
r_result.class_name = "@GlobalScope";
r_result.class_member = enumName;
@@ -3485,6 +3474,16 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol
return OK;
}
} break;
+ case GDScriptParser::COMPLETION_TYPE_HINT: {
+ GDScriptParser::DataType base_type = context._class->base_type;
+ base_type.has_type = true;
+ base_type.kind = GDScriptParser::DataType::CLASS;
+ base_type.class_type = const_cast<GDScriptParser::ClassNode *>(context._class);
+
+ if (_lookup_symbol_from_base(base_type, p_symbol, false, r_result) == OK) {
+ return OK;
+ }
+ } break;
default: {
}
}