Merge pull request #59943 from jordigcs/gdscript_warning_enums
Add enum values (Ignore, Warn, Error) to GDScript warnings
This commit is contained in:
commit
f2a7bb6b51
5 changed files with 103 additions and 59 deletions
|
|
@ -2232,9 +2232,13 @@ GDScriptLanguage::GDScriptLanguage() {
|
|||
GLOBAL_DEF("debug/gdscript/warnings/treat_warnings_as_errors", false);
|
||||
GLOBAL_DEF("debug/gdscript/warnings/exclude_addons", true);
|
||||
for (int i = 0; i < (int)GDScriptWarning::WARNING_MAX; i++) {
|
||||
String warning = GDScriptWarning::get_name_from_code((GDScriptWarning::Code)i).to_lower();
|
||||
bool default_enabled = !warning.begins_with("unsafe_");
|
||||
GLOBAL_DEF("debug/gdscript/warnings/" + warning, default_enabled);
|
||||
GDScriptWarning::Code code = (GDScriptWarning::Code)i;
|
||||
Variant default_enabled = GDScriptWarning::get_default_value(code);
|
||||
String path = GDScriptWarning::get_settings_path_from_code(code);
|
||||
GLOBAL_DEF(path, default_enabled);
|
||||
|
||||
PropertyInfo property_info = GDScriptWarning::get_property_info(code);
|
||||
ProjectSettings::get_singleton()->set_custom_property_info(path, property_info);
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,7 +203,8 @@ void GDScriptParser::push_warning(const Node *p_source, GDScriptWarning::Code p_
|
|||
if (ignored_warnings.has(warn_name)) {
|
||||
return;
|
||||
}
|
||||
if (!GLOBAL_GET("debug/gdscript/warnings/" + warn_name)) {
|
||||
int warn_level = (int)GLOBAL_GET(GDScriptWarning::get_settings_path_from_code(p_code));
|
||||
if (!warn_level) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -215,6 +216,11 @@ void GDScriptParser::push_warning(const Node *p_source, GDScriptWarning::Code p_
|
|||
warning.leftmost_column = p_source->leftmost_column;
|
||||
warning.rightmost_column = p_source->rightmost_column;
|
||||
|
||||
if (warn_level == GDScriptWarning::WarnLevel::ERROR) {
|
||||
push_error(warning.get_message(), p_source);
|
||||
return;
|
||||
}
|
||||
|
||||
List<GDScriptWarning>::Element *before = nullptr;
|
||||
for (List<GDScriptWarning>::Element *E = warnings.front(); E; E = E->next()) {
|
||||
if (E->get().start_line > warning.start_line) {
|
||||
|
|
|
|||
|
|
@ -163,6 +163,18 @@ String GDScriptWarning::get_message() const {
|
|||
#undef CHECK_SYMBOLS
|
||||
}
|
||||
|
||||
int GDScriptWarning::get_default_value(Code p_code) {
|
||||
if (get_name_from_code(p_code).to_lower().begins_with("unsafe_")) {
|
||||
return WarnLevel::IGNORE;
|
||||
}
|
||||
return WarnLevel::WARN;
|
||||
}
|
||||
|
||||
PropertyInfo GDScriptWarning::get_property_info(Code p_code) {
|
||||
// Making this a separate function in case a warning needs different PropertyInfo in the future.
|
||||
return PropertyInfo(Variant::INT, get_settings_path_from_code(p_code), PROPERTY_HINT_ENUM, "Ignore,Warn,Error");
|
||||
}
|
||||
|
||||
String GDScriptWarning::get_name() const {
|
||||
return get_name_from_code(code);
|
||||
}
|
||||
|
|
@ -210,6 +222,10 @@ String GDScriptWarning::get_name_from_code(Code p_code) {
|
|||
return names[(int)p_code];
|
||||
}
|
||||
|
||||
String GDScriptWarning::get_settings_path_from_code(Code p_code) {
|
||||
return "debug/gdscript/warnings/" + get_name_from_code(p_code).to_lower();
|
||||
}
|
||||
|
||||
GDScriptWarning::Code GDScriptWarning::get_code_from_name(const String &p_name) {
|
||||
for (int i = 0; i < WARNING_MAX; i++) {
|
||||
if (get_name_from_code((Code)i) == p_name) {
|
||||
|
|
|
|||
|
|
@ -33,11 +33,18 @@
|
|||
|
||||
#ifdef DEBUG_ENABLED
|
||||
|
||||
#include "core/object/object.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/templates/vector.h"
|
||||
|
||||
class GDScriptWarning {
|
||||
public:
|
||||
enum WarnLevel {
|
||||
IGNORE,
|
||||
WARN,
|
||||
ERROR
|
||||
};
|
||||
|
||||
enum Code {
|
||||
UNASSIGNED_VARIABLE, // Variable used but never assigned.
|
||||
UNASSIGNED_VARIABLE_OP_ASSIGN, // Variable never assigned but used in an assignment operation (+=, *=, etc).
|
||||
|
|
@ -81,7 +88,10 @@ public:
|
|||
|
||||
String get_name() const;
|
||||
String get_message() const;
|
||||
static int get_default_value(Code p_code);
|
||||
static PropertyInfo get_property_info(Code p_code);
|
||||
static String get_name_from_code(Code p_code);
|
||||
static String get_settings_path_from_code(Code p_code);
|
||||
static Code get_code_from_name(const String &p_name);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue