Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(fst-dict): add Sync to words_iter dynamic return type
Grant Lemons6ddc83c75790
diff --git a/harper-core/src/spell/dictionary.rs b/harper-core/src/spell/dictionary.rsindex c62cabbe0..4d98ac13f 100644--- a/harper-core/src/spell/dictionary.rs+++ b/harper-core/src/spell/dictionary.rs@@ -70,8 +70,8 @@ pub trait Dictionary: Send + Sync {fn get_word_metadata_str(&self, word: &str) -> WordMetadata;/// Iterate over the words in the dictionary.- fn words_iter(&self) -> Box<dyn Iterator<Item = &'_ [char]> + '_>;+ fn words_iter(&self) -> Box<dyn Iterator<Item = &'_ [char]> + Send + '_>;/// Iterate over all the words in the dictionary of a given length- fn words_with_len_iter(&self, len: usize) -> Box<dyn Iterator<Item = &'_ [char]> + '_>;+ fn words_with_len_iter(&self, len: usize) -> Box<dyn Iterator<Item = &'_ [char]> + Send + '_>;}diff --git a/harper-core/src/spell/fst_dictionary.rs b/harper-core/src/spell/fst_dictionary.rsindex f3274da1c..95a6b5f90 100644--- a/harper-core/src/spell/fst_dictionary.rs+++ b/harper-core/src/spell/fst_dictionary.rs@@ -110,11 +110,11 @@ impl Dictionary for FstDictionary {.collect()}- fn words_iter(&self) -> Box<dyn Iterator<Item = &'_ [char]> + '_> {+ fn words_iter(&self) -> Box<dyn Iterator<Item = &'_ [char]> + Send + '_> {self.full_dict.words_iter()}- fn words_with_len_iter(&self, len: usize) -> Box<dyn Iterator<Item = &'_ [char]> + '_> {+ fn words_with_len_iter(&self, len: usize) -> Box<dyn Iterator<Item = &'_ [char]> + Send + '_> {self.full_dict.words_with_len_iter(len)}}diff --git a/harper-core/src/spell/full_dictionary.rs b/harper-core/src/spell/full_dictionary.rsindex fca80dd8c..6662dfd97 100644--- a/harper-core/src/spell/full_dictionary.rs+++ b/harper-core/src/spell/full_dictionary.rs@@ -103,10 +103,10 @@ impl FullDictionary {/// list. NOTE: This function will sort the original word list by its/// length. If the word list's order is changed after creating the/// lookup, it will no longer be valid.- fn create_len_starts(words: &Vec<CharString>) -> Vec<usize> {- let mut len_words = words.clone();-+ fn create_len_starts(words: &[CharString]) -> Vec<usize> {+ let mut len_words: Vec<_> = words.to_vec();len_words.sort_by_key(|a| a.len());+let mut word_len_starts = vec![0, 0];for (index, len) in len_words.iter().map(SmallVec::len).enumerate() {@@ -235,11 +235,11 @@ impl Dictionary for FullDictionary {self.fuzzy_match(&word, max_distance, max_results)}- fn words_iter(&self) -> Box<dyn Iterator<Item = &'_ [char]> + '_> {+ fn words_iter(&self) -> Box<dyn Iterator<Item = &'_ [char]> + Send + '_> {Box::new(self.words.iter().map(|v| v.as_slice()))}- fn words_with_len_iter(&self, len: usize) -> Box<dyn Iterator<Item = &'_ [char]> + '_> {+ fn words_with_len_iter(&self, len: usize) -> Box<dyn Iterator<Item = &'_ [char]> + Send + '_> {if len == 0 || len >= self.word_len_starts.len() {return Box::new(std::iter::empty());}diff --git a/harper-core/src/spell/merged_dictionary.rs b/harper-core/src/spell/merged_dictionary.rsindex 648fed17d..13deee789 100644--- a/harper-core/src/spell/merged_dictionary.rs+++ b/harper-core/src/spell/merged_dictionary.rs@@ -58,11 +58,11 @@ impl Dictionary for MergedDictionary {found_metadata}- fn words_iter(&self) -> Box<dyn Iterator<Item = &'_ [char]> + '_> {+ fn words_iter(&self) -> Box<dyn Iterator<Item = &'_ [char]> + Send + '_> {Box::new(self.children.iter().flat_map(|c| c.words_iter()))}- fn words_with_len_iter(&self, len: usize) -> Box<dyn Iterator<Item = &'_ [char]> + '_> {+ fn words_with_len_iter(&self, len: usize) -> Box<dyn Iterator<Item = &'_ [char]> + Send + '_> {Box::new(self.children.iter()diff --git a/harper-ls/src/backend.rs b/harper-ls/src/backend.rsindex ed82648cc..533729ce1 100644--- a/harper-ls/src/backend.rs+++ b/harper-ls/src/backend.rs@@ -198,7 +198,7 @@ impl Backend {}Some(Box::new(CollapseIdentifiers::new(Box::new(ts_parser),- &doc_state.dict,+ Box::new(doc_state.dict.clone()),)))} else {Some(Box::new(ts_parser))