Fix script editor errors shown out of order

When warnings are treated as errors in GDScript, they are appended to
the error list via `push_error()` without regard for line ordering.
This causes them to appear after all other errors in the editor panel,
regardless of their actual line numbers.

Sort errors by line number (with column as tiebreaker) in
`_validate_script()` before display. This ensures the error panel and
the first-error indicator both reflect the correct source order. The
fix is language-agnostic, benefiting all script languages.
This commit is contained in:
Infiland
2026-04-02 23:18:44 +02:00
parent 3911e0963d
commit 07d360fbf6
+11
View File
@@ -838,6 +838,15 @@ Ref<Texture2D> ScriptTextEditor::get_theme_icon() {
return Ref<Texture2D>();
}
struct ScriptErrorLineComparator {
bool operator()(const ScriptLanguage::ScriptError &p_a, const ScriptLanguage::ScriptError &p_b) const {
if (p_a.line != p_b.line) {
return p_a.line < p_b.line;
}
return p_a.column < p_b.column;
}
};
void ScriptTextEditor::_validate_script() {
CodeEdit *te = code_editor->get_text_editor();
@@ -851,6 +860,8 @@ void ScriptTextEditor::_validate_script() {
Ref<Script> script = edited_res;
if (!script->get_language()->validate(text, script->get_path(), &fnc, &errors, &warnings, &safe_lines)) {
errors.sort_custom<ScriptErrorLineComparator>();
List<ScriptLanguage::ScriptError>::Element *E = errors.front();
while (E) {
List<ScriptLanguage::ScriptError>::Element *next_E = E->next();