Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix(#2216): consider words in user dictionary to be of the user dialect for wasm (#2223)

Grant Lemonsfac069997b5e
diff --git a/harper-wasm/src/lib.rs b/harper-wasm/src/lib.rs
index f257c542b..bdb8ecc31 100644
--- a/harper-wasm/src/lib.rs
+++ b/harper-wasm/src/lib.rs
@@ -4,6 +4,7 @@ use std::convert::Into;
use std::io::Cursor;
use std::sync::Arc;
+use harper_core::dict_word_metadata::DialectFlags;
use harper_core::language_detection::is_doc_likely_english;
use harper_core::linting::{LintGroup, Linter as _};
use harper_core::parsers::{IsolateEnglish, Markdown, Parser, PlainEnglish};
@@ -131,7 +132,7 @@ impl Linter {
let mut lint_dict = MergedDictionary::new();
lint_dict.add_dictionary(FstDictionary::curated());
- lint_dict.add_dictionary(Arc::new(user_dictionary.clone()));
+ lint_dict.add_dictionary(Arc::new(user_dictionary));
Arc::new(lint_dict)
}
@@ -350,7 +351,10 @@ impl Linter {
.extend_words(additional_words.iter().map(|word| {
(
word.chars().collect::<CharString>(),
- DictWordMetadata::default(),
+ DictWordMetadata {
+ dialects: DialectFlags::from_dialect(self.dialect.into()),
+ ..Default::default()
+ },
)
}));
@@ -621,3 +625,22 @@ pub struct OrganizedGroup {
#[wasm_bindgen(getter_with_clone)]
pub lints: Vec<Lint>,
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// If a word from another dialect is added to the user dictionary, it should be considered
+ /// part of the user's dialect as well.
+ #[test]
+ fn issue_2216() {
+ let text = "Aeon".to_owned();
+ let mut linter = Linter::new(Dialect::American);
+
+ linter.import_words(vec![text.clone()]);
+ dbg!(linter.dictionary.get_word_metadata_str(&text));
+
+ let lints = linter.lint(text, Language::Plain);
+ assert!(lints.is_empty());
+ }
+}