From cd918ff4702a7cf643fb6c8a85f8bd443b447aae Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Thu, 9 Jan 2025 21:07:41 +0300 Subject: [PATCH] GDScript: Remove `RENAMED_IN_GODOT_4_HINT` from `GDScriptWarning::Code` enum --- doc/classes/ProjectSettings.xml | 2 +- editor/plugins/script_text_editor.cpp | 2 +- modules/gdscript/gdscript.cpp | 1 + modules/gdscript/gdscript_analyzer.cpp | 8 ++++---- modules/gdscript/gdscript_editor.cpp | 6 ++++-- modules/gdscript/gdscript_parser.cpp | 2 +- modules/gdscript/gdscript_warning.cpp | 7 ------- modules/gdscript/gdscript_warning.h | 6 ++++-- 8 files changed, 16 insertions(+), 18 deletions(-) diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 7a58321fd00..742dcdabc1c 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -551,7 +551,7 @@ When set to [code]warn[/code] or [code]error[/code], produces a warning or an error respectively when the [code]@static_unload[/code] annotation is used in a script without any static variables. - + When enabled, using a property, enum, or function that was renamed since Godot 3 will produce a hint if an error occurs. diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index b95a0a7f9d8..c1ef99d6533 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -579,7 +579,7 @@ void ScriptTextEditor::_update_warnings() { bool has_connections_table = false; // Add missing connections. - if (GLOBAL_GET("debug/gdscript/warnings/enable").booleanize()) { + if (GLOBAL_GET("debug/gdscript/warnings/enable")) { Node *base = get_tree()->get_edited_scene_root(); if (base && missing_connections.size() > 0) { has_connections_table = true; diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 05fb4ac920a..db5a3b65ccb 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -2972,6 +2972,7 @@ GDScriptLanguage::GDScriptLanguage() { #ifdef DEBUG_ENABLED GLOBAL_DEF("debug/gdscript/warnings/enable", true); GLOBAL_DEF("debug/gdscript/warnings/exclude_addons", true); + GLOBAL_DEF("debug/gdscript/warnings/renamed_in_godot_4_hint", true); for (int i = 0; i < (int)GDScriptWarning::WARNING_MAX; i++) { GDScriptWarning::Code code = (GDScriptWarning::Code)i; Variant default_enabled = GDScriptWarning::get_default_value(code); diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 0e5fb015111..50b487059bf 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -3690,7 +3690,7 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a String base_name = is_self && !p_call->is_super ? "self" : base_type.to_string(); #ifdef SUGGEST_GODOT4_RENAMES String rename_hint; - if (GLOBAL_GET(GDScriptWarning::get_settings_path_from_code(GDScriptWarning::RENAMED_IN_GODOT_4_HINT)).booleanize()) { + if (GLOBAL_GET("debug/gdscript/warnings/renamed_in_godot_4_hint")) { const char *renamed_function_name = check_for_renamed_identifier(p_call->function_name, p_call->type); if (renamed_function_name) { rename_hint = " " + vformat(R"(Did you mean to use "%s"?)", String(renamed_function_name) + "()"); @@ -4036,7 +4036,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod if (!valid && base.is_hard_type()) { #ifdef SUGGEST_GODOT4_RENAMES String rename_hint; - if (GLOBAL_GET(GDScriptWarning::get_settings_path_from_code(GDScriptWarning::RENAMED_IN_GODOT_4_HINT)).booleanize()) { + if (GLOBAL_GET("debug/gdscript/warnings/renamed_in_godot_4_hint")) { const char *renamed_identifier_name = check_for_renamed_identifier(name, p_identifier->type); if (renamed_identifier_name) { rename_hint = " " + vformat(R"(Did you mean to use "%s"?)", renamed_identifier_name); @@ -4080,7 +4080,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod if (base.is_hard_type()) { #ifdef SUGGEST_GODOT4_RENAMES String rename_hint; - if (GLOBAL_GET(GDScriptWarning::get_settings_path_from_code(GDScriptWarning::RENAMED_IN_GODOT_4_HINT)).booleanize()) { + if (GLOBAL_GET("debug/gdscript/warnings/renamed_in_godot_4_hint")) { const char *renamed_identifier_name = check_for_renamed_identifier(name, p_identifier->type); if (renamed_identifier_name) { rename_hint = " " + vformat(R"(Did you mean to use "%s"?)", renamed_identifier_name); @@ -4596,7 +4596,7 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_ident // Not found. #ifdef SUGGEST_GODOT4_RENAMES String rename_hint; - if (GLOBAL_GET(GDScriptWarning::get_settings_path_from_code(GDScriptWarning::RENAMED_IN_GODOT_4_HINT)).booleanize()) { + if (GLOBAL_GET("debug/gdscript/warnings/renamed_in_godot_4_hint")) { const char *renamed_identifier_name = check_for_renamed_identifier(name, p_identifier->type); if (renamed_identifier_name) { rename_hint = " " + vformat(R"(Did you mean to use "%s"?)", renamed_identifier_name); diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 3a8463968b1..8f83c262fba 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -964,9 +964,11 @@ static void _find_annotation_arguments(const GDScriptParser::AnnotationNode *p_a } } else if (p_annotation->name == SNAME("@warning_ignore") || p_annotation->name == SNAME("@warning_ignore_start") || p_annotation->name == SNAME("@warning_ignore_restore")) { for (int warning_code = 0; warning_code < GDScriptWarning::WARNING_MAX; warning_code++) { - if (warning_code == GDScriptWarning::RENAMED_IN_GODOT_4_HINT) { - continue; +#ifndef DISABLE_DEPRECATED + if (warning_code >= GDScriptWarning::FIRST_DEPRECATED_WARNING) { + break; // Don't suggest deprecated warnings as they are never produced. } +#endif ScriptLanguage::CodeCompletionOption warning(GDScriptWarning::get_name_from_code((GDScriptWarning::Code)warning_code).to_lower(), ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT); warning.insert_text = warning.display.quote(p_quote_style); r_result.insert(warning.display, warning); diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index cd37cd0452f..64639178717 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -196,7 +196,7 @@ void GDScriptParser::push_warning(const Node *p_source, GDScriptWarning::Code p_ if (is_ignoring_warnings) { return; } - if (GLOBAL_GET("debug/gdscript/warnings/exclude_addons").booleanize() && script_path.begins_with("res://addons/")) { + if (GLOBAL_GET("debug/gdscript/warnings/exclude_addons") && script_path.begins_with("res://addons/")) { return; } GDScriptWarning::WarnLevel warn_level = (GDScriptWarning::WarnLevel)(int)GLOBAL_GET(GDScriptWarning::get_settings_path_from_code(p_code)); diff --git a/modules/gdscript/gdscript_warning.cpp b/modules/gdscript/gdscript_warning.cpp index a601cc49932..f14b38a1ef2 100644 --- a/modules/gdscript/gdscript_warning.cpp +++ b/modules/gdscript/gdscript_warning.cpp @@ -139,8 +139,6 @@ String GDScriptWarning::get_message() const { case DEPRECATED_KEYWORD: CHECK_SYMBOLS(2); return vformat(R"(The "%s" keyword is deprecated and will be removed in a future release, please replace its uses by "%s".)", symbols[0], symbols[1]); - case RENAMED_IN_GODOT_4_HINT: - break; // Renamed identifier hint is taken care of by the GDScriptAnalyzer. No message needed here. case CONFUSABLE_IDENTIFIER: CHECK_SYMBOLS(1); return vformat(R"(The identifier "%s" has misleading characters and might be confused with something else.)", symbols[0]); @@ -185,10 +183,6 @@ int GDScriptWarning::get_default_value(Code p_code) { } PropertyInfo GDScriptWarning::get_property_info(Code p_code) { - // Making this a separate function in case a warning needs different PropertyInfo in the future. - if (p_code == Code::RENAMED_IN_GODOT_4_HINT) { - return PropertyInfo(Variant::BOOL, get_settings_path_from_code(p_code)); - } return PropertyInfo(Variant::INT, get_settings_path_from_code(p_code), PROPERTY_HINT_ENUM, "Ignore,Warn,Error"); } @@ -236,7 +230,6 @@ String GDScriptWarning::get_name_from_code(Code p_code) { "ENUM_VARIABLE_WITHOUT_DEFAULT", "EMPTY_FILE", "DEPRECATED_KEYWORD", - "RENAMED_IN_GODOT_4_HINT", "CONFUSABLE_IDENTIFIER", "CONFUSABLE_LOCAL_DECLARATION", "CONFUSABLE_LOCAL_USAGE", diff --git a/modules/gdscript/gdscript_warning.h b/modules/gdscript/gdscript_warning.h index 99e9b30af57..e9ab309cd64 100644 --- a/modules/gdscript/gdscript_warning.h +++ b/modules/gdscript/gdscript_warning.h @@ -82,7 +82,6 @@ public: ENUM_VARIABLE_WITHOUT_DEFAULT, // A variable with an enum type does not have a default value. The default will be set to `0` instead of the first enum value. EMPTY_FILE, // A script file is empty. DEPRECATED_KEYWORD, // The keyword is deprecated and should be replaced. - RENAMED_IN_GODOT_4_HINT, // A variable or function that could not be found has been renamed in Godot 4. CONFUSABLE_IDENTIFIER, // The identifier contains misleading characters that can be confused. E.g. "usеr" (has Cyrillic "е" instead of Latin "e"). CONFUSABLE_LOCAL_DECLARATION, // The parent block declares an identifier with the same name below. CONFUSABLE_LOCAL_USAGE, // The identifier will be shadowed below in the block. @@ -99,6 +98,10 @@ public: WARNING_MAX, }; +#ifndef DISABLE_DEPRECATED + static constexpr int FIRST_DEPRECATED_WARNING = PROPERTY_USED_AS_FUNCTION; +#endif + constexpr static WarnLevel default_warning_levels[] = { WARN, // UNASSIGNED_VARIABLE WARN, // UNASSIGNED_VARIABLE_OP_ASSIGN @@ -136,7 +139,6 @@ public: WARN, // ENUM_VARIABLE_WITHOUT_DEFAULT WARN, // EMPTY_FILE WARN, // DEPRECATED_KEYWORD - WARN, // RENAMED_IN_GODOT_4_HINT WARN, // CONFUSABLE_IDENTIFIER WARN, // CONFUSABLE_LOCAL_DECLARATION WARN, // CONFUSABLE_LOCAL_USAGE