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

Improve typo suggestion hueristics #26087

Merged
merged 1 commit into from
Jun 8, 2015

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Jun 8, 2015

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)

@rust-highfive
Copy link
Collaborator

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.

@Aatch
Copy link
Contributor

Aatch commented Jun 8, 2015

@bors r+

@bors
Copy link
Contributor

bors commented Jun 8, 2015

📌 Commit 93d01eb has been approved by Aatch

bors added a commit that referenced this pull request Jun 8, 2015
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)
@bors
Copy link
Contributor

bors commented Jun 8, 2015

⌛ Testing commit 93d01eb with merge dcc59c0...

@bors bors merged commit 93d01eb into rust-lang:master Jun 8, 2015
@brson brson added the relnotes Marks issues that should be documented in the release notes of the next release. label Jun 16, 2015
// 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;

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.

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants