Skip to content

Prefer non-prelude paths when suggesting import #15362

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

Open
Victor-N-Suadicani opened this issue Jul 30, 2023 · 3 comments
Open

Prefer non-prelude paths when suggesting import #15362

Victor-N-Suadicani opened this issue Jul 30, 2023 · 3 comments
Labels
C-feature Category: feature request

Comments

@Victor-N-Suadicani
Copy link

As an example, Bevy's App struct can be found at both bevy::prelude::App and bevy::app::App. I feel that if I am importing App specifically (i.e. not using a glob import on Bevy's prelude), then I would rather use bevy::app::App. Yet rust-analyzer seems to only show me the bevy::prelude::App path. I'd like it to prefer showing me the bevy::app::App path (ideally it would list both, but the non-prelude path first).

@Victor-N-Suadicani Victor-N-Suadicani added the C-feature Category: feature request label Jul 30, 2023
@ju1ius
Copy link

ju1ius commented Jan 7, 2024

As a side note there's a rust-analyzer.imports.preferPrelude setting, but I can't get it to work at all.

I'm writing a library with an exposed prelude and RA suggests only the prelude imports with no other alternative.

@Veykril Since you implemented the feature, maybe you have an idea?

@Veykril
Copy link
Member

Veykril commented Jan 7, 2024

In your case, is the prelude defined in the same crate as where you are working in? In that case it's not surprising this is happening. My change only affects imports coming from other crates, your case is not yet implemented.

Hmm, no that should work. Can you elaborate on the specific setup that runs into problems? It should be working if you set rust-analyzer.imports.preferPrelude to false

@ju1ius
Copy link

ju1ius commented Jan 7, 2024

Can you elaborate on the specific setup that runs into problems?

This is a cargo workspace with a few crates:

+ workspace/
├── .vscode/
│   └── settings.json
├── my-lib/
├── my-lib-macros/
├── my-lib-sys/
└── my-lib-tests/

RA version is 0.3.1791

The RA bits of settings.json:

{
  "rust-analyzer.rustfmt.rangeFormatting.enable": true,
  "rust-analyzer.imports.preferNoStd": true,
  "rust-analyzer.imports.preferPrelude": false,
}

Nothing too fancy...

I do use imports from the main library prelude in the integration tests, but I'd rather not reference the prelude from the main library itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: feature request
Projects
None yet
Development

No branches or pull requests

3 participants