rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.33k stars 1.62k forks source link

Remove imports often doesn't commit the change causing future assist calls to bug #17723

Open joshka opened 4 months ago

joshka commented 4 months ago

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P) 0.3.2045-standalone (4afe0d539 2024-07-21)

rustc version: (eg. output of rustc -V) rustc 1.80.0 (051478957 2024-07-21)

editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable) VSCode

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

repository link (if public, optional): (eg. rust-analyzer)

code snippet to reproduce:

use std::{
    alloc::Layout,
    io::{stdout, Write},
};

fn main() {
    write!(stdout(), "Hello, world!\n").unwrap();
}

Trigger remove unused import on the alloc line:

use std::io::{stdout, Write};

fn main() {
    write!(stdout(), "Hello, world!\n").unwrap();
}

Trigger this again results in this odd output:

use std::ain() {   write!(stdout(), "Hello, world!\n").unwrap();
}

The above is a minimal repro, but I trigger this bug fairly regularly in normal use when attempting to clean up imports. It's a broken window / paper cut problem.

ShoyuVanilla commented 3 months ago

I guess that the assist triggers deletions at the same offset on file, without taking the previous call into account.