File tree Expand file tree Collapse file tree 5 files changed +39
-2
lines changed Expand file tree Collapse file tree 5 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -375,6 +375,27 @@ impl CodebookConfig {
375
375
Ok ( true )
376
376
}
377
377
378
+ /// Add a file to the ignore list
379
+ pub fn add_ignore ( & self , file : & str ) -> Result < bool , io:: Error > {
380
+ {
381
+ let mut project_settings = self . project_settings . write ( ) . unwrap ( ) ;
382
+ let file = file. to_string ( ) ;
383
+ // Check if file already exists
384
+ if project_settings. ignore_paths . contains ( & file) {
385
+ return Ok ( false ) ;
386
+ }
387
+
388
+ // Add the file
389
+ project_settings. ignore_paths . push ( file) ;
390
+ // Sort/dedup for consistency
391
+ project_settings. ignore_paths . sort ( ) ;
392
+ project_settings. ignore_paths . dedup ( ) ;
393
+ }
394
+ self . recalculate_effective_settings ( ) ;
395
+
396
+ Ok ( true )
397
+ }
398
+
378
399
/// Save the project configuration to its file
379
400
pub fn save ( & self ) -> Result < ( ) , io:: Error > {
380
401
let project_config_path = match self . project_config_path . as_ref ( ) {
Original file line number Diff line number Diff line change @@ -35,6 +35,11 @@ impl Codebook {
35
35
language : Option < queries:: LanguageType > ,
36
36
file_path : Option < & str > ,
37
37
) -> Vec < parser:: WordLocation > {
38
+ if file_path. is_some ( ) {
39
+ if self . config . should_ignore_path ( file_path. unwrap ( ) ) {
40
+ return Vec :: new ( ) ;
41
+ }
42
+ }
38
43
// get needed dictionary names
39
44
// get needed dictionaries
40
45
// call spell check on each dictionary
@@ -102,7 +107,7 @@ impl Codebook {
102
107
pub fn spell_check_file ( & self , path : & str ) -> Vec < WordLocation > {
103
108
let lang_type = queries:: get_language_name_from_filename ( path) ;
104
109
let file_text = std:: fs:: read_to_string ( path) . unwrap ( ) ;
105
- return self . spell_check ( & file_text, Some ( lang_type) , None ) ;
110
+ return self . spell_check ( & file_text, Some ( lang_type) , Some ( & path ) ) ;
106
111
}
107
112
108
113
pub fn get_suggestions ( & self , word : & str ) -> Option < Vec < String > > {
Original file line number Diff line number Diff line change @@ -10,6 +10,14 @@ fn example_file_path(file: &str) -> String {
10
10
format ! ( "tests/examples/{}" , file)
11
11
}
12
12
13
+ #[ test]
14
+ fn test_ignore_file ( ) {
15
+ utils:: init_logging ( ) ;
16
+ let processor = utils:: get_processor ( ) ;
17
+ let results = processor. spell_check ( "badword" , None , Some ( "ignore.txt" ) ) ;
18
+ assert_eq ! ( results. len( ) , 0 ) ;
19
+ }
20
+
13
21
#[ test]
14
22
fn test_example_files_word_locations ( ) {
15
23
utils:: init_logging ( ) ;
Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ use codebook::Codebook;
4
4
5
5
pub fn get_processor ( ) -> Codebook {
6
6
let config = Arc :: new ( codebook_config:: CodebookConfig :: default ( ) ) ;
7
+ config
8
+ . add_ignore ( "**/ignore.txt" )
9
+ . expect ( "Should ignore file" ) ;
7
10
let dict = Codebook :: new ( config) . unwrap ( ) ;
8
11
dict
9
12
}
Original file line number Diff line number Diff line change 1
1
{
2
2
"compilerOptions" : {
3
- // Enable latest features
3
+ // Enable latest featurez
4
4
"lib" : [" ESNext" , " DOM" ],
5
5
"target" : " ESNext" ,
6
6
"module" : " ESNext" ,
You can’t perform that action at this time.
0 commit comments