use crate::enums::report_format::ReportFormat;
use crate::functions::report_error::report_error;
use crate::functions::report_warning::report_warning;
use alloc::sync::Arc;
use luaur_analysis::functions::attach_type_data::attach_type_data;
use luaur_analysis::records::file_resolver::FileResolver;
use luaur_analysis::records::frontend::Frontend;
use luaur_analysis::records::module::Module;
use luaur_analysis::type_aliases::module_name_file_resolver::ModuleName;
use luaur_ast::functions::pretty_print_with_types_pretty_printer_alt_b::pretty_print_with_types_ast_stat_block;
pub fn report_module_result(
frontend: &mut Frontend,
name: &ModuleName,
format: ReportFormat,
annotate: bool,
) -> bool {
let cr = frontend.get_check_result(name, false, false);
let cr = match cr {
None => {
eprintln!("Failed to find result for {}", name);
return false;
}
Some(cr) => cr,
};
if frontend.get_source_module(name).is_null() {
eprintln!("Error opening {}", name);
return false;
}
for error in &cr.errors {
report_error(frontend, format, error);
}
let human_readable_name =
unsafe { FileResolver::get_human_readable_module_name(frontend.file_resolver, name) };
for error in &cr.lint_result.errors {
report_warning(format, &human_readable_name, error);
}
for warning in &cr.lint_result.warnings {
report_warning(format, &human_readable_name, warning);
}
if annotate {
let sm = frontend.get_source_module_mut(name);
let module = frontend.module_resolver.get_module(name);
let module_ptr = Arc::as_ptr(&module) as *mut Module;
unsafe {
attach_type_data(&mut *sm, &mut *module_ptr);
let annotated = pretty_print_with_types_ast_stat_block(&mut *(*sm).root);
print!("{}", annotated);
}
}
cr.errors.is_empty() && cr.lint_result.errors.is_empty()
}