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

Updating the "levenshtein-based" suggestions to include module imports... #30377

Merged
merged 1 commit into from
Dec 23, 2015

Conversation

wafflespeanut
Copy link
Contributor

fixes part of #30197

@wafflespeanut wafflespeanut changed the title Updatind the "levenshtein-based" suggestions... Updating the "levenshtein-based" suggestions... Dec 14, 2015
@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nrc (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. Due to 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.

@wafflespeanut
Copy link
Contributor Author

r? @Manishearth

TODO: crates & inline paths (and tests should also be updated)

@rust-highfive rust-highfive assigned Manishearth and unassigned nrc Dec 14, 2015
@wafflespeanut
Copy link
Contributor Author

(currently fails build due to minor type errors)

Minor clarification: The lev_distance function is currently used only for suggesting struct fields. Could that also be modified to make use of find_best_match_for_name? (so that lev_distance could be private, and max_distance won't be needed at all)

@wafflespeanut wafflespeanut force-pushed the levenshtein branch 2 times, most recently from b42a8d2 to a6263e4 Compare December 14, 2015 22:39
&source.as_str());
if let Some((name, _)) = best_match {
lev_suggestion =
format!(". Did you mean to use the exported import `{}`?",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"exported import"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know, the thing with pub use...

use food::bar;

mod baz {
    pub struct foobar;
}

mod food {
    pub use baz::foobar as baz;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe say "re-exported" instead for pub use ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that should work :)

@Manishearth
Copy link
Member

Please add tests for all the new suggestion cases (and list them in the PR too)

@wafflespeanut
Copy link
Contributor Author

@Manishearth you didn't address my question, btw?

@pnkfelix
Copy link
Member

The lev_distance function is currently used only for suggesting struct fields. Could that also be modified to make use of find_best_match_for_name? (so that lev_distance could be private, and max_distance won't be needed at all)

Switching to find_best_match_for_name sounds fine, assuming it works in this context

I'd be wary of coupling in the other change (making lev_distance private); there have been complaints recently about changes to libsyntax breaking plugins downstream, so until the compiler team firms firms up a policy regarding stability of libsyntax, I'd try to keep such so-called breaking changes isolated

@wafflespeanut wafflespeanut force-pushed the levenshtein branch 2 times, most recently from 6e27b49 to 8c68720 Compare December 15, 2015 11:59
@Manishearth
Copy link
Member

(I don't think anybody uses lev_distance outside of rustc, so I'm ambivalent on the private-ing)

}
}
if let Some(n) = best {
let best_dist = Some(name.len());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is okay, because our new function defines the maximum edit distance to be one-third of the characters in the given word. Here, the entire word's length (in bytes) is being used (seems rather rough to me). So, I've added an option for using custom edit distances. Check if this is okay...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this. Be sure to update the doc comment explaining the third argument.

I don't think the best_dist variable is necessary here, just put the Some(name.len()) inline in the call to find_best_match.

@wafflespeanut wafflespeanut force-pushed the levenshtein branch 3 times, most recently from 448fa66 to 88d5a07 Compare December 15, 2015 20:00
return SuggestionType::Macro(format!("{}!", macro_name));
}

let mut names: Vec<Name> = Vec::new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a vector or any pushes here. This can be constructed via a map iterator (self.value_ribs.iter().rev().map(|(&k, _)| k)) and passed directly to find_best_match_for_name()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. Nice :)

@Manishearth
Copy link
Member

Looks good to me with some nits.

@wafflespeanut wafflespeanut changed the title Updating the "levenshtein-based" suggestions... Updating the "levenshtein-based" suggestions to include module imports... Dec 16, 2015
@Manishearth
Copy link
Member

@bors r+

Thanks!

@bors
Copy link
Collaborator

bors commented Dec 23, 2015

📌 Commit 51ff171 has been approved by Manishearth

@bors
Copy link
Collaborator

bors commented Dec 23, 2015

⌛ Testing commit 51ff171 with merge 4ce1daf...

bors added a commit that referenced this pull request Dec 23, 2015
@bors
Copy link
Collaborator

bors commented Dec 23, 2015

💔 Test failed - auto-win-gnu-32-opt

@Manishearth
Copy link
Member

@bors retry

@bors bors merged commit 51ff171 into rust-lang:master Dec 23, 2015
@wafflespeanut wafflespeanut deleted the levenshtein branch December 23, 2015 13:39
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

Successfully merging this pull request may close these issues.

6 participants