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

Feature request: Replace use with qualified path

Open jplatte opened this issue 3 years ago • 4 comments

In some instances, an assist that does the opposite of "Replace qualified path with use" would be nice. For instance, I prefer using anyhow::Result as a qualified path instead of importing it, but occassionally come across use of it in codebases I maintain.

I think it would be useful to offer this assist both on a symbol in a use statement, as well as on uses of that symbol, although I'm not sure what semantics would be best for the latter – qualify just that one use or qualify all uses and remove the import.

jplatte avatar Aug 11 '22 08:08 jplatte

I'd say in this case we should offer ~~both, by~~

  • a) ~~if invoked on the use statement,~~ replace all occurences
  • b) ~~if invoked on a usage, replace only that usage~~

~~This is inline with other assists where behaviour differs when invoked depending on whether it happens on the "definition" or "usage"~~

Veykril avatar Aug 11 '22 08:08 Veykril

Right. I guess the current "Replace qualified path with use" acts on all items when just one is selected because there no other place you could put the cursor to apply the refactoring to all instances.

jplatte avatar Aug 11 '22 08:08 jplatte

Yes, and I think for that one it makes more sense to replace all. Honestly I wouldn't mind this one also always replacing all I guess, I don' treally see the use of only replacing a single one here. Seems weird to me to qualify one usage only in a file actually?

Veykril avatar Aug 11 '22 08:08 Veykril

Yeah, it would be kind of weird. Clippy also has a lint against it ("unnecessary qualified path" or sth. like that), though off by default.

jplatte avatar Aug 11 '22 08:08 jplatte

I've only found rustc's unused-qualifications which works only when there is also a use which you might presumably get rid of with this replace. Furthermore the lint is set to allow by default.

In any case I'd like to give it a try

mladedav avatar Feb 19 '23 15:02 mladedav