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
Fix autoimport does nothing when importing trait that is as _ imports #15587
Conversation
++ @Veykril I described the logic as descriptive as possible. I hope it's understandable and you could relate it with the diff. Please give any feedback if you have any? |
Can you add a test for this here -> https://github.com/dfireBird/rust-analyzer/blob/fix-15128/crates/ide-db/src/imports/insert_use/tests.rs? Or ideally two, one for each of those changes |
Regarding tests, I forgot to mention. But this only happens when the P.S: I actually have the tests in my local tree with modified config such |
There is a |
Tested for two cases: 1. Simple Use 2. Complex Use
0e2ead1
to
df1239b
Compare
I was adding the tests in |
Thanks! |
☀️ Test successful - checks-actions |
Potentially fixes #15128
There are two cases of imports:
On deeper inspection, the
recursive_merge
function (called bytry_merge_trees_mut
) is meaningful only in the case of complex path (i.e when the UseTree contains a UseTreeList).The
recursive_merge
function has match withOk
arm, that is only executed when both LHS and RHS hasPathSegment
with sameNameRef
. The removal of underscore is implemented in this arm in the case of complex path.For simple paths, the underscore is removed by checking if both LHS and RHS are simple paths and if their
Path
is same (the check is done here) and remove the underscore if one is found (I made an assumption here that RHS will always be what rust-analyzer suggests to import, because at this point I'm not sure how to remove underscore with help ofted::replace
).