Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Quick fix should sort items from the current workspace before items from external crates #17303

Closed
joshka opened this issue May 28, 2024 · 2 comments · Fixed by #17308
Closed
Labels
A-assists C-feature Category: feature request

Comments

@joshka
Copy link
Contributor

joshka commented May 28, 2024

In ratatui, performing the Import <type> quick fix on Color shows: color_eyre::owo_..., another color_eyre import, ratatui::style::Color, then a crossterm import. The order that I want always is current crate types first, then alphabetical. The sort order seems pretty random right now.

image

Why? Ctrl+., Enter Enter should be muscle memory

Even better might be to add an extra quick fix if there are crate imports that match as well as external imports: e.g.:
image
Should have the same option to 'ratatui::style::Color` as this does:
image

Why? Different UI modality (menu vs popup) for the same action (add an import from this crate). They should be the same where possible to make muscle memory / defaults just work. Right now the popup is jarring as there's no general way to guess if you're going to hit one or the other until you actually view the result (assuming your hands are typing ahead rather than responding to what you see on the screen).

Does this sound like a reasonable heuristic? Is "one of the imports is in this workspace" something that can be determined while getting the list of valid imports?

@joshka joshka added the C-feature Category: feature request label May 28, 2024
@mathew-horner
Copy link
Contributor

There are heuristics that handle the sort order, but in terms of preference for your code it seems to stop at the crate boundary. (link) It probably makes sense to make preference for workspace items somewhere between crate and std?

@joshka
Copy link
Contributor Author

joshka commented May 29, 2024

It took me a minute to work out why my example for this was not picking up the same crate logic. This code was in an example, so it's not in the same crate technically.

@bors bors closed this as completed in 26c1638 Jun 7, 2024
lnicola pushed a commit to lnicola/rust that referenced this issue Jun 23, 2024
…kril

Add preference modifier for workspace-local crates when using auto import.

`@joshka` pointed out some odd behavior of auto import ordering. It doesn't seem that the current heuristics were applying any sort of precedence to imports from the workspace. I've went ahead and added that.

I hope to get some feedback on the modifier numbers here. I just went with something that felt like it balanced giving more power to workspace crates without completely ignoring relative path distance.

closes rust-lang/rust-analyzer#17303
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists C-feature Category: feature request
Projects
None yet
3 participants