rust-lang / rust-lang/rust-analyzer

Feature: Action to explicitly import a path

Open
#11,674 1 comment 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

I often want to add use statements before writing the code that uses them, either because I need autocomplete to actually be definitive or because I'm trying to add a glob import (especially a crate::prelude::* import). I really wish Rust Analyzer had an explicit action that let me provide a path that it would import. The primary benefit here is having it keep my imports organized according to my configured auto-import settings. This is especially useful when I'm trying to add an import for which a group doesn't exist yet and I can't remember the correct ordering of import groups.

Bonus points if this same feature can also tell me what other paths I've already imported whose prefix matches what I'm typing. That way I could trigger this action and use it to check what I've already imported from a given crate/module without having to scroll to the top and back down.

This feature could also help with the problem of adding imports at scopes other than module scope, as there could be variants on the action for importing at function scope or innermost block scope (also see #8103).

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

Start by reviewing the requested explicit import action and the related scope issue #8103. Define the smallest complete version around supplying a path and applying the configured import organization; consider the existing-import lookup and function or block scope variants separately. Done should include a clear action contract and tests for the supported behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.