-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Improve typo suggestion hueristics #26087
Conversation
…typo'd name's length.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@bors r+ |
📌 Commit 93d01eb has been approved by |
This makes the maximum edit distance of typo suggestions a function of the typo'd name's length. FWIW, clang uses this same hueristic, and I've found their suggestions to be better than rustc's. Without something like this, you end up with suggestions that aren't related at all when there are short variable names. See also #20028 (comment)
// As a loose rule to avoid obviously incorrect suggestions, clamp the | ||
// maximum edit distance we will accept for a suggestion to one third of | ||
// the typo'd name's length. | ||
let max_distance = std::cmp::max(name.len(), 3) / 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we're dividing the max(name.len(),3)
by 3
, isn't the max_distance
always 1 now? It seems like we'd want this to be let max_distance = std::cmp::max(name.len() / 3, 3);
, instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, if it were min
instead of max
, it would be, but for example, if name.len()
was 9
, max(9,3)
is 9
, so max_distance would be 9 / 3
or 3
.
This makes the maximum edit distance of typo suggestions a function of the typo'd name's length. FWIW, clang uses this same hueristic, and I've found their suggestions to be better than rustc's. Without something like this, you end up with suggestions that aren't related at all when there are short variable names.
See also #20028 (comment)