rust-lang / rust-lang/rust-analyzer
Auto Import structure breaks with `"rust-analyzer.imports.prefix": "plain"`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
I do not believe this is a regression, but it is exacerbated by #17277.
rust-analyzer version: 0.3.1975-standalone (71a816a90 2024-05-26)
rustc version: 1.78.0 (9b00956e5 2024-04-29)
editor or extension: VSCode
relevant settings: rust-analyzer.imports.prefix
to reproduce:
- Create a new project with
serde(including featurederive) as a dependency; any external crate would work, but I chose serde for this report. - Create the following
srcdirectory
├── lib.rs
├── foo.rs
and the following files.
// lib.rs
use serde::Serialize;
mod foo;
#[derive(Serialize)]
struct Example;
impl Example {
fn a() {
}
}
// foo.rs
pub fn b() {
}
It is important that the module is named foo, so it is alphabetically before serde.
3. Through UI or JSON, change the setting rust-analyzer.imports.prefix to self.
4. In the body of Example::a(), type b and use auto-import. Observe that self::foo::b is correctly imported in a group below serde::Serialize. Remove the function call and import, so it once again resembles Step 2.
5. Change rust-analyzer.imports.prefix to plain (the default).
6. In the body of Example::a(), type b and use auto-import. Observe that foo::c is incorrectly imported. It should be below serde::Serialize, as it is a current module import, but it is instead above serde::Serialize in the same group, as if it was an external crate.
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
Reproduce the behavior using the minimal project in src/lib.rs and src/foo.rs, with serde and the rust-analyzer.imports.prefix setting changed between self and plain. Trace the auto-import behavior for b inside Example::a(); done means plain places the current-module import below serde::Serialize rather than grouping it as an external import.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100