Merge pull request #60521 from IgorKordiukiewicz/warning-ignore-annotations
Added button to add warning ignore annotations
This commit is contained in:
commit
12f25ce574
1 changed files with 36 additions and 1 deletions
|
@ -239,6 +239,29 @@ void ScriptTextEditor::_show_warnings_panel(bool p_show) {
|
|||
void ScriptTextEditor::_warning_clicked(Variant p_line) {
|
||||
if (p_line.get_type() == Variant::INT) {
|
||||
goto_line_centered(p_line.operator int64_t());
|
||||
} else if (p_line.get_type() == Variant::DICTIONARY) {
|
||||
Dictionary meta = p_line.operator Dictionary();
|
||||
const int line = meta["line"].operator int64_t() - 1;
|
||||
|
||||
CodeEdit *text_editor = code_editor->get_text_editor();
|
||||
String prev_line = line > 0 ? text_editor->get_line(line - 1) : "";
|
||||
if (prev_line.contains("@warning_ignore")) {
|
||||
const int closing_bracket_idx = prev_line.find(")");
|
||||
const String text_to_insert = ", " + meta["code"].operator String();
|
||||
prev_line = prev_line.insert(closing_bracket_idx, text_to_insert);
|
||||
text_editor->set_line(line - 1, prev_line);
|
||||
} else {
|
||||
const int indent = text_editor->get_indent_level(line) / text_editor->get_indent_size();
|
||||
String annotation_indent;
|
||||
if (!text_editor->is_indent_using_spaces()) {
|
||||
annotation_indent = String("\t").repeat(indent);
|
||||
} else {
|
||||
annotation_indent = String(" ").repeat(text_editor->get_indent_size() * indent);
|
||||
}
|
||||
text_editor->insert_line_at(line, annotation_indent + "@warning_ignore(" + meta["code"].operator String() + ")");
|
||||
}
|
||||
|
||||
_validate_script();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -482,8 +505,20 @@ void ScriptTextEditor::_update_warnings() {
|
|||
}
|
||||
|
||||
// Add script warnings.
|
||||
warnings_panel->push_table(2);
|
||||
warnings_panel->push_table(3);
|
||||
for (const ScriptLanguage::Warning &w : warnings) {
|
||||
Dictionary ignore_meta;
|
||||
ignore_meta["line"] = w.start_line;
|
||||
ignore_meta["code"] = w.string_code.to_lower();
|
||||
warnings_panel->push_cell();
|
||||
warnings_panel->push_meta(ignore_meta);
|
||||
warnings_panel->push_color(
|
||||
warnings_panel->get_theme_color(SNAME("accent_color"), SNAME("Editor")).lerp(warnings_panel->get_theme_color(SNAME("mono_color"), SNAME("Editor")), 0.5f));
|
||||
warnings_panel->add_text(TTR("[Ignore]"));
|
||||
warnings_panel->pop(); // Color.
|
||||
warnings_panel->pop(); // Meta ignore.
|
||||
warnings_panel->pop(); // Cell.
|
||||
|
||||
warnings_panel->push_cell();
|
||||
warnings_panel->push_meta(w.start_line - 1);
|
||||
warnings_panel->push_color(warnings_panel->get_theme_color(SNAME("warning_color"), SNAME("Editor")));
|
||||
|
|
Loading…
Reference in a new issue