luaur_analyze_cli/functions/
report_module_result.rs1use crate::enums::report_format::ReportFormat;
2use crate::functions::report_error::report_error;
3use crate::functions::report_warning::report_warning;
4use alloc::sync::Arc;
5use luaur_analysis::functions::attach_type_data::attach_type_data;
6use luaur_analysis::records::file_resolver::FileResolver;
7use luaur_analysis::records::frontend::Frontend;
8use luaur_analysis::records::module::Module;
9use luaur_analysis::type_aliases::module_name_file_resolver::ModuleName;
10use luaur_ast::functions::pretty_print_with_types_pretty_printer_alt_b::pretty_print_with_types_ast_stat_block;
11
12pub fn report_module_result(
15 frontend: &mut Frontend,
16 name: &ModuleName,
17 format: ReportFormat,
18 annotate: bool,
19) -> bool {
20 let cr = frontend.get_check_result(name, false, false);
22
23 let cr = match cr {
24 None => {
25 eprintln!("Failed to find result for {}", name);
26 return false;
27 }
28 Some(cr) => cr,
29 };
30
31 if frontend.get_source_module(name).is_null() {
33 eprintln!("Error opening {}", name);
34 return false;
35 }
36
37 for error in &cr.errors {
39 report_error(frontend, format, error);
40 }
41
42 let human_readable_name =
44 unsafe { FileResolver::get_human_readable_module_name(frontend.file_resolver, name) };
45
46 for error in &cr.lint_result.errors {
48 report_warning(format, &human_readable_name, error);
49 }
50 for warning in &cr.lint_result.warnings {
52 report_warning(format, &human_readable_name, warning);
53 }
54
55 if annotate {
56 let sm = frontend.get_source_module_mut(name);
59 let module = frontend.module_resolver.get_module(name);
60
61 let module_ptr = Arc::as_ptr(&module) as *mut Module;
65 unsafe {
66 attach_type_data(&mut *sm, &mut *module_ptr);
67
68 let annotated = pretty_print_with_types_ast_stat_block(&mut *(*sm).root);
70
71 print!("{}", annotated);
73 }
74 }
75
76 cr.errors.is_empty() && cr.lint_result.errors.is_empty()
78}