-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Suggest giving recommending substitution based on naming conventions with available #64585
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
Comments
If #51398 was implemented, we could add |
@varkor I looked at My guess is that this function is the one used to suggest alternatives to the user in case there is no method with a given name. The caveat here is that the function takes the distance by default as one-third of the word size. In the above case I tried some examples to verify this, Distance 1
Distance 2
I think distance should probably be a function of the size, smaller words might need a larger distance. Again, I am not sure if this is the same function that is being used to find the closest name to a method |
@sam09: I think this is the right function. I agree that it'd be helpful to have a higher cutoff for smaller words. You could try using a slightly different default distance function, and see if there are many changes after running |
I’m not sure that is the right approach. If you allow a larger Levenstein distance you’ll just let in an lot of totally unrelated method names. The idea is that the compiler can exploit knowledge about naming conventions to give better suggestions. So, e.g. use the current cut offs but compare against ‘is_{}’ as well, at least in a Boolean context. |
An option would be to try both levenstein distance and substring containment, as in I would say that this would need a cutoff of words shorter than 4 or 5 chars to avoid matching things like |
Current output:
We still don't check for an appropriate return type though, it is purely based on levenshtein distance. |
New rustacean here. In writing simple programs to get a feel for the language, I tried testing if a string slice is empty as the conditional for a if/else statement. Something like the following:
Of course the correct method is
.is_empty()
. I would suppose that this is a common mistake for people coming from languages like C++. It would be friendly of the compiler to recognize that in this boolean context there is a.is_empty()
method that is the same name but withis_
prepended, takes the provided (no) parameters, and returns the required boolean, and suggest that alternative to the user in the error output.The text was updated successfully, but these errors were encountered: