Skip to main content

lintel_diagnostics/
reporter.rs

1use core::time::Duration;
2
3use lintel_schema_cache::CacheStatus;
4use lintel_validation_cache::ValidationCacheStatus;
5
6use crate::diagnostics::LintelDiagnostic;
7
8/// A file that was checked and the schema it resolved to.
9pub struct CheckedFile {
10    pub path: String,
11    pub schema: String,
12    /// `None` for local schemas and builtins; `Some` for remote schemas.
13    pub cache_status: Option<CacheStatus>,
14    /// `None` when validation caching is not applicable; `Some` for validation cache hits/misses.
15    pub validation_cache_status: Option<ValidationCacheStatus>,
16}
17
18/// Result of a check run (validation + optional format checking).
19pub struct CheckResult {
20    pub errors: Vec<LintelDiagnostic>,
21    pub checked: Vec<CheckedFile>,
22}
23
24impl CheckResult {
25    pub fn has_errors(&self) -> bool {
26        !self.errors.is_empty()
27    }
28
29    pub fn files_checked(&self) -> usize {
30        self.checked.len()
31    }
32}
33
34/// Format a verbose line for a checked file, including cache status tags.
35pub fn format_checked_verbose(file: &CheckedFile) -> String {
36    let schema_tag = match file.cache_status {
37        Some(CacheStatus::Hit) => " [cached]",
38        Some(CacheStatus::Miss | CacheStatus::Disabled) => " [fetched]",
39        None => "",
40    };
41    let validation_tag = match file.validation_cache_status {
42        Some(ValidationCacheStatus::Hit) => " [validated:cached]",
43        Some(ValidationCacheStatus::Miss) => " [validated]",
44        None => "",
45    };
46    format!(
47        "  {} ({}){schema_tag}{validation_tag}",
48        file.path, file.schema
49    )
50}
51
52/// Trait for formatting and outputting check results.
53pub trait Reporter {
54    /// Called after all checks complete with the full result and elapsed time.
55    fn report(&mut self, result: CheckResult, elapsed: Duration);
56
57    /// Called each time a file is checked (for streaming progress).
58    fn on_file_checked(&mut self, file: &CheckedFile);
59}