Skip to content

refactor(suggestions): extract shared did_you_mean helper - #2268

Merged
max-sixty merged 1 commit into
mainfrom
did-you-mean-helper
Apr 16, 2026
Merged

max-sixty merged 1 commit into
mainfrom
did-you-mean-helper

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

After PR #2266 merged, two sites computed Jaro-Winkler "did you mean" suggestions with the same 0.7 threshold, descending sort, and (mostly) the same dedupe needs: similar_subcommands in src/commands/external.rs (top-level dispatch) and the inline scoring inside unknown_step_command_exit in src/commands/alias.rs (wt step dispatch). This pulls the scoring loop into a did_you_mean helper alongside format_command_label in commands/mod.rs, and has both sites delegate to it.

The helper's docstring pins the 0.7 threshold to clap's internal did_you_mean so future maintainers know not to drift. The alias.rs site gains harmless dedupe — no shadowing collisions reach that point because shadowed names are filtered out before the call.

Behavior is unchanged: same threshold, same sort order, same outputs. The five similar_subcommands_* unit tests in external.rs and the two test_*_alias_did_you_mean integration tests pass unchanged.

This was written by Claude Code on behalf of @max-sixty

Both the top-level external dispatcher (`similar_subcommands`) and the
`wt step` alias dispatcher (`unknown_step_command_exit`) computed
Jaro-Winkler suggestion lists with the same 0.7 threshold, descending
sort, and dedupe needs. Pull the scoring loop into a single helper in
`commands/mod.rs` and have both sites delegate to it.

The helper's docstring pins the 0.7 threshold to clap's internal
`did_you_mean` so future maintainers know not to drift. The `alias.rs`
site gains harmless dedupe (no shadowing collisions reach that point
since shadowed names are filtered upstream).

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 42acd55 into main Apr 16, 2026
34 of 36 checks passed
@max-sixty
max-sixty deleted the did-you-mean-helper branch April 16, 2026 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants