rust-lang / rust-lang/rust-analyzer

Enable auto-import assist for prelude and glob imported items

Open
#13,796 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists C-feature
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.