rust-analyzer
rust-analyzer copied to clipboard
Adding a `use` should have higher priority than renaming to similar
When there's some use of a symbol SomeTrait
that's from some other module and there's a similar symbol in scope (like HasSomeTrait
), the option to add a use for SomeTrait
should appear in vscode's action list thing as the first item, above renaming to the similar symbol.
Interesting problem! This happens because we have, effectively, three sources of light bulbs:
- our assists (which are correctly sorted by the target element)
- out diagnostics (which are not really sorted)
- diagnostics from rustc (which are not sorted as well)
And we just append diagnositcs before all other assists here:
https://github.com/rust-analyzer/rust-analyzer/blob/ebd1309c9a3ac0e6b0cee197f30a962d5263e727/crates/rust-analyzer/src/main_loop/handlers.rs#L704-L722
I think a better behavior would be to use this sort order:
- our diagnostics (b/c we know they are high priority)
- out assists
- rustc diagnostics.
I would be happy to work on this topic this weekend. Do you have any code example to be sure I understand the issue.
And we just append diagnositcs before all other assists here:
This seems to no longer be the case, AFAICT compiler diagnostics now come last: https://github.com/rust-lang/rust-analyzer/blob/dbb8fedf8b887adfde3b445f9ec4bdf11da9ae9f/crates/rust-analyzer/src/handlers.rs#L1114
However, I'm still seeing the assist to use an item of a different name before that to import the item with the exact right name.