Skip to content

Commit 3e840ca

Browse files
committed
Extract ProjectFilesWalker
1 parent 85c8ee9 commit 3e840ca

File tree

6 files changed

+233
-175
lines changed

6 files changed

+233
-175
lines changed

crates/red_knot/src/main.rs

+36-14
Original file line numberDiff line numberDiff line change
@@ -266,29 +266,49 @@ impl MainLoop {
266266
Severity::Error
267267
};
268268

269-
let failed = result
270-
.iter()
271-
.any(|diagnostic| diagnostic.severity() >= min_error_severity);
272-
273269
if check_revision == revision {
274270
let mut stdout = stdout().lock();
275-
for diagnostic in result {
276-
writeln!(stdout, "{}", diagnostic.display(db, &display_config))?;
271+
if result.is_empty() {
272+
if db.project().files(db).is_empty() {
273+
tracing::warn!("No python files found under the given path(s)");
274+
}
275+
276+
writeln!(stdout, "All checks passed!")?;
277+
278+
if self.watcher.is_none() {
279+
return Ok(ExitStatus::Success);
280+
}
281+
} else {
282+
let mut failed = false;
283+
let diagnostics_count = result.len();
284+
285+
for diagnostic in result {
286+
writeln!(stdout, "{}", diagnostic.display(db, &display_config))?;
287+
288+
failed |= diagnostic.severity() >= min_error_severity;
289+
}
290+
291+
writeln!(
292+
stdout,
293+
"Found {} diagnostic{}",
294+
diagnostics_count,
295+
if diagnostics_count > 1 { "s" } else { "" }
296+
)?;
297+
298+
if self.watcher.is_none() {
299+
return Ok(if failed {
300+
ExitStatus::Failure
301+
} else {
302+
ExitStatus::Success
303+
});
304+
}
277305
}
278306
} else {
279307
tracing::debug!(
280308
"Discarding check result for outdated revision: current: {revision}, result revision: {check_revision}"
281309
);
282310
}
283311

284-
if self.watcher.is_none() {
285-
return Ok(if failed {
286-
ExitStatus::Failure
287-
} else {
288-
ExitStatus::Success
289-
});
290-
}
291-
292312
tracing::trace!("Counts after last check:\n{}", countme::get_all());
293313
}
294314

@@ -333,7 +353,9 @@ impl MainLoopCancellationToken {
333353
enum MainLoopMessage {
334354
CheckWorkspace,
335355
CheckCompleted {
356+
/// The diagnostics that were found during the check.
336357
result: Vec<Box<dyn Diagnostic>>,
358+
337359
revision: u64,
338360
},
339361
ApplyChanges(Vec<watch::ChangeEvent>),

0 commit comments

Comments
 (0)