Skip to content

Commit

Permalink
fix(dict): Mirror original case for custom dict
Browse files Browse the repository at this point in the history
Fixes #781
  • Loading branch information
epage committed Dec 13, 2023
1 parent 86c4c9f commit 55d802d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions crates/typos-cli/src/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,27 +284,30 @@ impl<'i, 'w, D: typos::Dictionary> typos::Dictionary for Override<'i, 'w, D> {
self.inner.correct_ident(ident)
}

fn correct_word<'s>(&'s self, word: typos::tokens::Word<'_>) -> Option<Status<'s>> {
if word.case() == typos::tokens::Case::None {
fn correct_word<'s>(&'s self, word_token: typos::tokens::Word<'_>) -> Option<Status<'s>> {
if word_token.case() == typos::tokens::Case::None {
return None;
}

for ignored in &self.ignored_words {
if ignored.is_match(word.token()) {
if ignored.is_match(word_token.token()) {
return Some(Status::Valid);
}
}

// Skip hashing if we can
if !self.words.is_empty() {
let w = UniCase::new(word.token());
let w = UniCase::new(word_token.token());
// HACK: couldn't figure out the lifetime issue with replacing `cloned` with `borrow`
if let Some(status) = self.words.get(&w).cloned() {
return Some(status);
if let Some(mut corrections) = self.words.get(&w).cloned() {
for s in corrections.corrections_mut() {
case_correct(s, word_token.case())
}
return Some(corrections);
}
}

self.inner.correct_word(word)
self.inner.correct_word(word_token)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/typos-cli/tests/cmd/extend-words-case.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ args = ""
status.code = 2
stdin = ""
stdout = """
error: `Trailling` should be `trailing`
error: `Trailling` should be `Trailing`
--> ./file.txt:1:26
|
1 | public function noErrorOnTraillingSemicolonAndWhitespace(Connection $connection)
Expand Down

0 comments on commit 55d802d

Please sign in to comment.