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

[WIP] Merge imports from the same module #2475

Closed
wants to merge 3 commits into from

Conversation

topecongiro
Copy link
Contributor

@topecongiro topecongiro commented Feb 20, 2018

This PR adds a merge_imports config option.
When this option is enabled, rustfmt will merge use declarations from the same module.

The implementation is limited in several ways:

  1. It does not merge imports if there are comments within or among them.
  2. The merge_imports only works when reorder_imports is set to ture.

Closes #1383.
Closes #2452.

EDIT: merge_imports does take effect on its own, but still need some work and more tests.

Note that `merge_imports` takes effect only when paired with `reorder_imports`.
@topecongiro
Copy link
Contributor Author

(I think that this option is required in RFC somewhere, but I forget where and cannot find one)

use super::{contains_comment, rewrite_comment, CharClasses, CodeCharKind, CommentCodeSlices,
FindUncommented, FullCodeCharKind};
use shape::{Indent, Shape};
use CharClasses;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does not handle use super::{/* .. */}; properly.

@topecongiro topecongiro changed the title Merge imports from the same module [WIP] Merge imports from the same module Feb 21, 2018
@nrc
Copy link
Member

nrc commented Feb 23, 2018

A couple of comments: I don't think we need this to work when reorder is not enabled - I can't imagine someone would want to merge but not reorder.

We need to think a bit about how we want to use nested imports. My personal feeling (and the intention on the RFC) was that nested imports should be used rarely and shallowly. But that is not a great guideline for an automatic tool.

To start with it might be good to have different levels of merging, rather than just true/false. E.g., no merging/merge with no nesting/merge with some nesting (?)/merge with maximal nesting. I'm also not sure if we should un-merge at all. E.g., if you specify 'merge with no nesting' and there is a nested import, should we split it?

btw, there is also a compile error.

@nrc nrc mentioned this pull request Mar 12, 2018
6 tasks
@topecongiro
Copy link
Contributor Author

@nrc Thank you for you reviews. Unfortunately I will not have enough time to work on rustfmt for a while, so I am going to close this PR for now. I will come back on this at some point, thank you for taking time to review on WIP PR!

@topecongiro topecongiro mentioned this pull request Apr 6, 2018
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.

2 participants