-
Notifications
You must be signed in to change notification settings - Fork 891
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
Rename merge_imports
to imports_granularity
and add a Module
option.
#4600
Rename merge_imports
to imports_granularity
and add a Module
option.
#4600
Conversation
@calebcartwright Is this closer to what you had in mind? Also I don't know if we want to do anything special to avoid breaking people's configuration files re. |
I think the best way to avoid this will be to come up with a new config option that's enum based, so that we can present a deprecation warning to folks using |
Hm, I couldn't think of a suitable new name so I opted to keep it as-is, but I made |
Thank you for the updates @goffrie. Please note that the CI failure on beta is not spurious, and would need to be resolved.
Please note that As for the name, I still think we'll need a new name that doesn't carry such a boolean connotation. We've had previous config options with very boolean sounding names (e.g. A relatively common naming pattern for enum-based options is to have a |
OK, that reasoning makes sense to me. I've renamed the option to Sadly the code that does the forwarding is a bit messy, but I couldn't find a good way to clean it up. Let me know if you have any suggestions... Also the beta tests should be fixed now. |
merge_imports
more granular with a Module
option.merge_imports
to a imports_merge_style
and add a Module
option.
merge_imports
to a imports_merge_style
and add a Module
option.merge_imports
to imports_merge_style
and add a Module
option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates and your work on this! I know there's a bit of an initial hill we have to climb here to pivot to supporting multiple strategies, but this will be a big enabler in providing some features highly desired by the community.
Looks pretty good overall, and have left some inline comments below on a few items. Would also be good to add some additional tests that include combinations of various values of related config options (e.g. group_imports
and reorder_imports
)
src/formatting/reorder.rs
Outdated
match context.config.imports_merge_style() { | ||
ImportMergeStyle::Crate => normalized_items = merge_use_trees(normalized_items), | ||
ImportMergeStyle::Module => { | ||
normalized_items = unnest_use_trees(merge_use_trees(normalized_items)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way we could format with the Module merge style without first converting it to the Crate style? I realize that could potentially involve some non-minimal refactoring of the existing code to split out the reusable bits from the Crate-specific strategy, but I think we'll want to go that route given the additional strategies we know we'll need to support eventually
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively if you'd prefer, I'd be okay with just adding // TODO
comments inline here and deferring this to a later date. The new config option and mapping of the old ones is a good enhancement in its own right, so don't necessarily need to block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm not a huge fan of this code either. I'll try to rewrite it.
I am wondering whether the name |
Thanks @johnmave126 - i think we're going to change that (I almost posted here earlier) but going to utilize one of the other threads instead to allow us to keep the discussion on this PR centered on the implementation |
@calebcartwright Just to confirm. Is the thread for discussion rust-lang/style-team#140? |
Here: #3362 (comment) I know it's a little tricky as there's some bifurcation in the discussion, but that existing thread in this repo felt like the best available option |
I cleaned the docs up a bit, and now instead of merging and unmerging in separate steps, we merge up to the desired granularity from the start, so the code is a bit cleaner now. |
CI failure on Windows seems to be some cargo-make issue, possibly upstream. |
Looks like a linker error, more likely caused by some changes on the GH runner environments rather than an issue with cargo-make itself. Will take a look at that in a bit |
CI's fixed now, you can rebase or grab 9a19515 to get the windows gnu jobs passing again. Have only taken a quick glance through the updates but they looked pretty great! Going to give it a few more days for the community to weigh in on the option and variant names, after which I imagine this will be good to (other than potentially renaming a couple things) |
d1bad36
to
28c08e4
Compare
Thanks again @goffrie! Based on the discussions in the linked threads, we're going to go with After this update I believe we'll be good to merge and hopefully get this shipped in v1.4.32 |
merge_imports
to imports_merge_style
and add a Module
option.merge_imports
to imports_granularity
and add a Module
option.
46dba84
to
622d040
Compare
Done :) |
backported in #4634 |
This renames the existing
true
/false
options toCrate
/Never
, then adds a newModule
option which causes imports to be grouped together by their originating module.The crate/module option terminology is taken from #3362 (comment) which makes the most sense to me. I haven't implemented the other options there, though.