use yog_data::{Diagnostic, Schema};
#[derive(Debug, Default, Schema)]
pub(crate) struct Checked {
pub(crate) problems: Vec<Diagnostic>,
}
pub(crate) fn check(path: &str, text: &str) -> Checked {
let format = yog_ids::Format::of_path(std::path::Path::new(path));
if matches!(
format,
Some(yog_ids::Format::Script | yog_ids::Format::Nanites)
) {
return Checked {
problems: yog_script_build::check_source(path, text),
};
}
let doc = match yog_data::text::parse(text) {
Ok(doc) => doc,
Err(e) => {
return Checked {
problems: vec![Diagnostic::syntax(e)],
};
}
};
let Some(format) = yog_ids::Format::of_path(std::path::Path::new(path)) else {
return Checked::default();
};
let problems = yog_formats::problems(format, &doc.value)
.into_iter()
.map(|p| yog_data::placed(text, &doc, p))
.collect();
Checked { problems }
}