-
Notifications
You must be signed in to change notification settings - Fork 888
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
Share use
normalisation code between ordering and formatting
#2531
Comments
There actually looks to be a whole lot of duplicate code between imports.rs and reorder.rs and its not clear to me how to resolve it. |
Hi @nrc, you mentioned in #2536 that I might be interested in pursuing this, and it looks interesting! Do you think this issue could be resolved in an incremental way, e.g. via multiple PRs that each refactor one small thing? My only caveat right now is that I don't have a ton of time over the next 3-4 days, so if you need this issue resolved ASAP, I'm probably not the person to do it. But I'll have more free time near the end of the week, and over the weekend, so if this issue isn't super urgent then I'm happy to help. |
Yes, but it is probably a few small PRs, a large PR, and maybe a few more small ones. I'm not entirely sure.
That's fine, this is not super-urgent since afaik nothing is actually broken, it's just sub-optimal code. I'll try and add a few pointers here some time in the next few days. A good place to start would be to update rustc-ap-syntax dependency. That should bring in this PR which I think will break the code in reorder.rs (hopefully that will show up in tests, I think there will be compilation breakage too). Fixing reorder.rs should be fairly easy - if you look at the changes to ast.rs in the rustc PR, you should be able to change the |
I have implemented this in https://github.com/topecongiro/rustfmt/tree/merge-imports. All tests are passing, although the code needs more refactorings and the commit history is not well organized. I will create a PR once I make it tidier. |
In order to accurately re-order, we need to apply a lot of the normalisation transfomations. This is a waste since we then throw them all away (worse we do it on every compare, not just once for the whole search). We should instead do the conversion to our own data types earlier, sort then output the re-ordered (and normalised) imports. I think that means we need to include either span info or comments and newlines and visibility with our representation of
use
paths.The text was updated successfully, but these errors were encountered: