rust-analyzer
rust-analyzer copied to clipboard
Feat: "One" import granularity
The current options for rust-analyzer.assist.importGranularity are "preserve", "crate", "module", and "item". Personally, I group all of my imports into a single use block (and don't really understand why nobody else seems to do so); rust-analyzer should support (enforcing) this grouping along the existing use groupings.
This should be called One like in rustfmt.
Relevant code is mainly here https://github.com/rust-analyzer/rust-analyzer/blob/93036aa0e201474d43c38be3862f4a899defe267/crates/ide_db/src/helpers/insert_use.rs#L155-L193
We also should adjust our guessing infra to be able to understand that form here https://github.com/rust-analyzer/rust-analyzer/blob/93036aa0e201474d43c38be3862f4a899defe267/crates/ide_db/src/helpers/insert_use.rs#L246-L318
And config changes are needed here https://github.com/rust-analyzer/rust-analyzer/blob/93036aa0e201474d43c38be3862f4a899defe267/crates/rust-analyzer/src/config.rs
can you please assign this issue to me?
We also should adjust our guessing infra to be able to understand that form here
What's the most resilient way to identify the correct ImportGranularityGuess?
Looking at the rustfmt implementation, it looks like having merged use trees one for each visibility level is obviously One, but what about mixed cases? What should it guess?
https://github.com/rust-lang/rustfmt/pull/4680/files#diff-7bd4f14a75a37432af3ab896bbbe38f88428b490b5d76ed1586f7f473a745e98R1772-R1781
To identify we probably just want to check if there is only one tree that starts as use { ... };
If mixed it should fall back to Unknown I'd say.
i was thinking about writing a test that checks for one tree for each of the possible publicity types
use { ... };
pub use { ... };
pub(crate) use { ... };
thoughts?
Sounds good
Some personal stuff made me quite unproductive in February. Looks like @jeremyBanks is actively working on it, so it's only fair I am un-assigned from this issue
@rustbot claim