Skip to content

Commit 0542a88

Browse files
committed
Make ignore_paths actually work
1 parent e2b73d3 commit 0542a88

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

crates/codebook-config/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,27 @@ impl CodebookConfig {
375375
Ok(true)
376376
}
377377

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+
378399
/// Save the project configuration to its file
379400
pub fn save(&self) -> Result<(), io::Error> {
380401
let project_config_path = match self.project_config_path.as_ref() {

crates/codebook/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ impl Codebook {
3535
language: Option<queries::LanguageType>,
3636
file_path: Option<&str>,
3737
) -> 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+
}
3843
// get needed dictionary names
3944
// get needed dictionaries
4045
// call spell check on each dictionary
@@ -102,7 +107,7 @@ impl Codebook {
102107
pub fn spell_check_file(&self, path: &str) -> Vec<WordLocation> {
103108
let lang_type = queries::get_language_name_from_filename(path);
104109
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));
106111
}
107112

108113
pub fn get_suggestions(&self, word: &str) -> Option<Vec<String>> {

crates/codebook/tests/test_files.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ fn example_file_path(file: &str) -> String {
1010
format!("tests/examples/{}", file)
1111
}
1212

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+
1321
#[test]
1422
fn test_example_files_word_locations() {
1523
utils::init_logging();

crates/codebook/tests/utils/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ use codebook::Codebook;
44

55
pub fn get_processor() -> Codebook {
66
let config = Arc::new(codebook_config::CodebookConfig::default());
7+
config
8+
.add_ignore("**/ignore.txt")
9+
.expect("Should ignore file");
710
let dict = Codebook::new(config).unwrap();
811
dict
912
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
// Enable latest features
3+
// Enable latest featurez
44
"lib": ["ESNext", "DOM"],
55
"target": "ESNext",
66
"module": "ESNext",

0 commit comments

Comments
 (0)