rust-lang / rust-lang/rust-analyzer

Configuration to change where `use` statements are inserted when auto-importing

Open
#16,921 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

I would like for the auto-import code action to insert the use statement inside the function where it was invoked, and if there is no function, to put it at the module level.

I prefer having my imports inside functions when possible because it makes it easier to move the function, and to see what this specific function depends on. It's common for me to be in situations where a single function makes plenty of imports that other parts of the same module won't reference, cluttering the import section at the top of the module.

I'd be willing to implement this myself, but I don't know how the development process works here and sadly I don't have the time to look into it. However, if someone points me towards some direction I might be able to pick it up.

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 locating the auto-import code action and its configuration entry points. Determine how an option can select function-local insertion versus module-level insertion, then cover both cases with tests. Done means the configured behavior is respected when a use statement is inserted.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.