Skip to content

dev/sg: levenshtein suggestions when subcommand not found

Administrator requested to merge sg-suggest into main

Created by: bobheadxi

Adds a subcommand suggester to the following hooks:

  • (App).CommandNotFound
  • (Command).Action, where the action used to be "show subcommand help"

Currently, we suggest up to the 3 most similar command names to arg where the levenshtein match score is > 0.3, as described here: https://github.com/agext/levenshtein#overview , emphasis mine as to why this seemed like a good fit:

The Match function provides a similarity metric, with the same range and meaning as Similarity, but with a bonus for string pairs that share a common prefix and have a similarity above a "bonus threshold". It uses the same method as proposed by Winkler for the Jaro distance, and the reasoning behind it is that these string pairs are very likely spelling variations or errors, and they are more closely linked than the edit distance alone would suggest.

Closes https://github.com/sourcegraph/sourcegraph/issues/33886

Test plan

Simple unit tests, and manual tests:

image

Merge request reports

Loading