rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Turn autoimport from an assist into a quickfix

Open obsgolem opened this issue 6 months ago • 5 comments

Which will allow e.g. write!() to import when std::fmt::Write/std::io::Write are not in scope, but there is no explicit method call to trigger the assist on.

obsgolem avatar Jun 17 '25 17:06 obsgolem

rust-analyzer already has an assist for that, https://rust-analyzer.github.io/book/assists.html#auto_import.

ChayimFriedman2 avatar Jun 17 '25 17:06 ChayimFriedman2

No it doesn't:

use std::fs::File;

fn main() {
    let f = File::create("hello_world").unwrap();
    write!(f, "hello world");
}

Error appears on f, no assist.

obsgolem avatar Jun 17 '25 19:06 obsgolem

That's because it's a macro, and there is no explicit method invocation.

To do something here we would need to emit our own error, and it won't happen soon.

ChayimFriedman2 avatar Jun 17 '25 20:06 ChayimFriedman2

Is that a reason to leave this issue closed?

obsgolem avatar Jun 17 '25 20:06 obsgolem

Even when we have the diagnostic it may prove unfeasible to have a quickfix for this macro.

But I can reopen the issue and edit it to clarify that we want to change the assist into a quickfix.

ChayimFriedman2 avatar Jun 17 '25 20:06 ChayimFriedman2