MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / _validate_script

Method _validate_script

editor/script/script_text_editor.cpp:833–885  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

831}
832
833void ScriptTextEditor::_validate_script() {
834 CodeEdit *te = code_editor->get_text_editor();
835
836 String text = te->get_text();
837 List<String> fnc;
838
839 warnings.clear();
840 errors.clear();
841 depended_errors.clear();
842 safe_lines.clear();
843
844 if (!script->get_language()->validate(text, script->get_path(), &fnc, &errors, &warnings, &safe_lines)) {
845 List<ScriptLanguage::ScriptError>::Element *E = errors.front();
846 while (E) {
847 List<ScriptLanguage::ScriptError>::Element *next_E = E->next();
848 if ((E->get().path.is_empty() && !script->get_path().is_empty()) || E->get().path != script->get_path()) {
849 depended_errors[E->get().path].push_back(E->get());
850 E->erase();
851 }
852 E = next_E;
853 }
854
855 if (errors.size() > 0) {
856 const int line = errors.front()->get().line;
857 const int column = errors.front()->get().column;
858 const String message = errors.front()->get().message.replace("[", "[lb]");
859 const String error_text = vformat(TTR("Error at ([hint=Line %d, column %d]%d, %d[/hint]):"), line, column, line, column) + " " + message;
860 code_editor->set_error(error_text);
861 code_editor->set_error_pos(line - 1, column - 1);
862 }
863 script_is_valid = false;
864 } else {
865 code_editor->set_error("");
866 if (!script->is_tool()) {
867 script->set_source_code(text);
868 script->update_exports();
869 te->get_syntax_highlighter()->update_cache();
870 }
871
872 functions.clear();
873 for (const String &E : fnc) {
874 functions.push_back(E);
875 }
876 script_is_valid = true;
877 }
878 _update_connected_methods();
879 _update_warnings();
880 _update_errors();
881 _update_background_color();
882
883 emit_signal(SNAME("name_changed"));
884 emit_signal(SNAME("edited_script_changed"));
885}
886
887void ScriptTextEditor::_update_warnings() {
888 int warning_nb = warnings.size();

Callers

nothing calls this directly

Calls 15

vformatFunction · 0.85
TTRFunction · 0.85
get_text_editorMethod · 0.80
set_error_posMethod · 0.80
sizeMethod · 0.65
get_textMethod · 0.45
clearMethod · 0.45
validateMethod · 0.45
get_languageMethod · 0.45
get_pathMethod · 0.45
frontMethod · 0.45

Tested by

no test coverage detected