fix(#2216): consider words in user dictionary to be of the user dialect for wasm (#2223)
Some checks are pending
Binaries / harper-cli - macOS-aarch64 (push) Waiting to run
Binaries / harper-cli - Linux-aarch64-GNU (push) Waiting to run
Binaries / harper-cli - Linux-aarch64-musl (push) Waiting to run
Binaries / harper-cli - macOS-x86_64 (push) Waiting to run
Binaries / harper-cli - Linux-x86_64-GNU (push) Waiting to run
Binaries / harper-cli - Linux-x86_64-musl (push) Waiting to run
Binaries / harper-cli - Windows-x86_64 (push) Waiting to run
Binaries / harper-ls - macOS-aarch64 (push) Waiting to run
Binaries / harper-ls - Linux-aarch64-GNU (push) Waiting to run
Binaries / harper-ls - Linux-aarch64-musl (push) Waiting to run
Binaries / harper-ls - macOS-x86_64 (push) Waiting to run
Binaries / harper-ls - Linux-x86_64-GNU (push) Waiting to run
Binaries / harper-ls - Linux-x86_64-musl (push) Waiting to run
Binaries / harper-ls - Windows-x86_64 (push) Waiting to run
Build Web / build-web (push) Waiting to run
Chrome Plugin / chrome-plugin (push) Waiting to run
Just Checks / just check-js (push) Waiting to run
Just Checks / just check-rust (push) Waiting to run
Just Checks / just test-chrome-plugin (push) Waiting to run
Just Checks / just test-firefox-plugin (push) Waiting to run
Just Checks / just test-harperjs (push) Waiting to run
Just Checks / just test-obsidian (push) Waiting to run
Just Checks / just test-rust (push) Waiting to run
Just Checks / just test-vscode (push) Waiting to run
VS Code Plugin / alpine-arm64 (push) Waiting to run
VS Code Plugin / alpine-x64 (push) Waiting to run
VS Code Plugin / darwin-arm64 (push) Waiting to run
VS Code Plugin / darwin-x64 (push) Waiting to run
VS Code Plugin / linux-arm64 (push) Waiting to run
VS Code Plugin / linux-armhf (push) Waiting to run
VS Code Plugin / linux-x64 (push) Waiting to run
VS Code Plugin / win32-arm64 (push) Waiting to run
VS Code Plugin / win32-x64 (push) Waiting to run
WordPress Plugin / wp-plugin (push) Waiting to run

This commit is contained in:
Grant Lemons 2025-11-20 17:23:58 -07:00 committed by GitHub
parent eac891213f
commit fac069997b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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());
}
}