rust-lang / rust-analyzer

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

Prefer to auto complete in scope word rather than import #18530

Open baxterjo opened 3 days ago

baxterjo commented 3 days ago

I see a lot of issues about the scope of one import vs another. But I'm experiencing a lot of frustration when using the auto complete feature for in scope variables competing with auto import.

Example

Image

This seems completely unexpected. I would assume local vars should always be prefered over importing a new module in terms of auto complete.

ChayimFriedman2 commented 3 days ago

Hmm... I'm not sure it would be better. This is an exact match after all.

lnicola commented 3 days ago

I'd probably prefer a prefix match to rank above an exact match flyimport, because if it's wrong, it's only wrong once (assuming you actually import it).

baxterjo commented 18 hours ago

Hmm... I'm not sure it would be better. This is an exact match after all.

Exact match makes sense if from a pure text search perspective. But I would argue that DX and context matter here.

The primary goal should be to do the least work possible first, then to provide a good match. Matches that take no action other than autocomplete should be ranked above matches that both autocomplete and import, regardless of the exactness of the match. Because if the match with imports happens to be wrong, the developer must go to the top of the file and undo what rust-analyzer did before continuing their work. This is very disruptive to workflow.

baxterjo commented 18 hours ago

I'd probably prefer a prefix match to rank above an exact match flyimport, because if it's wrong, it's only wrong once (assuming you actually import it).

I don't fully understand what you mean in the second half of this comment, but I think we're on the same page?

ChayimFriedman2 commented 15 hours ago

I assume that developers rarely accept the wrong completion. Also if they do, it's a matter of Undo, no need to go to the top of the file. But the argument @lnicola provided is convincing.