Skip to content

Commit 0d75ff4

Browse files
committed
feat: respect ignore ambiguous flag in planner
1 parent 630e257 commit 0d75ff4

File tree

15 files changed

+156
-18
lines changed

15 files changed

+156
-18
lines changed

AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ Exit codes:
151151
6. For file and directory names, detect and schedule renames with depth ordering
152152
7. Emit `plan.json` and fast summary stats
153153

154+
- `--ignore-ambiguous` now prunes ambiguous identifiers (plain words that map to multiple styles) before matching or renaming; make sure new search variants respect this toggle and keep tests in `renamify-core/tests/ignore_ambiguous_test.rs` passing.
155+
154156
- Implementation note: `scan_repository_multi` pre-filters candidate files with an `AhoCorasick` automaton, processes them in parallel via `rayon`, and only runs the expensive compound identifier scan on lines discovered by direct variant hits or token heuristics. When adjusting matching logic, keep the `token_line_hits` bookkeeping in sync with the `additional_lines` fed into `find_enhanced_matches`.
155157

156158
Boundary rules

renamify-cli/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ fn main() {
134134
atomic,
135135
output,
136136
quiet,
137+
styles.ignore_ambiguous,
137138
false, // regex flag - not used in Plan command
138139
)
139140
},
@@ -204,6 +205,7 @@ fn main() {
204205
},
205206
output,
206207
quiet,
208+
styles.ignore_ambiguous,
207209
false, // regex flag - not used in Search command
208210
)
209211
},
@@ -276,6 +278,7 @@ fn main() {
276278
styles.exclude_styles,
277279
styles.include_styles,
278280
styles.only_styles,
281+
styles.ignore_ambiguous,
279282
exclude_match,
280283
exclude_matching_lines,
281284
format,

renamify-cli/src/plan.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub fn handle_plan(
3333
atomic: AtomicArgs,
3434
output: OutputFormat,
3535
quiet: bool,
36+
ignore_ambiguous: bool,
3637
_regex: bool, // TODO: Implement regex mode
3738
) -> Result<()> {
3839
// Error if both preview and JSON output are specified
@@ -109,6 +110,7 @@ pub fn handle_plan(
109110
include_acronyms,
110111
exclude_acronyms,
111112
only_acronyms,
113+
ignore_ambiguous,
112114
None, // working_dir
113115
Some(&atomic_config),
114116
)?;

renamify-cli/src/rename.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub fn handle_rename(
1717
exclude_styles: Vec<StyleArg>,
1818
include_styles: Vec<StyleArg>,
1919
only_styles: Vec<StyleArg>,
20+
ignore_ambiguous: bool,
2021
exclude_match: Vec<String>,
2122
exclude_matching_lines: Option<String>,
2223
preview: Option<PreviewArg>,
@@ -86,6 +87,7 @@ pub fn handle_rename(
8687
&exclude_styles,
8788
&include_styles,
8889
&only_styles,
90+
ignore_ambiguous,
8991
&exclude_match,
9092
exclude_matching_lines.as_ref(),
9193
preview_format.as_ref(),

renamify-cli/src/search.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub fn handle_search(
2828
only_acronyms: Vec<String>,
2929
output: OutputFormat,
3030
quiet: bool,
31+
ignore_ambiguous: bool,
3132
) -> Result<()> {
3233
// Convert CLI style args to core Style enum
3334
let exclude_styles: Vec<Style> = exclude_styles.into_iter().map(Into::into).collect();
@@ -79,7 +80,9 @@ pub fn handle_search(
7980
include_acronyms,
8081
exclude_acronyms,
8182
only_acronyms,
83+
ignore_ambiguous,
8284
None, // working_dir
85+
None, // atomic_config
8386
)?;
8487

8588
// Handle output based on format

renamify-cli/tests/cli_tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ fn test_plan_command_basic() {
9595
vec![], // include_acronyms
9696
vec![], // exclude_acronyms
9797
vec![], // only_acronyms
98+
false, // ignore_ambiguous
9899
Some(temp_dir.path()), // working_dir
99100
None, // atomic_config
100101
)
@@ -142,6 +143,7 @@ fn test_plan_command_with_styles() {
142143
vec![], // include_acronyms
143144
vec![], // exclude_acronyms
144145
vec![], // only_acronyms
146+
false, // ignore_ambiguous
145147
Some(temp_dir.path()), // working_dir
146148
None, // atomic_config
147149
)
@@ -185,6 +187,7 @@ fn test_plan_command_with_styles() {
185187
vec![], // include_acronyms
186188
vec![], // exclude_acronyms
187189
vec![], // only_acronyms
190+
false, // ignore_ambiguous
188191
Some(temp_dir.path()), // working_dir
189192
None, // atomic_config
190193
)

renamify-cli/tests/train_case_e2e_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ The Rename-Tool-Based-Solution is working.
235235
&[], // exclude_styles
236236
&[], // include_styles
237237
&[], // only_styles
238+
false, // ignore_ambiguous
238239
&[], // exclude_match
239240
None, // exclude_matching_lines
240241
None, // preview_format

renamify-core/src/operations/plan.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn plan_operation(
3131
include_acronyms: Vec<String>,
3232
exclude_acronyms: Vec<String>,
3333
only_acronyms: Vec<String>,
34+
ignore_ambiguous: bool,
3435
working_dir: Option<&std::path::Path>,
3536
atomic_config: Option<&crate::atomic::AtomicConfig>,
3637
) -> Result<(PlanResult, Option<String>)> {
@@ -83,7 +84,7 @@ pub fn plan_operation(
8384
include_acronyms,
8485
exclude_acronyms,
8586
only_acronyms,
86-
ignore_ambiguous: false, // TODO: Get from args
87+
ignore_ambiguous,
8788
atomic_config: atomic_config.cloned(),
8889
};
8990

renamify-core/src/operations/rename.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn rename_operation(
2222
exclude_styles: &[Style],
2323
include_styles: &[Style],
2424
only_styles: &[Style],
25+
ignore_ambiguous: bool,
2526
exclude_match: &[String],
2627
exclude_matching_lines: Option<&String>,
2728
preview_format: Option<&String>,
@@ -74,7 +75,7 @@ pub fn rename_operation(
7475
include_acronyms: include_acronyms.to_owned(),
7576
exclude_acronyms: exclude_acronyms.to_owned(),
7677
only_acronyms: only_acronyms.to_owned(),
77-
ignore_ambiguous: false,
78+
ignore_ambiguous,
7879
atomic_config: atomic_config.cloned(),
7980
};
8081

renamify-core/src/scanner.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,16 @@ pub fn scan_repository_multi(
249249

250250
// Build acronym set from options
251251
let acronym_set = build_acronym_set(options);
252-
let variant_map = generate_variant_map_with_acronyms(
252+
let mut variant_map = generate_variant_map_with_acronyms(
253253
search,
254254
replace,
255255
options.styles.as_deref(),
256256
&acronym_set,
257257
options.atomic_config.as_ref(),
258258
);
259+
if options.ignore_ambiguous {
260+
variant_map.retain_unambiguous();
261+
}
259262
let variants: Vec<String> = variant_map.keys().cloned().collect();
260263
let _pattern = build_pattern(&variants)?;
261264

@@ -482,6 +485,10 @@ pub fn scan_repository_multi(
482485
)
483486
};
484487

488+
if options.ignore_ambiguous {
489+
file_matches.retain(|m| !is_ambiguous(&m.variant));
490+
}
491+
485492
if file_matches.is_empty() {
486493
return outcome;
487494
}
@@ -646,6 +653,10 @@ fn generate_hunks(
646653
};
647654

648655
for m in matches {
656+
if options.ignore_ambiguous && is_ambiguous(&m.variant) {
657+
continue;
658+
}
659+
649660
// Check if this match should be excluded
650661
if options.exclude_match.contains(&m.variant) || options.exclude_match.contains(&m.text) {
651662
continue;
@@ -1016,6 +1027,12 @@ impl VariantMap {
10161027
pub fn keys(&self) -> impl Iterator<Item = &String> {
10171028
self.map.keys()
10181029
}
1030+
1031+
/// Remove entries whose keys are considered ambiguous identifiers.
1032+
pub fn retain_unambiguous(&mut self) {
1033+
self.map
1034+
.retain(|key, _| !crate::ambiguity::is_ambiguous(key));
1035+
}
10191036
}
10201037

10211038
/// Generate variant map with custom acronym configuration

0 commit comments

Comments
 (0)