@@ -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 , OYarn , SymType , DEBUG_STEPS , EXTENSION_NAME } , core:: { entry_point:: { EntryPoint , EntryPointType } , evaluation:: ContextValue , file_mgr:: FileInfo , model:: Model , odoo:: SyncOdoo , symbols:: symbol:: Symbol , xml_data:: { XmlData , XmlDataDelete , XmlDataMenuItem , XmlDataRecord , XmlDataTemplate } } , threads:: SessionInfo , Sy , S } ;
6
+ use crate :: { constants:: { BuildSteps , OYarn , SymType , DEBUG_STEPS , EXTENSION_NAME } , core:: { diagnostics :: { create_diagnostic , DiagnosticCode } , entry_point:: { EntryPoint , EntryPointType } , evaluation:: ContextValue , file_mgr:: FileInfo , model:: Model , odoo:: SyncOdoo , symbols:: symbol:: Symbol , xml_data:: { XmlData , XmlDataDelete , XmlDataMenuItem , XmlDataRecord , XmlDataTemplate } } , threads:: SessionInfo , Sy , S } ;
7
7
8
8
9
9
@@ -69,15 +69,12 @@ impl XmlValidator {
69
69
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 > > > ) {
70
70
let Some ( model) = session. sync_odoo . models . get ( & xml_data_record. model . 0 ) . cloned ( ) else {
71
71
//TODO register to not_found_models
72
- diagnostics. push ( Diagnostic :: new (
73
- 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 ) ) ,
74
- Some ( lsp_types:: DiagnosticSeverity :: ERROR ) ,
75
- Some ( lsp_types:: NumberOrString :: String ( S ! ( "OLS30450" ) ) ) ,
76
- Some ( EXTENSION_NAME . to_string ( ) ) ,
77
- format ! ( "Model '{}' not found in module '{}'" , xml_data_record. model. 0 , module. borrow( ) . name( ) ) ,
78
- None ,
79
- None
80
- ) ) ;
72
+ if let Some ( diagnostic) = create_diagnostic ( session, DiagnosticCode :: OLS05055 , & [ & xml_data_record. model . 0 , module. borrow ( ) . name ( ) ] ) {
73
+ diagnostics. push ( Diagnostic {
74
+ range : Range { start : Position :: new ( xml_data_record. model . 1 . start . try_into ( ) . unwrap ( ) , 0 ) , end : Position :: new ( xml_data_record. model . 1 . end . try_into ( ) . unwrap ( ) , 0 ) } ,
75
+ ..diagnostic. clone ( )
76
+ } ) ;
77
+ }
81
78
info ! ( "Model '{}' not found in module '{}'" , xml_data_record. model. 0 , module. borrow( ) . name( ) ) ;
82
79
return ;
83
80
} ;
@@ -130,31 +127,25 @@ impl XmlValidator {
130
127
main_sym = model. borrow ( ) . get_main_symbols ( session, from_module) ;
131
128
}
132
129
if main_sym. is_empty ( ) {
133
- diagnostics. push ( Diagnostic :: new (
134
- Range :: new ( Position :: new ( field. text_range . as_ref ( ) . unwrap ( ) . start . try_into ( ) . unwrap ( ) , 0 ) , Position :: new ( field. text_range . as_ref ( ) . unwrap ( ) . end . try_into ( ) . unwrap ( ) , 0 ) ) ,
135
- Some ( lsp_types:: DiagnosticSeverity :: ERROR ) ,
136
- Some ( lsp_types:: NumberOrString :: String ( S ! ( "OLS30453" ) ) ) ,
137
- Some ( EXTENSION_NAME . to_string ( ) ) ,
138
- format ! ( "Model '{}' not found" , field. text. as_ref( ) . unwrap( ) ) ,
139
- None ,
140
- None
141
- ) )
130
+ if let Some ( diagnostic) = create_diagnostic ( session, DiagnosticCode :: OLS05056 , & [ & field. text . as_ref ( ) . unwrap ( ) ] ) {
131
+ diagnostics. push ( Diagnostic {
132
+ range : Range { start : Position :: new ( field. text_range . as_ref ( ) . unwrap ( ) . start . try_into ( ) . unwrap ( ) , 0 ) , end : Position :: new ( field. text_range . as_ref ( ) . unwrap ( ) . end . try_into ( ) . unwrap ( ) , 0 ) } ,
133
+ ..diagnostic. clone ( )
134
+ } ) ;
135
+ }
142
136
}
143
137
}
144
138
} ,
145
139
_ => { }
146
140
}
147
141
//TODO check type
148
142
} else {
149
- diagnostics. push ( Diagnostic :: new (
150
- Range :: new ( Position :: new ( field. range . start . try_into ( ) . unwrap ( ) , 0 ) , Position :: new ( field. range . end . try_into ( ) . unwrap ( ) , 0 ) ) ,
151
- Some ( lsp_types:: DiagnosticSeverity :: ERROR ) ,
152
- Some ( lsp_types:: NumberOrString :: String ( S ! ( "OLS30451" ) ) ) ,
153
- Some ( EXTENSION_NAME . to_string ( ) ) ,
154
- format ! ( "Field '{}' not found in model '{}'" , field. name, xml_data_record. model. 0 ) ,
155
- None ,
156
- None
157
- ) ) ;
143
+ if let Some ( diagnostic) = create_diagnostic ( session, DiagnosticCode :: OLS05057 , & [ & field. name , & xml_data_record. model . 0 ] ) {
144
+ diagnostics. push ( Diagnostic {
145
+ range : Range { start : Position :: new ( field. range . start . try_into ( ) . unwrap ( ) , 0 ) , end : Position :: new ( field. range . end . try_into ( ) . unwrap ( ) , 0 ) } ,
146
+ ..diagnostic. clone ( )
147
+ } ) ;
148
+ }
158
149
}
159
150
}
160
151
//Diagnostic if some mandatory fields are not detected
0 commit comments