@@ -89,6 +89,8 @@ pub struct FileInfo {
8989 pub noqas_blocs : HashMap < u32 , NoqaInfo > ,
9090 noqas_lines : HashMap < u32 , NoqaInfo > ,
9191 diagnostic_filters : Vec < DiagnosticFilter > ,
92+
93+ pub diag_test_comments : Vec < ( u32 , Vec < String > ) > , //for tests: line and list of codes
9294}
9395
9496impl FileInfo {
@@ -109,6 +111,7 @@ impl FileInfo {
109111 noqas_blocs : HashMap :: new ( ) ,
110112 noqas_lines : HashMap :: new ( ) ,
111113 diagnostic_filters : Vec :: new ( ) ,
114+ diag_test_comments : vec ! [ ] ,
112115 }
113116 }
114117 pub fn update ( & mut self , session : & mut SessionInfo , uri : & str , content : Option < & Vec < TextDocumentContentChangeEvent > > , version : Option < i32 > , in_workspace : bool , force : bool ) -> bool {
@@ -191,7 +194,7 @@ impl FileInfo {
191194 if in_workspace {
192195 self . noqas_blocs . clear ( ) ;
193196 self . noqas_lines . clear ( ) ;
194- self . extract_tokens ( & parsed_module, & source) ;
197+ self . extract_tokens ( & parsed_module, & source, session . sync_odoo . test_mode ) ;
195198 }
196199 self . valid = true ;
197200 for error in parsed_module. errors ( ) . iter ( ) {
@@ -229,7 +232,7 @@ impl FileInfo {
229232 self . _build_ast ( session, session. sync_odoo . get_file_mgr ( ) . borrow ( ) . is_in_workspace ( & self . uri ) ) ;
230233 }
231234
232- pub fn extract_tokens ( & mut self , parsed_module : & Parsed < ModModule > , source : & String ) {
235+ pub fn extract_tokens ( & mut self , parsed_module : & Parsed < ModModule > , source : & String , parse_test_comments : bool ) {
233236 let mut is_first_expr: bool = true ;
234237 let mut noqa_to_add = None ;
235238 let mut previous_token: Option < & Token > = None ;
@@ -269,6 +272,14 @@ impl FileInfo {
269272 }
270273 }
271274 }
275+ if parse_test_comments {
276+ if text. starts_with ( "#OLS" ) || text. starts_with ( "# OLS" ) {
277+ let codes = text. split ( "," ) . map ( |s| s. trim ( ) . trim_start_matches ( '#' ) . trim ( ) . to_string ( ) ) . collect :: < Vec < String > > ( ) ;
278+ let char = self . file_info_ast . borrow ( ) . text_rope . as_ref ( ) . unwrap ( ) . try_byte_to_char ( token. start ( ) . to_usize ( ) ) . expect ( "unable to get char from bytes" ) ;
279+ let line = self . file_info_ast . borrow ( ) . text_rope . as_ref ( ) . unwrap ( ) . try_char_to_line ( char) . ok ( ) . expect ( "unable to get line from char" ) ;
280+ self . diag_test_comments . push ( ( line as u32 , codes) ) ;
281+ }
282+ }
272283 } ,
273284 TokenKind :: Class | TokenKind :: Def => {
274285 if noqa_to_add. is_some ( ) {
0 commit comments