rust-lang / rust-lang/rust-analyzer
Auto-import destroys previous formatting of nested-imports (merges all into one line)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
rust-analyzer version: 0.3.1995-standalone
rustc version: rustc 1.78.0 (9b00956e5 2024-04-29)
editor or extension: VSCode (extension version v0.3.1995)
code snippet to reproduce:
use std::{
collections::HashMap,
net::IpAddr,
fs::{File, copy},
};
fn main() {
let x = HashSet::new();
}
When triggering an auto-import for HashSet in above snippet, the import is changed to:
use std::{
collections::{HashMap, HashSet}, fs::{copy, File}, net::IpAddr
};
This makes the import a lot less readable and leads to more diff-noise in git. Instead, I would have expected this:
use std::{
collections::{HashMap, HashSet},
net::IpAddr,
fs::{File, copy},
};
This bug is already present for quite a while (years, if my memory serves me right).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported Rust snippet in rust-analyzer with the VSCode extension and trace the auto-import path that formats nested imports. The fix is done when adding HashSet preserves separate import lines and existing formatting, and the behavior is covered by the relevant rust-analyzer test if one is found.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100