Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

GDScript: Use extends line as range for MISSING_TOOL warning

Malcolm Andersonad74e634d6dd
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index 827789cd986..21e45d5ce92 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -452,7 +452,7 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c
#ifdef DEBUG_ENABLED
if (!parser->_is_tool && ext_parser->get_parser()->_is_tool) {
- parser->push_warning(p_class, GDScriptWarning::MISSING_TOOL);
+ parser->push_warning(p_class->extends_start_line, p_class->extends_start_column, p_class->extends_end_line, p_class->extends_end_column, GDScriptWarning::MISSING_TOOL);
}
#endif // DEBUG_ENABLED
@@ -486,7 +486,7 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c
#ifdef DEBUG_ENABLED
if (!parser->_is_tool && base_parser->get_parser()->_is_tool) {
- parser->push_warning(p_class, GDScriptWarning::MISSING_TOOL);
+ parser->push_warning(p_class->extends_start_line, p_class->extends_start_column, p_class->extends_end_line, p_class->extends_end_column, GDScriptWarning::MISSING_TOOL);
}
#endif // DEBUG_ENABLED
@@ -513,7 +513,7 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c
#ifdef DEBUG_ENABLED
if (!parser->_is_tool && info_parser->get_parser()->_is_tool) {
- parser->push_warning(p_class, GDScriptWarning::MISSING_TOOL);
+ parser->push_warning(p_class->extends_start_line, p_class->extends_start_column, p_class->extends_end_line, p_class->extends_end_column, GDScriptWarning::MISSING_TOOL);
}
#endif // DEBUG_ENABLED
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index a404b572a91..611c9c761b1 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -1024,6 +1024,8 @@ void GDScriptParser::parse_class_name() {
void GDScriptParser::parse_extends() {
current_class->extends_used = true;
+ current_class->extends_start_line = previous.start_line;
+ current_class->extends_start_column = previous.start_column;
int chain_index = 0;
@@ -1034,6 +1036,8 @@ void GDScriptParser::parse_extends() {
current_class->extends_path = previous.literal;
if (!match(GDScriptTokenizer::Token::PERIOD)) {
+ current_class->extends_end_line = previous.end_line;
+ current_class->extends_end_column = previous.end_column;
return;
}
}
@@ -1041,6 +1045,8 @@ void GDScriptParser::parse_extends() {
make_completion_context(COMPLETION_INHERIT_TYPE, current_class, chain_index++);
if (!consume(GDScriptTokenizer::Token::IDENTIFIER, R"(Expected superclass name after "extends".)")) {
+ current_class->extends_end_line = previous.end_line;
+ current_class->extends_end_column = previous.end_column;
return;
}
current_class->extends.push_back(parse_identifier());
@@ -1048,10 +1054,15 @@ void GDScriptParser::parse_extends() {
while (match(GDScriptTokenizer::Token::PERIOD)) {
make_completion_context(COMPLETION_INHERIT_TYPE, current_class, chain_index++);
if (!consume(GDScriptTokenizer::Token::IDENTIFIER, R"(Expected superclass name after ".".)")) {
+ current_class->extends_end_line = previous.end_line;
+ current_class->extends_end_column = previous.end_column;
return;
}
current_class->extends.push_back(parse_identifier());
}
+
+ current_class->extends_end_line = previous.end_line;
+ current_class->extends_end_column = previous.end_column;
}
template <typename T>
diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h
index d86a96c65f7..a760863a1ea 100644
--- a/modules/gdscript/gdscript_parser.h
+++ b/modules/gdscript/gdscript_parser.h
@@ -762,6 +762,13 @@ public:
Vector<IdentifierNode *> extends; // List for indexing: extends A.B.C
DataType base_type;
String fqcn; // Fully-qualified class name. Identifies uniquely any class in the project.
+
+ // Range for a class's "extends <CLASS_NAME>" line.
+ // Used as range for some warnings/errors.
+ int extends_start_line = -1;
+ int extends_start_column = -1;
+ int extends_end_line = -1;
+ int extends_end_column = -1;
#ifdef TOOLS_ENABLED
ClassDocData doc_data;