Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Acknowledge pub(crate) imports in import suggestions #16265

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

Patryk27
Copy link
Contributor

@Patryk27 Patryk27 commented Jan 5, 2024

rust-analyzer has logic that discounts suggesting uses for private imports, but that logic is unnecessarily strict - for instance given this code:

mod foo {
    pub struct Foo;
}

pub(crate) use self::foo::*;

mod bar {
    fn main() {
        Foo$0;
    }
}

... RA will suggest to add use crate::foo::Foo;, which not only makes the code overly verbose (especially in larger code bases), but also is disjoint with what rustc itself suggests.

This commit adjusts the logic, so that pub(crate) imports are taken into account when generating the suggestions; considering rustc's behavior, I think this change doesn't warrant any extra configuration flag.

Note that this is my first commit to RA, so I guess the approach taken here might be suboptimal - certainly feels somewhat hacky, maybe there's some better way of finding out the optimal import path 😅

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 5, 2024
@Veykril Veykril added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 10, 2024
@Patryk27 Patryk27 force-pushed the suggest-pub-crate-imports branch from 4061b71 to 5f7ed0e Compare January 10, 2024 17:19
@Patryk27
Copy link
Contributor Author

Ready!

@Patryk27 Patryk27 force-pushed the suggest-pub-crate-imports branch from 5f7ed0e to d6d4dd5 Compare January 10, 2024 17:20
rust-analyzer has logic that discounts suggesting `use`s for private
imports, but that logic is unnecessarily strict - for instance given
this code:

```rust
mod foo {
    pub struct Foo;
}

pub(crate) use self::foo::*;

mod bar {
    fn main() {
        Foo$0;
    }
}
```

... RA will suggest to add `use crate::foo::Foo;`, which not only makes
the code overly verbose (especially in larger code bases), but also is
disjoint with what rustc itself suggests.

This commit adjusts the logic, so that `pub(crate)` imports are taken
into account when generating the suggestions; considering rustc's
behavior, I think this change doesn't warrant any extra configuration
flag.

Note that this is my first commit to RA, so I guess the approach taken
here might be suboptimal - certainly feels somewhat hacky, maybe there's
some better way of finding out the optimal import path 😅
@Patryk27 Patryk27 force-pushed the suggest-pub-crate-imports branch from d6d4dd5 to 76aaf17 Compare January 10, 2024 17:21
@Veykril Veykril changed the title Suggest pub(crate) imports fix: Acknowledge pub(crate) imports in import suggestions Jan 11, 2024
@Veykril
Copy link
Member

Veykril commented Jan 11, 2024

Thanks!
@bors r+

@bors
Copy link
Contributor

bors commented Jan 11, 2024

📌 Commit 76aaf17 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jan 11, 2024

⌛ Testing commit 76aaf17 with merge d5366b5...

@bors
Copy link
Contributor

bors commented Jan 11, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing d5366b5 to master...

@bors bors merged commit d5366b5 into rust-lang:master Jan 11, 2024
10 checks passed
@Patryk27 Patryk27 deleted the suggest-pub-crate-imports branch January 11, 2024 10:08
bors added a commit that referenced this pull request Jan 11, 2024
internal: Consider all kinds of explicit private imports in find_path

Builds on top of #16265 to make things a bit more general, now we consider all explicit private imports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants