@@ -10,6 +10,7 @@ use std::hash::{Hash, Hasher};
1010use std:: path:: PathBuf ;
1111use std:: str:: FromStr ;
1212use std:: { collections:: HashMap , fs} ;
13+ use crate :: core:: config:: DiagnosticFilter ;
1314use crate :: core:: diagnostics:: { create_diagnostic, DiagnosticCode , DiagnosticSetting } ;
1415use crate :: threads:: SessionInfo ;
1516use crate :: utils:: PathSanitizer ;
@@ -72,6 +73,7 @@ pub struct FileInfo {
7273 diagnostics : HashMap < BuildSteps , Vec < Diagnostic > > ,
7374 pub noqas_blocs : HashMap < u32 , NoqaInfo > ,
7475 noqas_lines : HashMap < u32 , NoqaInfo > ,
76+ diagnostic_filters : Vec < DiagnosticFilter > ,
7577}
7678
7779impl FileInfo {
@@ -91,6 +93,7 @@ impl FileInfo {
9193 diagnostics : HashMap :: new ( ) ,
9294 noqas_blocs : HashMap :: new ( ) ,
9395 noqas_lines : HashMap :: new ( ) ,
96+ diagnostic_filters : Vec :: new ( ) ,
9497 }
9598 }
9699 pub fn update ( & mut self , session : & mut SessionInfo , uri : & str , content : Option < & Vec < TextDocumentContentChangeEvent > > , version : Option < i32 > , in_workspace : bool , force : bool ) -> bool {
@@ -287,6 +290,11 @@ impl FileInfo {
287290 diagnostic. range . end = self . offset_to_position ( diagnostic. range . end . line as usize ) ;
288291 diagnostic
289292 }
293+ pub fn update_diagnostic_filters ( & mut self , session : & SessionInfo ) {
294+ self . diagnostic_filters = session. sync_odoo . config . diagnostic_filters . iter ( ) . cloned ( ) . filter ( |filter| {
295+ ( filter. negation && !filter. paths . matches ( & self . uri ) ) || ( !filter. negation && filter. paths . matches ( & self . uri ) )
296+ } ) . collect :: < Vec < _ > > ( ) ;
297+ }
290298
291299 pub fn publish_diagnostics ( & mut self , session : & mut SessionInfo ) {
292300 if self . need_push {
@@ -319,11 +327,7 @@ impl FileInfo {
319327 }
320328 }
321329 }
322- for filter in & session. sync_odoo . config . diagnostic_filters {
323- // Path match
324- if ( !filter. negation && !filter. paths . matches ( & self . uri ) ) || ( filter. negation && filter. paths . matches ( & self . uri ) ) {
325- continue ;
326- }
330+ for filter in self . diagnostic_filters . iter ( ) {
327331 if !filter. codes . is_empty ( ) {
328332 // we pass the filter if we do not have code, or does it not match the filter
329333 let Some ( updated_code) = & updated. code else {
@@ -488,7 +492,11 @@ impl FileMgr {
488492 }
489493
490494 pub fn update_file_info ( & mut self , session : & mut SessionInfo , uri : & str , content : Option < & Vec < TextDocumentContentChangeEvent > > , version : Option < i32 > , force : bool ) -> ( bool , Rc < RefCell < FileInfo > > ) {
491- let file_info = self . files . entry ( uri. to_string ( ) ) . or_insert_with ( || Rc :: new ( RefCell :: new ( FileInfo :: new ( uri. to_string ( ) ) ) ) ) ;
495+ let file_info = self . files . entry ( uri. to_string ( ) ) . or_insert_with ( || {
496+ let mut file_info = FileInfo :: new ( uri. to_string ( ) ) ;
497+ file_info. update_diagnostic_filters ( session) ;
498+ Rc :: new ( RefCell :: new ( file_info) )
499+ } ) ;
492500 let return_info = file_info. clone ( ) ;
493501 //Do not modify the file if a version is not given but the file is opened
494502 let mut updated: bool = false ;
@@ -500,6 +508,12 @@ impl FileMgr {
500508 ( updated, return_info)
501509 }
502510
511+ pub fn update_all_file_diagnostic_filters ( & mut self , session : & SessionInfo ) {
512+ for file_info in self . files . values ( ) {
513+ file_info. borrow_mut ( ) . update_diagnostic_filters ( session) ;
514+ }
515+ }
516+
503517 pub fn delete_path ( session : & mut SessionInfo , uri : & String ) {
504518 //delete all files that are the uri or in subdirectory
505519 let matching_keys: Vec < String > = session. sync_odoo . get_file_mgr ( ) . borrow_mut ( ) . files . keys ( ) . filter ( |k| PathBuf :: from ( k) . starts_with ( uri) ) . cloned ( ) . collect ( ) ;
0 commit comments