Skip to content

Commit 19db639

Browse files
committed
Fix bug where duplicate word mispellings were ignored in release builds
1 parent 962977c commit 19db639

3 files changed

Lines changed: 23 additions & 13 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ tree-sitter-swift = "<0.8.0"
6666
tree-sitter-toml-ng = "<0.8.0"
6767
tree-sitter-typescript = "0.23.2"
6868
tree-sitter-yaml = "0.7.2"
69-
tree-sitter-vhdl = { git = "https://github.com/jpt13653903/tree-sitter-vhdl", tag = "v1.3.1" }
69+
tree-sitter-vhdl = "<2"
7070
tree-sitter-zig = "<2"
7171
tree-sitter-c-sharp= "<0.24.0"
7272
codebook-tree-sitter-latex = "<0.7.0"

crates/codebook/src/parser.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,12 @@ fn find_locations_code(
247247
end_byte: global_end,
248248
};
249249
if let Some(existing_result) = word_locations.get_mut(&word_pos.word) {
250-
#[cfg(debug_assertions)]
251-
{
252-
let added = existing_result.insert(location);
253-
if !added {
254-
let word = word_pos.word.clone();
255-
panic!(
256-
"Two of the same locations found. Make a better query. Word: {word}, Location: {location:?}"
257-
)
258-
}
259-
}
250+
let added = existing_result.insert(location);
251+
debug_assert!(
252+
added,
253+
"Two of the same locations found. Make a better query. Word: {}, Location: {:?}",
254+
word_pos.word, location
255+
);
260256
} else {
261257
let mut set = HashSet::new();
262258
set.insert(location);
@@ -408,6 +404,19 @@ mod parser_tests {
408404
}
409405
}
410406

407+
#[test]
408+
fn test_duplicate_word_locations() {
409+
// Use a code language to exercise find_locations_code path
410+
let text = "// wrld foo wrld";
411+
let results = find_locations(text, LanguageType::Rust, |_| false, &[]);
412+
let wrld = results.iter().find(|loc| loc.word == "wrld").unwrap();
413+
assert_eq!(
414+
wrld.locations.len(),
415+
2,
416+
"Expected two locations for repeated word 'wrld'"
417+
);
418+
}
419+
411420
// Something is up with the HTML tree-sitter package
412421
// #[test]
413422
// fn test_spell_checking_with_unicode() {

0 commit comments

Comments
 (0)