rust-lang / rust-lang/rust-analyzer
Add new imports to aliased module import instead of importing via alias
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
In our project at work we have some imports like this:
use async_graphql::{self as gql, Object, ID};
(This enables the use of gql::Context<'_>, whereas having the full async_graphql::Context<'_> would be a good deal more verbose.)
However, when we do this, RA will add new imports from the async-graphql crate as:
use async_graphql::{self as gql, Object, ID};
+ use gql::InputObject;
Instead, the preferred way to do this would be to add it to the original import:
- use async_graphql::{self as gql, Object, ID};
+ use async_graphql::{self as gql, Object, ID, InputObject};
I understand this is a bit of an edge case, but it would be nice if RA could handle this correctly. (If someone can point out the right place to change the code for this, I might be able to contribute a PR.)
rust-analyzer version: 0.3.1766-standalone (457b966b1 2023-12-10)
rustc version: rustc 1.74.1 (a28077b28 2023-12-04)
relevant settings:
- Rust-analyzer > Imports > Group: Enable
- Rust-analyzer > Imports > Granularity: Group =
crate
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 reported case with use async_graphql::{self as gql, Object, ID}; and the Group/crate import settings. Trace how rust-analyzer chooses the target for a new import when the source module is aliased; done when InputObject is added to the existing async_graphql import rather than emitted through gql.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100