Check base scripts for signal receiving methods before warning about them missing

This commit is contained in:
Michael Alexsander Silva Dias 2019-06-11 19:48:35 -03:00
parent 30e8b53c38
commit 831dd19546

View file

@ -547,7 +547,6 @@ void ScriptTextEditor::_validate_script() {
script->set_source_code(text);
script->update_exports();
_update_member_keywords();
//script->reload(); //will update all the variables in property editors
}
functions.clear();
@ -558,10 +557,11 @@ void ScriptTextEditor::_validate_script() {
}
_update_connected_methods();
code_editor->set_warning_nb(missing_connections.size() + warnings.size());
int warning_nb = warnings.size();
warnings_panel->clear();
// add missing connections
// Add missing connections.
if (GLOBAL_GET("debug/gdscript/warnings/enable").booleanize()) {
Node *base = get_tree()->get_edited_scene_root();
if (base && missing_connections.size() > 0) {
warnings_panel->push_table(1);
@ -574,14 +574,19 @@ void ScriptTextEditor::_validate_script() {
warnings_panel->push_cell();
warnings_panel->push_color(warnings_panel->get_color("warning_color", "Editor"));
warnings_panel->add_text(vformat(TTR("Missing connected method '%s' for signal '%s' from node '%s' to node '%s'"), connection.method, connection.signal, source_path, target_path));
warnings_panel->pop(); // Color
warnings_panel->pop(); // Cell
warnings_panel->add_text(vformat(TTR("Missing connected method '%s' for signal '%s' from node '%s' to node '%s'."), connection.method, connection.signal, source_path, target_path));
warnings_panel->pop(); // Color.
warnings_panel->pop(); // Cell.
}
warnings_panel->pop(); // Table.
warning_nb += missing_connections.size();
}
warnings_panel->pop(); // Table
}
// add script warnings
code_editor->set_warning_nb(warning_nb);
// Add script warnings.
warnings_panel->push_table(3);
for (List<ScriptLanguage::Warning>::Element *E = warnings.front(); E; E = E->next()) {
ScriptLanguage::Warning w = E->get();
@ -591,13 +596,13 @@ void ScriptTextEditor::_validate_script() {
warnings_panel->push_color(warnings_panel->get_color("warning_color", "Editor"));
warnings_panel->add_text(TTR("Line") + " " + itos(w.line));
warnings_panel->add_text(" (" + w.string_code + "):");
warnings_panel->pop(); // Color
warnings_panel->pop(); // Meta goto
warnings_panel->pop(); // Cell
warnings_panel->pop(); // Color.
warnings_panel->pop(); // Meta goto.
warnings_panel->pop(); // Cell.
warnings_panel->push_cell();
warnings_panel->add_text(w.message);
warnings_panel->pop(); // Cell
warnings_panel->pop(); // Cell.
Dictionary ignore_meta;
ignore_meta["line"] = w.line;
@ -605,11 +610,10 @@ void ScriptTextEditor::_validate_script() {
warnings_panel->push_cell();
warnings_panel->push_meta(ignore_meta);
warnings_panel->add_text(TTR("(ignore)"));
warnings_panel->pop(); // Meta ignore
warnings_panel->pop(); // Cell
//warnings_panel->add_newline();
warnings_panel->pop(); // Meta ignore.
warnings_panel->pop(); // Cell.
}
warnings_panel->pop(); // Table
warnings_panel->pop(); // Table.
line--;
bool highlight_safe = EDITOR_DEF("text_editor/highlighting/highlight_type_safe_lines", true);
@ -874,12 +878,27 @@ void ScriptTextEditor::_update_connected_methods() {
int line = script->get_language()->find_function(connection.method, text_edit->get_text());
if (line < 0) {
missing_connections.push_back(connection);
continue;
// There is a chance that the method is inherited from another script.
bool found_inherited_function = false;
Ref<Script> inherited_script = script->get_base_script();
while (!inherited_script.is_null()) {
line = inherited_script->get_language()->find_function(connection.method, inherited_script->get_source_code());
if (line != -1) {
found_inherited_function = true;
break;
}
inherited_script = inherited_script->get_base_script();
}
if (!found_inherited_function) {
missing_connections.push_back(connection);
}
} else {
text_edit->set_line_info_icon(line - 1, get_parent_control()->get_icon("Slot", "EditorIcons"), connection.method);
}
}
}
}
void ScriptTextEditor::_lookup_connections(int p_row, String p_method) {