Rust-analyzer: Adding a `use` should have higher priority than renaming to similar

Created on 9 Apr 2020  路  2Comments  路  Source: rust-analyzer/rust-analyzer

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.

E-has-instructions E-medium

Most helpful comment

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.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matklad picture matklad  路  28Comments

Veetaha picture Veetaha  路  27Comments

bjorn3 picture bjorn3  路  25Comments

matklad picture matklad  路  57Comments

GrayJack picture GrayJack  路  25Comments