Skip to content

Commit 55d802d

Browse files
committed
fix(dict): Mirror original case for custom dict
Fixes #781
1 parent 86c4c9f commit 55d802d

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

crates/typos-cli/src/dict.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,27 +284,30 @@ impl<'i, 'w, D: typos::Dictionary> typos::Dictionary for Override<'i, 'w, D> {
284284
self.inner.correct_ident(ident)
285285
}
286286

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

292292
for ignored in &self.ignored_words {
293-
if ignored.is_match(word.token()) {
293+
if ignored.is_match(word_token.token()) {
294294
return Some(Status::Valid);
295295
}
296296
}
297297

298298
// Skip hashing if we can
299299
if !self.words.is_empty() {
300-
let w = UniCase::new(word.token());
300+
let w = UniCase::new(word_token.token());
301301
// HACK: couldn't figure out the lifetime issue with replacing `cloned` with `borrow`
302-
if let Some(status) = self.words.get(&w).cloned() {
303-
return Some(status);
302+
if let Some(mut corrections) = self.words.get(&w).cloned() {
303+
for s in corrections.corrections_mut() {
304+
case_correct(s, word_token.case())
305+
}
306+
return Some(corrections);
304307
}
305308
}
306309

307-
self.inner.correct_word(word)
310+
self.inner.correct_word(word_token)
308311
}
309312
}
310313

crates/typos-cli/tests/cmd/extend-words-case.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ args = ""
33
status.code = 2
44
stdin = ""
55
stdout = """
6-
error: `Trailling` should be `trailing`
6+
error: `Trailling` should be `Trailing`
77
--> ./file.txt:1:26
88
|
99
1 | public function noErrorOnTraillingSemicolonAndWhitespace(Connection $connection)

0 commit comments

Comments
 (0)