Skip to content

Add a "Did you mean?" prompt if user misspells example name, and optionally re-run if the user says "Yes!" #17

@rnag

Description

@rnag

Is your feature request related to a problem? Please describe.

I don't know if it's possible but I'd like to suggest auto-correction if a user misspells or mistypes an example name, similar to how cargo run --example does it already currently.

Related Issues

#18

Describe the solution you'd like

Potentially something like:


Sorry bud, no such example `my_exmaple` exists.

Did you mean `my_example`? [Y/N]:  $  
Did you mean `my_example`? [Y/N]:  $  y

[Runs the example file `my_example`...]

Describe alternatives you've considered

I haven't actually looked into any existing solutions for spelling correction yet. It would be cool to implement this, I feel. Preferably with the least overhead in terms of overall dependency size, compilation or build time, etc.

Additional context

It's not too necessary as when we call cargo run --example, it'll already offer an auto correction hint. But I think it's nice to add proactive spellchecking and correction -- this way it'll be a little faster, as we can catch the error earlier, and we don't need to waste time spawning a new process to call cargo run --example when we already know the example name is misspelled, for example.

Just for completeness sake, Here's a sample auto correction hint from cargo run --example on one of my projects, which I think is really cool/nice:

PS serde-this-or-that> cargo run --example d
error: no example target named `d`

        Did you mean `demo`?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions