diff options
Diffstat (limited to 'modules/gdscript/gdscript_editor.cpp')
-rw-r--r-- | modules/gdscript/gdscript_editor.cpp | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 5e626f0520..724715d9e5 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -54,11 +54,16 @@ void GDScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const p_delimiters->push_back("#"); } +void GDScriptLanguage::get_doc_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("\"\"\" \"\"\""); p_delimiters->push_back("''' '''"); + // NOTE: StringName, NodePath and r-strings are not listed here. } bool GDScriptLanguage::is_using_templates() { @@ -75,19 +80,25 @@ Ref<Script> GDScriptLanguage::make_template(const String &p_template, const Stri #endif if (!type_hints) { processed_template = processed_template.replace(": int", "") + .replace(": Shader.Mode", "") + .replace(": VisualShader.Type", "") + .replace(": float", "") .replace(": String", "") .replace(": Array[String]", "") - .replace(": float", "") + .replace(": Node", "") .replace(": CharFXTransform", "") .replace(":=", "=") - .replace(" -> String", "") - .replace(" -> int", "") + .replace(" -> void", "") .replace(" -> bool", "") - .replace(" -> void", ""); + .replace(" -> int", "") + .replace(" -> PortType", "") + .replace(" -> String", "") + .replace(" -> Object", ""); } processed_template = processed_template.replace("_BASE_", p_base_class_name) - .replace("_CLASS_", p_class_name.to_pascal_case()) + .replace("_CLASS_SNAKE_CASE_", p_class_name.to_snake_case().validate_identifier()) + .replace("_CLASS_", p_class_name.to_pascal_case().validate_identifier()) .replace("_TS_", _get_indentation()); scr->set_source_code(processed_template); return scr; @@ -190,10 +201,6 @@ bool GDScriptLanguage::validate(const String &p_script, const String &p_path, Li return true; } -bool GDScriptLanguage::has_named_classes() const { - return false; -} - bool GDScriptLanguage::supports_builtin_mode() const { return true; } @@ -500,7 +507,7 @@ String GDScriptLanguage::make_function(const String &p_class, const String &p_na s += p_args[i].get_slice(":", 0); if (th) { String type = p_args[i].get_slice(":", 1); - if (!type.is_empty() && type != "var") { + if (!type.is_empty()) { s += ": " + type; } } @@ -977,7 +984,7 @@ static void _find_identifiers_in_class(const GDScriptParser::ClassNode *p_class, ScriptLanguage::CodeCompletionOption option; switch (member.type) { case GDScriptParser::ClassNode::Member::VARIABLE: - if (p_only_functions || outer || (p_static)) { + if (p_only_functions || outer || (p_static && !member.variable->is_static)) { continue; } option = ScriptLanguage::CodeCompletionOption(member.variable->identifier->name, ScriptLanguage::CODE_COMPLETION_KIND_MEMBER, location); @@ -1119,6 +1126,7 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base base_type.script_type = base_script; } else { base_type.kind = GDScriptParser::DataType::NATIVE; + base_type.builtin_type = Variant::OBJECT; base_type.native_type = scr->get_instance_base_type(); } } else { @@ -1285,7 +1293,7 @@ static void _find_identifiers(const GDScriptParser::CompletionContext &p_context static const char *_keywords_with_space[] = { "and", "not", "or", "in", "as", "class", "class_name", "extends", "is", "func", "signal", "await", - "const", "enum", "static", "var", "if", "elif", "else", "for", "match", "while", + "const", "enum", "static", "var", "if", "elif", "else", "for", "match", "when", "while", nullptr }; @@ -1623,6 +1631,7 @@ static bool _guess_expression_type(GDScriptParser::CompletionContext &p_context, native_type.script_type = parent; } else { native_type.kind = GDScriptParser::DataType::NATIVE; + native_type.builtin_type = Variant::OBJECT; native_type.native_type = native_type.script_type->get_instance_base_type(); if (!ClassDB::class_exists(native_type.native_type)) { native_type.kind = GDScriptParser::DataType::UNRESOLVED; @@ -2152,6 +2161,7 @@ static bool _guess_identifier_type(GDScriptParser::CompletionContext &p_context, if (ClassDB::class_exists(p_identifier->name) && ClassDB::is_class_exposed(p_identifier->name)) { r_type.type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT; r_type.type.kind = GDScriptParser::DataType::NATIVE; + r_type.type.builtin_type = Variant::OBJECT; r_type.type.native_type = p_identifier->name; r_type.type.is_constant = true; if (Engine::get_singleton()->has_singleton(p_identifier->name)) { @@ -2188,7 +2198,7 @@ static bool _guess_identifier_type_from_base(GDScriptParser::CompletionContext & } return true; case GDScriptParser::ClassNode::Member::VARIABLE: - if (!is_static) { + if (!is_static || member.variable->is_static) { if (member.variable->get_datatype().is_set() && !member.variable->get_datatype().is_variant()) { r_type.type = member.variable->get_datatype(); return true; @@ -2263,21 +2273,25 @@ static bool _guess_identifier_type_from_base(GDScriptParser::CompletionContext & return true; } - if (!is_static) { - List<PropertyInfo> members; + List<PropertyInfo> members; + if (is_static) { + scr->get_property_list(&members); + } else { scr->get_script_property_list(&members); - for (const PropertyInfo &prop : members) { - if (prop.name == p_identifier) { - r_type = _type_from_property(prop); - return true; - } + } + for (const PropertyInfo &prop : members) { + if (prop.name == p_identifier) { + r_type = _type_from_property(prop); + return true; } } + Ref<Script> parent = scr->get_base_script(); if (parent.is_valid()) { base_type.script_type = parent; } else { base_type.kind = GDScriptParser::DataType::NATIVE; + base_type.builtin_type = Variant::OBJECT; base_type.native_type = scr->get_instance_base_type(); } } else { @@ -2447,6 +2461,7 @@ static bool _guess_method_return_type_from_base(GDScriptParser::CompletionContex base_type.script_type = base_script; } else { base_type.kind = GDScriptParser::DataType::NATIVE; + base_type.builtin_type = Variant::OBJECT; base_type.native_type = scr->get_instance_base_type(); } } else { @@ -2702,8 +2717,8 @@ static bool _get_subscript_type(GDScriptParser::CompletionContext &p_context, co } r_base_type.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT; r_base_type.kind = GDScriptParser::DataType::NATIVE; - r_base_type.native_type = node->get_class_name(); r_base_type.builtin_type = Variant::OBJECT; + r_base_type.native_type = node->get_class_name(); return true; } } @@ -3257,6 +3272,7 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co base_type.script_type = base_script; } else { base_type.kind = GDScriptParser::DataType::NATIVE; + base_type.builtin_type = Variant::OBJECT; base_type.native_type = scr->get_instance_base_type(); } } else { @@ -3393,6 +3409,12 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co } } + if ("Variant" == p_symbol) { + r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS; + r_result.class_name = "Variant"; + return OK; + } + if ("PI" == p_symbol || "TAU" == p_symbol || "INF" == p_symbol || "NAN" == p_symbol) { r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS_CONSTANT; r_result.class_name = "@GDScript"; |