@@ -10,6 +10,7 @@ use std::hash::{Hash, Hasher};
10
10
use std:: path:: PathBuf ;
11
11
use std:: str:: FromStr ;
12
12
use std:: { collections:: HashMap , fs} ;
13
+ use crate :: core:: config:: DiagnosticFilter ;
13
14
use crate :: core:: diagnostics:: { create_diagnostic, DiagnosticCode , DiagnosticSetting } ;
14
15
use crate :: threads:: SessionInfo ;
15
16
use crate :: utils:: PathSanitizer ;
@@ -72,6 +73,7 @@ pub struct FileInfo {
72
73
diagnostics : HashMap < BuildSteps , Vec < Diagnostic > > ,
73
74
pub noqas_blocs : HashMap < u32 , NoqaInfo > ,
74
75
noqas_lines : HashMap < u32 , NoqaInfo > ,
76
+ diagnostic_filters : Vec < DiagnosticFilter > ,
75
77
}
76
78
77
79
impl FileInfo {
@@ -91,6 +93,7 @@ impl FileInfo {
91
93
diagnostics : HashMap :: new ( ) ,
92
94
noqas_blocs : HashMap :: new ( ) ,
93
95
noqas_lines : HashMap :: new ( ) ,
96
+ diagnostic_filters : Vec :: new ( ) ,
94
97
}
95
98
}
96
99
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 {
287
290
diagnostic. range . end = self . offset_to_position ( diagnostic. range . end . line as usize ) ;
288
291
diagnostic
289
292
}
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
+ }
290
298
291
299
pub fn publish_diagnostics ( & mut self , session : & mut SessionInfo ) {
292
300
if self . need_push {
@@ -319,11 +327,7 @@ impl FileInfo {
319
327
}
320
328
}
321
329
}
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 ( ) {
327
331
if !filter. codes . is_empty ( ) {
328
332
// we pass the filter if we do not have code, or does it not match the filter
329
333
let Some ( updated_code) = & updated. code else {
@@ -488,7 +492,11 @@ impl FileMgr {
488
492
}
489
493
490
494
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
+ } ) ;
492
500
let return_info = file_info. clone ( ) ;
493
501
//Do not modify the file if a version is not given but the file is opened
494
502
let mut updated: bool = false ;
@@ -500,6 +508,12 @@ impl FileMgr {
500
508
( updated, return_info)
501
509
}
502
510
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
+
503
517
pub fn delete_path ( session : & mut SessionInfo , uri : & String ) {
504
518
//delete all files that are the uri or in subdirectory
505
519
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