rust-lang / rust-lang/rust-analyzer
Enable auto-import assist for prelude and glob imported items
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Use case
The anyhow crate provides the following definition:
pub type Result<T, E = Error> = core::result::Result<T, E>;
If you create a new file, and use the type Result<()> somewhere, there is no way to automatically add use anyhow::Result;, because Result is already a type that exists.
Proposed solution:
If the item under the cursor has been imported from prelude or a glob import, allow auto-importing an alternative item with the same name.
Provide a new assist for changing the import of the item under the cursor.
If the item is defined in the current module, no assist is shown.
If the item is already imported from a use, allow selecting an alternative import which replaces the old one.
If the item is imported by default, like std's Result, allow selecting an import to hide it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example with anyhow::Result and inspect the existing auto-import assist and its tests, focusing on how prelude and glob-imported names are resolved. Determine how an alternative same-named item can be offered without ambiguity, then add coverage showing the expected assist behavior for prelude and glob imports.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100