@@ -4,6 +4,7 @@ use ruff_text_size::{Ranged, TextRange};
44use tracing:: { error, info} ;
55use weak_table:: { PtrWeakHashSet , PtrWeakKeyHashMap } ;
66use std:: collections:: { HashMap , HashSet } ;
7+ use std:: ffi:: OsStr ;
78
89use crate :: core:: csv_arch_builder:: CsvArchBuilder ;
910use crate :: core:: diagnostics:: { create_diagnostic, DiagnosticCode } ;
@@ -50,6 +51,7 @@ pub struct ModuleSymbol {
5051 pub parent : Option < Weak < RefCell < Symbol > > > ,
5152 pub not_found_paths : Vec < ( BuildSteps , Vec < OYarn > ) > ,
5253 pub not_found_data : HashMap < String , BuildSteps > ,
54+ pub not_found_models : HashMap < OYarn , BuildSteps > ,
5355 pub in_workspace : bool ,
5456 pub model_dependencies : PtrWeakHashSet < Weak < RefCell < Model > > > , //always on validation level, as odoo step is always required
5557 pub dependencies : Vec < Vec < Option < PtrWeakHashSet < Weak < RefCell < Symbol > > > > > > ,
@@ -76,6 +78,7 @@ impl ModuleSymbol {
7678 is_external,
7779 not_found_paths : vec ! [ ] ,
7880 not_found_data : HashMap :: new ( ) ,
81+ not_found_models : HashMap :: new ( ) ,
7982 in_workspace : false ,
8083 root_path : dir_path. sanitize ( ) ,
8184 loaded : false ,
@@ -151,7 +154,6 @@ impl ModuleSymbol {
151154 let manifest_file_info = session. sync_odoo . get_file_mgr ( ) . borrow ( ) . get_file_info ( & manifest_path. sanitize ( ) ) . expect ( "file not found in cache" ) . clone ( ) ;
152155 let mut manifest_file_info = ( * manifest_file_info) . borrow_mut ( ) ;
153156 manifest_file_info. replace_diagnostics ( crate :: constants:: BuildSteps :: ARCH , diagnostics) ;
154- manifest_file_info. publish_diagnostics ( session) ;
155157 }
156158
157159 /* Load manifest to identify the module characteristics.
@@ -363,6 +365,38 @@ impl ModuleSymbol {
363365 diagnostics
364366 }
365367
368+ pub fn validate_manifest ( symbol : & Rc < RefCell < Symbol > > , session : & mut SessionInfo ) {
369+ let data_paths = symbol. borrow ( ) . as_module_package ( ) . data . clone ( ) ;
370+ let mut diagnostics = vec ! [ ] ;
371+ for ( data_url, data_range) in data_paths. iter ( ) {
372+ // validate csv file names, check that their models exist
373+ let path = PathBuf :: from ( symbol. borrow ( ) . paths ( ) [ 0 ] . clone ( ) ) . join ( data_url) ;
374+ if path. extension ( ) . unwrap_or_default ( ) != "csv" || !path. exists ( ) {
375+ continue ;
376+ }
377+ let Some ( model_name) = path. file_stem ( ) . and_then ( OsStr :: to_str) . map ( |n| Sy ! ( n. to_string( ) ) ) else {
378+ continue ;
379+ } ;
380+ let maybe_model = session. sync_odoo . models . get ( & model_name) . cloned ( ) ;
381+ let model_exists = maybe_model. as_ref ( ) . map ( |m| m. borrow_mut ( ) . has_symbols ( ) ) . unwrap_or ( false ) ;
382+ if !model_exists {
383+ if let Some ( diagnostic) = create_diagnostic ( session, DiagnosticCode :: OLS05056 , & [ & model_name] ) {
384+ diagnostics. push ( Diagnostic {
385+ range : Range :: new ( Position :: new ( data_range. start ( ) . to_u32 ( ) , 0 ) , Position :: new ( data_range. end ( ) . to_u32 ( ) , 0 ) ) ,
386+ ..diagnostic. clone ( )
387+ } ) ;
388+ }
389+ symbol. borrow_mut ( ) . as_module_package_mut ( ) . not_found_models . insert ( model_name. clone ( ) , BuildSteps :: VALIDATION ) ;
390+ session. sync_odoo . get_main_entry ( ) . borrow_mut ( ) . not_found_symbols_for_models . insert ( symbol. clone ( ) ) ;
391+ }
392+ }
393+ let manifest_path = PathBuf :: from ( symbol. borrow ( ) . as_module_package ( ) . root_path . clone ( ) ) . join ( "__manifest__.py" ) ;
394+ let manifest_file_info = session. sync_odoo . get_file_mgr ( ) . borrow ( ) . get_file_info ( & manifest_path. sanitize ( ) ) . expect ( "file not found in cache" ) . clone ( ) ;
395+ let mut manifest_file_info = ( * manifest_file_info) . borrow_mut ( ) ;
396+ manifest_file_info. replace_diagnostics ( crate :: constants:: BuildSteps :: VALIDATION , diagnostics) ;
397+ manifest_file_info. publish_diagnostics ( session) ;
398+ }
399+
366400 pub fn load_data ( symbol : & Rc < RefCell < Symbol > > , session : & mut SessionInfo ) {
367401 let data_paths = symbol. borrow ( ) . as_module_package ( ) . data . clone ( ) ;
368402 for ( data_url, _data_range) in data_paths. iter ( ) {
0 commit comments