feat(xatu): add JSON debug output for parsed files
This commit is contained in:
@@ -29,6 +29,43 @@ impl std::fmt::Display for Report {
|
||||
}
|
||||
}
|
||||
|
||||
/// Contains parser output without lint diagnostics.
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
pub struct DebugReport {
|
||||
files: Vec<DebugFile>,
|
||||
}
|
||||
|
||||
impl DebugReport {
|
||||
pub fn has_parse_errors(&self) -> bool {
|
||||
self.files.iter().any(|file| !file.parsed.errors.is_empty())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
struct DebugFile {
|
||||
path: std::path::PathBuf,
|
||||
parsed: ast::ParsedFile,
|
||||
}
|
||||
|
||||
/// Collects parser output without running lint rules.
|
||||
pub fn debug(mut files: Vec<SourceFile>) -> DebugReport {
|
||||
files.sort_by(|left, right| left.path.cmp(&right.path));
|
||||
files.dedup_by(|left, right| left.path == right.path);
|
||||
let mut store = FileStore::default();
|
||||
let files = files
|
||||
.into_iter()
|
||||
.map(|file| {
|
||||
let file_id = store.add(file);
|
||||
let file = store.get(file_id);
|
||||
DebugFile {
|
||||
path: file.path.clone(),
|
||||
parsed: parser::parse_file(file_id, &file.source),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
DebugReport { files }
|
||||
}
|
||||
|
||||
/// Analyzes source files and returns the diagnostics Xatu finds.
|
||||
pub fn future_sight(files: Vec<SourceFile>) -> status::Result<Report> {
|
||||
let mut store = FileStore::default();
|
||||
|
||||
Reference in New Issue
Block a user