Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Did you mean ...?" suggestions for misspelled commands #2844

Open
the-mikedavis opened this issue Nov 8, 2023 · 7 comments
Open

"Did you mean ...?" suggestions for misspelled commands #2844

the-mikedavis opened this issue Nov 8, 2023 · 7 comments

Comments

@the-mikedavis
Copy link

the-mikedavis commented Nov 8, 2023

Some CLI tools make suggestions when you mistype a command. For example with Mix or Cargo:

$ mix hel
** (Mix) The task "hel" could not be found. Did you mean "help"?
$ cargo hel
error: no such subcommand: `hel`

	Did you mean `help`?

They find any commands where the edit distance to the input command is above some threshold. Mix uses Jaro distance while Cargo uses Damerau–Levenshtein.

I think it would be an easy QoL win to add this to rebar. Elixir's String.jaro_distance/2 is not a very large chunk of code when translated / vendored: https://gist.github.com/the-mikedavis/db39019721fab873980df3560345a93b. Then any places that return an error message that Command ~ts not found can suggest #provider.names where the jaro distance is close enough to 1.0 (Mix uses 0.8).

What do you think? I could submit a PR if you're interested.

@paulo-ferraz-oliveira
Copy link
Contributor

👍

In erlang_ls' els_utils.erl you'll already find references (in Erlang) to both mentioned distance algo.s: Jaro and Damerau-Levenshtein. Maybe worth a look (?)

Fwiw, I'd very much like to see this in rebar3.

@garazdawi
Copy link
Contributor

I've long though we should have Jaro/Damerau-Levenstein in the string module in Erlang. So a PR there would be appriciated :)

@ferd
Copy link
Collaborator

ferd commented Nov 14, 2023

Yeah I don't have any opposition to that. The State contains a list of all live providers, and you can see them being searched in rebar_core. Be aware that you can also get commands such as rebar3 namespace cmd and that either the namespace or the command can be misspelled, but even just doing the command would be an improvement.

See

case CommandProvider of
not_found when Command =/= do ->
case Namespace of
default ->
{error, io_lib:format("Command ~ts not found", [atom_to_list(Command)])};
_ ->
{error, io_lib:format("Command ~ts not found in namespace ~ts",
[atom_to_list(Command), atom_to_list(Namespace)])}
end;
not_found when Command =:= do, Namespace =/= default ->
do([{default, do} | TargetProviders], State);
for the specific bit where it complains of things not being found.

@garazdawi
Copy link
Contributor

I've long though we should have Jaro/Damerau-Levenstein in the string module in Erlang. So a PR there would be appriciated :)

Seems like I triggered one of my collegues at Erlang/OTP team, so we will soon see a PR for this in the Erlang/OTP repo.

@the-mikedavis
Copy link
Author

Ah, I had actually already started on a PR to Erlang/OTP. I will submit what I have upstream and they can take it over or supersede it if they'd like :)

@garazdawi
Copy link
Contributor

Ah, I had actually already started on a PR to Erlang/OTP. I will submit what I have upstream and they can take it over or supersede it if they'd like :)

Thats what you get when you use gossip as coordination protocol :) Always good to have more implementation to take inspiration from!

@ferd
Copy link
Collaborator

ferd commented Nov 15, 2023

If we do depend on the Erlang/OTP module, we'll need to do a dynamic check to avoid failing when running on older releases. It's rather straightforward, just something we need to make an exception for.

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

No branches or pull requests

4 participants