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

VSCode showing rename preview without option to disable this

Open bjorn3 opened this issue 1 year ago • 4 comments

rust-analyzer version: rust-analyzer version: 0.4.1997-standalone [/home/bjorn/.var/app/com.visualstudio.code/data/vscode/extensions/rust-lang.rust-analyzer-0.4.1997-linux-x64/server/rust-analyzer]

editor or extension: VSCode

This started happening just today. It is really annoying having to click on the checkbox for each file affected by the rename and then having to click accept. Previously F2, enter new name and enter was enough to apply a rename. I already tried "editor.rename.enablePreview": false, but that doesn't have any effect.

bjorn3 avatar Jun 14 '24 10:06 bjorn3

Does this always happen or only when renaming certain usages? r-a forces the preview when you are trying to edit a file that is a library https://github.com/veykril/rust-analyzer/blob/fa486e694e1fe7774f20350bb15ff933f670dc3c/crates/rust-analyzer/src/lsp/to_proto.rs#L1114-L1118

Veykril avatar Jun 14 '24 11:06 Veykril

Though we haven't changed anything in this regard recently as far as I am aware

Veykril avatar Jun 14 '24 11:06 Veykril

I'm working on a binary. Also turns out it happens with any refactor now, not just renames. Even a quick fix like "Fill struct fields".

I just tried reloading vscode, and now it doesn't show refactor previews anymore. Weird.

bjorn3 avatar Jun 14 '24 11:06 bjorn3

Hmm ye other refactors would do the same. That sounds like something confuse r-a quite a bit there 😕

Veykril avatar Jun 14 '24 11:06 Veykril

@VladimirMakaev reported seeing this issue to me today in a closed-source linting CLI and I was able to consistently reproduce it. I think I've figured out the issue: it's the presence of of integration tests/snapshot tests that depend on the main Rust binary. They, for whatever reason, make rust-analyzer show the refactor preview for any chance because considers the binary a library.

Unless bjorn3 is using buck2—and I don't believe they are—I think the cause of this issue is some recent VFS/rust-analyzer.toml-related changes that saw land recently.

davidbarsky avatar Jul 08 '24 15:07 davidbarsky

the vfs/toml stuff didn't touch the CrateOrigin's which is the only thing that affects this. VSCode will force a preview only for edits that change crates of type CrateOrigin::Library aka crates that do not belong to your workspace.

Veykril avatar Jul 08 '24 15:07 Veykril

I have seen this repeatedly in the last month or so for renames. Restarting rust analyzer seems to fix it. Thanks for that suggestion; I was reloading the VSCode window entirely.

rbalicki2 avatar Feb 22 '25 03:02 rbalicki2

Information for future people who get just as annoyed at this as me: This also occurs when the rename would create a naming conflict (say renaming a variable from abc to test and then 3 levels of if down you already have a variable named test when you're also using abc at the same time.)

Note that it doesn't actually tell you this in any way, you just have to either commit the rename and then fix the errors that result, or tear your hair out wondering why the refactor is forcibly requiring a preview even though preview is disabled.

In my opinion, rename previews being disabled means that it should never start a preview, but I will note that the rename preview makes me irrationally frustrated because it won't go away despite me disabling it multiple times so this is a very biased view.

I'd really rather have it error out (if it can) or just commit the rename anyway while causing errors (if erroring out isn't possible), so if either of these could be added as a config I would be very grateful.

mystise avatar Sep 13 '25 21:09 mystise

@mystise https://github.com/rust-lang/rust-analyzer/pull/20193 will provide an option to disable rename conflict warning. As for the UI, I agree it's abysmal, but sadly VSCode does not really allow us to do any better: I filled https://github.com/microsoft/vscode/issues/254517 for that, but sadly we haven't heard from the VSCode on it.

ChayimFriedman2 avatar Sep 14 '25 00:09 ChayimFriedman2