use DisplayDiagnostics in MainLoop, fix JSON snapshot

This commit is contained in:
Brent Westbrook 2025-07-04 11:49:24 -04:00
parent 70b226f0ab
commit 8c905be063
2 changed files with 47 additions and 9 deletions

View file

@ -18,7 +18,7 @@ use clap::{CommandFactory, Parser};
use colored::Colorize;
use crossbeam::channel as crossbeam_channel;
use rayon::ThreadPoolBuilder;
use ruff_db::diagnostic::{Diagnostic, DisplayDiagnosticConfig, Severity};
use ruff_db::diagnostic::{Diagnostic, DisplayDiagnosticConfig, DisplayDiagnostics, Severity};
use ruff_db::max_parallelism;
use ruff_db::system::{OsSystem, SystemPath, SystemPathBuf};
use salsa::plumbing::ZalsaDatabase;
@ -309,14 +309,19 @@ impl MainLoop {
return Ok(ExitStatus::Success);
}
} else {
let mut max_severity = Severity::Info;
let diagnostics_count = result.len();
for diagnostic in result {
write!(stdout, "{}", diagnostic.display(db, &display_config))?;
let max_severity = result
.iter()
.map(Diagnostic::severity)
.max()
.unwrap_or(Severity::Info);
max_severity = max_severity.max(diagnostic.severity());
}
write!(
stdout,
"{}",
DisplayDiagnostics::new(db, &display_config, &result)
)?;
if should_print_summary {
writeln!(

View file

@ -564,9 +564,42 @@ fn json_diagnostics() -> anyhow::Result<()> {
success: false
exit_code: 1
----- stdout -----
[{"cell":null,"code":null,"end_location":{"column":8,"row":2},"filename":"test.py","fix":null,"location":{"column":7,"row":2},"message":"Name `x` used when not defined","noqa_row":null,"url":"https://docs.astral.sh/ty/reference/rules/#unresolved-reference"}]
[{"cell":null,"code":null,"end_location":{"column":8,"row":3},"filename":"test.py","fix":null,"location":{"column":7,"row":3},"message":"Cannot subscript object of type `Literal[4]` with no `__getitem__` method","noqa_row":null,"url":"https://docs.astral.sh/ty/reference/rules/#non-subscriptable"}]
[
{
"cell": null,
"code": null,
"end_location": {
"column": 8,
"row": 2
},
"filename": "test.py",
"fix": null,
"location": {
"column": 7,
"row": 2
},
"message": "Name `x` used when not defined",
"noqa_row": null,
"url": "https://docs.astral.sh/ty/reference/rules/#unresolved-reference"
},
{
"cell": null,
"code": null,
"end_location": {
"column": 8,
"row": 3
},
"filename": "test.py",
"fix": null,
"location": {
"column": 7,
"row": 3
},
"message": "Cannot subscript object of type `Literal[4]` with no `__getitem__` method",
"noqa_row": null,
"url": "https://docs.astral.sh/ty/reference/rules/#non-subscriptable"
}
]
----- stderr -----
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
"#);