@@ -3,7 +3,7 @@ use std::{cell::RefCell, collections::HashMap, hash::Hash, path::PathBuf, rc::Rc
3
3
use lsp_types:: { Diagnostic , Position , Range } ;
4
4
use tracing:: { info, trace} ;
5
5
6
- use crate :: { constants:: { BuildSteps , SymType , DEBUG_STEPS } , core:: { entry_point:: { EntryPoint , EntryPointType } , file_mgr:: FileInfo , odoo:: SyncOdoo , symbols:: symbol:: Symbol , xml_data:: { XmlData , XmlDataActWindow , XmlDataDelete , XmlDataMenuItem , XmlDataRecord , XmlDataReport , XmlDataTemplate } } , threads:: SessionInfo } ;
6
+ use crate :: { constants:: { BuildSteps , SymType , DEBUG_STEPS , EXTENSION_NAME } , core:: { entry_point:: { EntryPoint , EntryPointType } , file_mgr:: FileInfo , model :: Model , odoo:: SyncOdoo , symbols:: symbol:: Symbol , xml_data:: { XmlData , XmlDataActWindow , XmlDataDelete , XmlDataMenuItem , XmlDataRecord , XmlDataReport , XmlDataTemplate } } , threads:: SessionInfo , S } ;
7
7
8
8
9
9
@@ -35,74 +35,97 @@ impl XmlValidator {
35
35
}
36
36
let module = self . xml_symbol . borrow ( ) . find_module ( ) . unwrap ( ) ;
37
37
let mut dependencies = vec ! [ ] ;
38
+ let mut model_dependencies = vec ! [ ] ;
39
+ let mut diagnostics = vec ! [ ] ;
38
40
for xml_ids in self . xml_symbol . borrow ( ) . as_xml_file_sym ( ) . xml_ids . values ( ) {
39
41
for xml_id in xml_ids. iter ( ) {
40
- self . validate_xml_id ( session, & module, xml_id, & mut dependencies) ;
42
+ self . validate_xml_id ( session, & module, xml_id, & mut diagnostics , & mut dependencies, & mut model_dependencies ) ;
41
43
}
42
44
}
43
- for mut dep in dependencies. iter_mut ( ) {
45
+ for dep in dependencies. iter_mut ( ) {
44
46
self . xml_symbol . borrow_mut ( ) . add_dependency ( & mut dep. borrow_mut ( ) , BuildSteps :: VALIDATION , BuildSteps :: ARCH_EVAL ) ;
45
47
}
48
+ for model in model_dependencies. iter ( ) {
49
+ self . xml_symbol . borrow_mut ( ) . add_model_dependencies ( & model) ;
50
+ }
46
51
let file_info = self . get_file_info ( & mut session. sync_odoo ) ;
52
+ file_info. borrow_mut ( ) . replace_diagnostics ( BuildSteps :: VALIDATION , diagnostics) ;
47
53
file_info. borrow_mut ( ) . publish_diagnostics ( session) ;
48
54
}
49
55
50
- pub fn validate_xml_id ( & self , session : & mut SessionInfo , module : & Rc < RefCell < Symbol > > , data : & XmlData , dependencies : & mut Vec < Rc < RefCell < Symbol > > > ) {
51
- let path = data. get_file_symbol ( ) . unwrap ( ) . upgrade ( ) . unwrap ( ) . borrow ( ) . paths ( ) [ 0 ] . clone ( ) ;
52
- let mut file_info = session. sync_odoo . get_file_mgr ( ) . borrow ( ) . get_file_info ( & path) . unwrap ( ) ;
53
- let mut diagnostics = vec ! [ ] ;
56
+ pub fn validate_xml_id ( & self , session : & mut SessionInfo , module : & Rc < RefCell < Symbol > > , data : & XmlData , diagnostics : & mut Vec < Diagnostic > , dependencies : & mut Vec < Rc < RefCell < Symbol > > > , model_dependencies : & mut Vec < Rc < RefCell < Model > > > ) {
57
+ let Some ( xml_file) = data. get_xml_file_symbol ( ) else {
58
+ return ;
59
+ } ;
60
+ let path = xml_file. borrow ( ) . paths ( ) [ 0 ] . clone ( ) ;
54
61
match data {
55
- XmlData :: RECORD ( xml_data_record) => self . validate_record ( session, module, xml_data_record, & mut diagnostics, dependencies) ,
56
- XmlData :: MENUITEM ( xml_data_menu_item) => self . validate_menu_item ( session, module, xml_data_menu_item, & mut diagnostics, dependencies) ,
57
- XmlData :: TEMPLATE ( xml_data_template) => self . validate_template ( session, module, xml_data_template, & mut diagnostics, dependencies) ,
58
- XmlData :: DELETE ( xml_data_delete) => self . validate_delete ( session, module, xml_data_delete, & mut diagnostics, dependencies) ,
59
- XmlData :: ACT_WINDOW ( xml_data_act_window) => self . validate_act_window ( session, module, xml_data_act_window, & mut diagnostics, dependencies) ,
60
- XmlData :: REPORT ( xml_data_report) => self . validate_report ( session, module, xml_data_report, & mut diagnostics, dependencies) ,
62
+ XmlData :: RECORD ( xml_data_record) => self . validate_record ( session, module, xml_data_record, diagnostics, dependencies, model_dependencies ) ,
63
+ XmlData :: MENUITEM ( xml_data_menu_item) => self . validate_menu_item ( session, module, xml_data_menu_item, diagnostics, dependencies, model_dependencies ) ,
64
+ XmlData :: TEMPLATE ( xml_data_template) => self . validate_template ( session, module, xml_data_template, diagnostics, dependencies, model_dependencies ) ,
65
+ XmlData :: DELETE ( xml_data_delete) => self . validate_delete ( session, module, xml_data_delete, diagnostics, dependencies, model_dependencies ) ,
66
+ XmlData :: ACT_WINDOW ( xml_data_act_window) => self . validate_act_window ( session, module, xml_data_act_window, diagnostics, dependencies, model_dependencies ) ,
67
+ XmlData :: REPORT ( xml_data_report) => self . validate_report ( session, module, xml_data_report, diagnostics, dependencies, model_dependencies ) ,
61
68
}
62
- file_info. borrow_mut ( ) . update_validation_diagnostics ( HashMap :: from ( [ ( BuildSteps :: VALIDATION , diagnostics) ] ) ) ;
63
69
}
64
70
65
- fn validate_record ( & self , session : & mut SessionInfo , module : & Rc < RefCell < Symbol > > , xml_data_record : & XmlDataRecord , diagnostics : & mut Vec < Diagnostic > , dependencies : & mut Vec < Rc < RefCell < Symbol > > > ) {
66
- let mut model_ok = false ;
67
- let model = session. sync_odoo . models . get ( & xml_data_record. model . 0 ) . cloned ( ) ;
68
- if let Some ( model) = model {
69
- self . xml_symbol . borrow_mut ( ) . add_model_dependencies ( & model) ;
70
- for main_sym in model. borrow ( ) . get_main_symbols ( session, Some ( module. clone ( ) ) ) . iter ( ) {
71
- model_ok = true ;
72
- dependencies. push ( main_sym. borrow ( ) . get_file ( ) . unwrap ( ) . upgrade ( ) . unwrap ( ) ) ;
73
- }
74
- } else {
71
+ fn validate_record ( & self , session : & mut SessionInfo , module : & Rc < RefCell < Symbol > > , xml_data_record : & XmlDataRecord , diagnostics : & mut Vec < Diagnostic > , dependencies : & mut Vec < Rc < RefCell < Symbol > > > , model_dependencies : & mut Vec < Rc < RefCell < Model > > > ) {
72
+ let Some ( model) = session. sync_odoo . models . get ( & xml_data_record. model . 0 ) . cloned ( ) else {
75
73
//TODO register to not_found_models
76
- }
77
- if !model_ok {
78
- diagnostics . push ( Diagnostic {
79
- range : Range :: new ( Position :: new ( xml_data_record . model . 1 . start . try_into ( ) . unwrap ( ) , 0 ) , Position :: new ( xml_data_record . model . 1 . end . try_into ( ) . unwrap ( ) , 0 ) ) ,
80
- severity : Some ( lsp_types :: DiagnosticSeverity :: ERROR ) ,
81
- message : format ! ( "Model '{}' not found in module '{}'" , xml_data_record. model. 0 , module. borrow( ) . name( ) ) ,
82
- source : Some ( "OdooLS" . to_string ( ) ) ,
83
- .. Default :: default ( )
84
- } ) ;
74
+ diagnostics . push ( Diagnostic :: new (
75
+ Range :: new ( Position :: new ( xml_data_record . model . 1 . start . try_into ( ) . unwrap ( ) , 0 ) , Position :: new ( xml_data_record . model . 1 . end . try_into ( ) . unwrap ( ) , 0 ) ) ,
76
+ Some ( lsp_types :: DiagnosticSeverity :: ERROR ) ,
77
+ Some ( lsp_types :: NumberOrString :: String ( S ! ( "OLS30450" ) ) ) ,
78
+ Some ( EXTENSION_NAME . to_string ( ) ) ,
79
+ format ! ( "Model '{}' not found in module '{}'" , xml_data_record. model. 0 , module. borrow( ) . name( ) ) ,
80
+ None ,
81
+ None
82
+ ) ) ;
85
83
info ! ( "Model '{}' not found in module '{}'" , xml_data_record. model. 0 , module. borrow( ) . name( ) ) ;
84
+ return ;
85
+ } ;
86
+ model_dependencies. push ( model. clone ( ) ) ;
87
+ let main_symbols = model. borrow ( ) . get_main_symbols ( session, Some ( module. clone ( ) ) ) ;
88
+ for main_sym in main_symbols. iter ( ) {
89
+ dependencies. push ( main_sym. borrow ( ) . get_file ( ) . unwrap ( ) . upgrade ( ) . unwrap ( ) ) ;
90
+ }
91
+ let mut all_fields = HashMap :: new ( ) ;
92
+ Symbol :: all_members ( & main_symbols[ 0 ] , session, & mut all_fields, true , true , false , Some ( module. clone ( ) ) , & mut None , false ) ;
93
+ for field in & xml_data_record. fields {
94
+ let declared_field = all_fields. get ( & field. name ) ;
95
+ if let Some ( declared_field) = declared_field {
96
+ //TODO Check type
97
+ } else {
98
+
99
+ diagnostics. push ( Diagnostic :: new (
100
+ Range :: new ( Position :: new ( field. range . start . try_into ( ) . unwrap ( ) , 0 ) , Position :: new ( field. range . end . try_into ( ) . unwrap ( ) , 0 ) ) ,
101
+ Some ( lsp_types:: DiagnosticSeverity :: ERROR ) ,
102
+ Some ( lsp_types:: NumberOrString :: String ( S ! ( "OLS30451" ) ) ) ,
103
+ Some ( EXTENSION_NAME . to_string ( ) ) ,
104
+ format ! ( "Field '{}' not found in model '{}'" , field. name, xml_data_record. model. 0 ) ,
105
+ None ,
106
+ None
107
+ ) ) ;
108
+ }
86
109
}
87
110
}
88
111
89
- fn validate_menu_item ( & self , session : & mut SessionInfo , module : & Rc < RefCell < Symbol > > , xml_data_menu_item : & XmlDataMenuItem , diagnostics : & mut Vec < Diagnostic > , dependencies : & mut Vec < Rc < RefCell < Symbol > > > ) {
112
+ fn validate_menu_item ( & self , session : & mut SessionInfo , module : & Rc < RefCell < Symbol > > , xml_data_menu_item : & XmlDataMenuItem , diagnostics : & mut Vec < Diagnostic > , dependencies : & mut Vec < Rc < RefCell < Symbol > > > , model_dependencies : & mut Vec < Rc < RefCell < Model > > > ) {
90
113
91
114
}
92
115
93
- fn validate_template ( & self , session : & mut SessionInfo , module : & Rc < RefCell < Symbol > > , xml_data_template : & XmlDataTemplate , diagnostics : & mut Vec < Diagnostic > , dependencies : & mut Vec < Rc < RefCell < Symbol > > > ) {
116
+ fn validate_template ( & self , session : & mut SessionInfo , module : & Rc < RefCell < Symbol > > , xml_data_template : & XmlDataTemplate , diagnostics : & mut Vec < Diagnostic > , dependencies : & mut Vec < Rc < RefCell < Symbol > > > , model_dependencies : & mut Vec < Rc < RefCell < Model > > > ) {
94
117
95
118
}
96
119
97
- fn validate_delete ( & self , session : & mut SessionInfo , module : & Rc < RefCell < Symbol > > , xml_data_delete : & XmlDataDelete , diagnostics : & mut Vec < Diagnostic > , dependencies : & mut Vec < Rc < RefCell < Symbol > > > ) {
120
+ fn validate_delete ( & self , session : & mut SessionInfo , module : & Rc < RefCell < Symbol > > , xml_data_delete : & XmlDataDelete , diagnostics : & mut Vec < Diagnostic > , dependencies : & mut Vec < Rc < RefCell < Symbol > > > , model_dependencies : & mut Vec < Rc < RefCell < Model > > > ) {
98
121
99
122
}
100
123
101
- fn validate_act_window ( & self , session : & mut SessionInfo , module : & Rc < RefCell < Symbol > > , xml_data_act_window : & XmlDataActWindow , diagnostics : & mut Vec < Diagnostic > , dependencies : & mut Vec < Rc < RefCell < Symbol > > > ) {
124
+ fn validate_act_window ( & self , session : & mut SessionInfo , module : & Rc < RefCell < Symbol > > , xml_data_act_window : & XmlDataActWindow , diagnostics : & mut Vec < Diagnostic > , dependencies : & mut Vec < Rc < RefCell < Symbol > > > , model_dependencies : & mut Vec < Rc < RefCell < Model > > > ) {
102
125
103
126
}
104
127
105
- fn validate_report ( & self , session : & mut SessionInfo , module : & Rc < RefCell < Symbol > > , xml_data_report : & XmlDataReport , diagnostics : & mut Vec < Diagnostic > , dependencies : & mut Vec < Rc < RefCell < Symbol > > > ) {
128
+ fn validate_report ( & self , session : & mut SessionInfo , module : & Rc < RefCell < Symbol > > , xml_data_report : & XmlDataReport , diagnostics : & mut Vec < Diagnostic > , dependencies : & mut Vec < Rc < RefCell < Symbol > > > , model_dependencies : & mut Vec < Rc < RefCell < Model > > > ) {
106
129
107
130
}
108
131
}
0 commit comments